UNPKG

1.17 kBPlain TextView Raw
1#!/usr/bin/env node
2
3const mri = require('mri')
4const chalk = require('chalk')
5const list = require('./list.js')
6const why = require('npm-why/cli-main.js')
7
8const help = `
9 ${chalk.bold('nls')} - Missing inspector for npm packages.
10
11 Usage
12
13 $ nls [<target-dir>] ${chalk.dim('List available npm scripts.')}
14 $ nls why <package-name> ${chalk.dim('Identifies why a package has been installed.')}
15
16 Options
17
18 -h, --help ${chalk.dim('Output usage information')}
19 -v, --version ${chalk.dim('Output the version number')}
20
21 Examples
22
23 # List npm scripts in current dir
24 $ ${chalk.green('nls')}
25
26 # List npm scripts in "node_modules/chalk"
27 $ ${chalk.green('nls node_modules/chalk')}
28
29 # Find who depend upon package 'chalk'.
30 $ ${chalk.green('nls why chalk')}
31`
32
33const args = mri(process.argv.slice(2), {
34 boolean: ['help', 'version', 'why'],
35 alias: {
36 h: 'help',
37 v: 'version',
38 w: 'why'
39 }
40})
41
42if (args.help) {
43 console.info(help)
44} else if (args.version) {
45 console.info(require('../package.json').version)
46} else if (args._[0] === 'why' && args._.length === 2) {
47 why(process.cwd(), args._[1])
48} else {
49 list()
50}