-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·51 lines (47 loc) · 985 Bytes
/
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
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const readPkgUp = require('read-pkg-up');
const opn = require('opn');
const inquirer = require('inquirer');
const cli = meow(`
Usage
$ npm-ls-home
$ nlh
Options
-l, -list Show package dependencies
`, {
alias: {
l: 'list'
}
});
function open(pkg) {
opn(`https://www.npmjs.com/package/${pkg}`, {wait: false});
}
function prompt(pkg, dependencies, devDependencies) {
const pkgs = [pkg];
Object.keys(dependencies).map(key => {
pkgs.push(key);
return key;
});
Object.keys(devDependencies).map(key => {
pkgs.push(key);
return key;
});
inquirer.prompt({
type: 'list',
name: 'pkg',
message: 'Choice a package',
choices: pkgs,
default: [pkg]
}, answer => {
open(answer.pkg);
});
}
readPkgUp().then(result => {
if (cli.flags.l || cli.flags.list) {
prompt(result.pkg.name, result.pkg.dependencies || {}, result.pkg.devDependencies || {});
} else {
open(result.pkg.name);
}
});