forked from dependency-check-team/dependency-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·62 lines (55 loc) · 2.51 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
#!/usr/bin/env node
var check = require('./')
var args = require('minimist')(process.argv.slice(2))
if (args.version) {
console.log(require('./package.json').version)
process.exit(1)
}
if (args.help || args._.length === 0) {
console.log('\nUsage: dependency-check <path to package.json or module folder> <options>')
console.log('\nOptions:')
console.log('--missing (default) Check to make sure that all modules in your code are listed in your package.json')
console.log('--unused, --extra The inverse of the --missing check and will tell you which modules in your package.json *were not* used in your code')
console.log("--no-dev Won't tell you about which devDependencies in your package.json dependencies that were not used in your code. Only usable with --unused")
console.log("--ignore-module, -i Won't tell you about module names passed in as --ignore-module / -i. Only usable with --unused")
console.log('--entry By default your main and bin entries from package.json will be parsed, but you can add more the list of entries by passing them in as --entry')
console.log("--no-default-entries Won't parse your main and bin entries from package.json will be parsed")
console.log('--version Show current version')
console.log('--ignore To always exit with code 0 pass --ignore')
console.log('--transformer=<cmd> Transform each file with the program "cmd". The current filename is available as $$')
console.log('')
process.exit(1)
}
check({
path: args._[0],
entries: args.entry,
noDefaultEntries: args['default-entries'] === false,
transformer: args.transformer
}, function (err, data) {
if (err) {
console.error(err.message)
return process.exit(1)
}
var pkg = data.package
var deps = data.used
var results, errMsg, successMsg
if (args.unused || args.extra) {
results = check.extra(pkg, deps, {
excludeDev: args.dev === false,
ignore: [].concat(args['ignore-module'] || [], args.i || [])
})
errMsg = 'Fail! Modules in package.json not used in code: '
successMsg = 'Success! All dependencies in package.json are used in the code'
} else {
results = check.missing(pkg, deps)
errMsg = 'Fail! Dependencies not listed in package.json: '
successMsg = 'Success! All dependencies used in the code are listed in package.json'
}
if (results.length === 0) {
console.log(successMsg)
process.exit(0)
} else {
console.error(errMsg + results.join(', '))
process.exit(args.ignore ? 0 : 1)
}
})