-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcheck.js
executable file
·49 lines (46 loc) · 1.54 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
44
45
46
47
48
49
#!/usr/bin/env node
const pkgFacade = require('./src/pkgFacade');
const view = Object.assign({}, require('./src/views/package'), require('./src/views/general'))
const argv = require('./src/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 if (argv["yarn-berry"]) {
pkgFacade.addImplementation('yarn-berry', require('./src/pkgmanagers/yarnBerry'))
pkgFacade.setActiveImplementation('yarn-berry')
} else {
pkgFacade.addImplementation('npm', require('./src/pkgmanagers/npm'))
pkgFacade.setActiveImplementation('npm')
}
let auditExit;
pkgFacade.getAudit({ argv, shellOptions: { ignoreExit: true, handleExit: (ex) => { auditExit = ex }} })
.then(input => {
if (!argv.json) {
view.totalActions(Object.keys(input).length)
}
return auditChecker.getUnresolved(input)
})
.then(issues => {
if (argv.json) {
return view.printJsonReportAsync(issues)
.then(() => auditOk(issues));
} else {
view.printHumanReadableReport(auditOk(issues), issues);
return auditOk(issues)
}
}).then(isOk => {
if (auditExit === 0) {
process.exit(0);
}
if (!isOk) {
process.exit(1);
}
})
.catch(e => {
view.genericError(e);
process.exit(2);
});