-
Notifications
You must be signed in to change notification settings - Fork 1
/
postinstall.js
48 lines (43 loc) · 1.47 KB
/
postinstall.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
const Spinner = require('cli-spinner').Spinner;
const path = require('path');
const pathResolve = (...args) => path.resolve(__dirname, ...args);
const npm = require('npm-programmatic');
const pkgJson = require(pathResolve('./package.json'));
const deps = Object.keys(pkgJson.customDependencies).map((dep) => `${dep}@${pkgJson.customDependencies[dep]}`);
const spinner = new Spinner();
const outputText = `Installing framevuerk-builder@${pkgJson.version} Dependencies...`;
spinner.setSpinnerString(Spinner.spinners[18] || '|/-\\');
spinner.setSpinnerTitle(outputText);
const install = (tryes) => {
spinner.start();
let retries = tryes;
return new Promise((resolve, reject) => {
const start = () => {
retries = retries - 1;
return npm.install(deps, {
save: false,
cwd: __dirname,
output: false,
global: false,
}).then(() => {
return resolve();
}).catch((e) => {
if (retries <= 0) {
reject(e);
} else {
spinner.setSpinnerTitle(`${outputText} (${(tryes - retries) + 1} / ${tryes})`);
return start();
}
}).finally(() => {
spinner.stop();
});
}
start();
});
}
install(5).then(() => {
console.log('Done!');
}).catch((x) => {
console.log('Failed to install!');
console.log(x);
});