forked from naugtur/npm-audit-resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.js
43 lines (40 loc) · 1.32 KB
/
check.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
#!/usr/bin/env node
const pkgFacade = require('audit-resolve-core/pkgFacade');
const view = Object.assign({}, require('./src/views/package'), require('./src/views/general'))
const argv = require('audit-resolve-core/arguments').get();
const auditChecker = require('./src/check/auditChecker')
function auditOk(issues) {
return !(issues && issues.length);
}
if (argv.yarn) {
pkgFacade.addImplementation('yarn', require('./src/pkgmanagers/yarn'))
pkgFacade.setActiveImplementation('yarn')
} else {
pkgFacade.addImplementation('npm', require('./src/pkgmanagers/npm'))
pkgFacade.setActiveImplementation('npm')
}
pkgFacade.getAudit({ argv, shellOptions: { ignoreExit: true } })
.then(input => {
if (!argv.json) {
view.totalActions(input.actions.length)
}
return auditChecker.aggregateIssuesFromAudit(input)
})
.then(result => {
const { issues } = result;
if (argv.json) {
return view.printJsonReportAsync(result)
.then(() => auditOk(issues));
} else {
view.printHumanReadableReport(auditOk(issues), issues);
return auditOk(issues)
}
}).then(isOk => {
if (!isOk) {
process.exit(1);
}
})
.catch(e => {
view.genericError(e);
process.exit(2);
});