-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
LsCommand.js
55 lines (45 loc) · 1.2 KB
/
LsCommand.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import chalk from "chalk";
import columnify from "columnify";
import Command from "../Command";
import output from "../utils/output";
export function handler(argv) {
return new LsCommand(argv._, argv).run();
}
export const command = "ls";
export const describe = "List all public packages";
export const builder = {
"json": {
describe: "Show information in JSON format",
group: "Command Options:",
type: "boolean"
}
};
export default class LsCommand extends Command {
get requiresGit() {
return false;
}
initialize(callback) {
// Nothing to do...
callback(null, true);
}
execute(callback) {
const formattedPackages = this.filteredPackages
.map((pkg) => {
return {
name: pkg.name,
version: pkg.version,
private: pkg.isPrivate()
};
});
if (this.options.json) {
output(JSON.stringify(formattedPackages, null, 2));
} else {
formattedPackages.forEach((pkg) => {
pkg.version = chalk.grey(`v${pkg.version}`);
pkg.private = pkg.private ? `(${chalk.red("private")})` : "";
});
output(columnify(formattedPackages, { showHeaders: false }));
}
callback(null, true);
}
}