-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
executable file
·72 lines (56 loc) · 1.43 KB
/
cli.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
// @flow
"use strict";
const meow = require("meow");
const chalk = require("chalk");
const {internal, global} = require('./');
/*::
type FlagsType = {
cwd?: string
}
*/
/*::
type CliType = {
input: Array<string>,
flags: FlagsType,
showHelp: Function,
}
*/
async function cli(argv /*: Array<string>*/) {
const cli /*: CliType*/ = meow({
argv,
help: `
popular package helps identify the popular package within a mono repo
Usage
$ popular-package <command> [options]
Commands
internal Get the internal (within monorepo) popularity of the packages
global Get the popularity of packages by number of downloads on npm
Examples
View internal popularity of a package in bolt or lerna repo:
$ popular-package internal
View popularity of packages on npm for a bolt or lerna repo:
$ popular-package global
`
});
if (cli.input.length < 1) {
cli.showHelp();
}
const command = cli.input[0];
const cwd = cli.flags.cwd || process.cwd();
if (command === 'internal') {
await internal({
cwd,
});
} else if (command === 'global') {
await global({
cwd,
});
} else {
throw new Error(chalk`Unknown command {red "${command}"}. Supported commands are {green "internal"} and {green "global"}`);
}
}
cli(process.argv.slice(2)).catch(err => {
console.error(err);
process.exit(1);
});