-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
37 lines (30 loc) · 816 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
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const pkgName = process.argv[2];
if(!pkgName){
console.error('need a name.');
return;
}
const pkgVersion = process.argv[3];
const cwd = process.cwd();
const pkgPath = path.join(cwd, 'package.json');
const pkgLockPath = path.join(cwd, 'package-lock.json');
try {
fs.accessSync(pkgPath);
} catch(e){
console.error(` unhave "package.json" file in "${cwd}"`);
return;
}
try {
fs.statSync(pkgLockPath);
} catch(e){
console.error(` unhave "package-lock.json" file in "${cwd}"`);
return;
}
const package = require(pkgPath);
const pkgLock = require(pkgLockPath);
const {main} = require('./index');
const outLog = require('./lib/outlog');
const rootMap = main(package, pkgLock, pkgName, pkgVersion);
outLog(pkgName, rootMap);