-
Notifications
You must be signed in to change notification settings - Fork 0
/
installDep.js
executable file
·44 lines (39 loc) · 1.5 KB
/
installDep.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
#!/usr/bin/env node
'use strict';
(async () => {
const util = require('util');
const FR = require('./fileRequesterBE.js');
const exec = util.promisify(require('child_process').exec);
const fs = require('fs');
const path = require('path');
let readPackageJSON = () => FR.readFile(path.resolve(process.cwd(), "package.json"));
function installPackage(packageName) {
console.log(packageName);
return exec(`nls ${packageName}`)
.then((e) => {
fs.appendFile('.successLog.txt', e, () => {});
})
.catch((e) => {
fs.appendFile('.errorLog.txt', e, () => {});
});
}
let main = (async () => {
readPackageJSON()
.then(async (packageJSON) => {
packageJSON = JSON.parse(packageJSON);
packageJSON.dependencies = packageJSON.dependencies || {};
packageJSON.devDependencies = packageJSON.devDependencies || {};
let packages = {
...packageJSON.dependencies,
...packageJSON.devDependencies
}
for (let [k, v] of Object.entries(packages)) {
if (v[0] === "^") v = v.slice(1, v.length);
await installPackage(`${k}@${v}`)
}
}).catch((e) => {
console.log("error");
fs.appendFile('.errorLog.txt', `Missing package.json `, () => {});
});
})();
})();