-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallBackToLocalInstall.js
53 lines (45 loc) · 1.27 KB
/
fallBackToLocalInstall.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
50
51
52
53
const { exec } = require('child_process');
const {
error,
log,
warn,
} = require('colorful-logging');
module.exports = () => new Promise((resolve, reject) => {
const cwd = process.cwd();
warn(
'accelerator-tool-cli does not exist. Attempting to install locally, ' +
`within the directory from which the tool was invoked: ${cwd}.`,
);
try {
let pkg;
try {
pkg = require(require.resolve('./package.json', { paths: [ cwd ] }));
} catch (err) {}
if (!pkg) {
const err = new Error(
'No package.json found in current working directory.',
);
logFallbackError(err);
return reject(err);
}
const cmd = 'npm install accelerator-tool-cli';
exec(cmd, (err, stdout) => {
if (err) {
logFallbackError(err);
return reject(err);
}
log(stdout);
return resolve();
});
} catch (err) {
logFallbackError(err);
return reject(err);
}
});
const logFallbackError = (err) => error(
'Could not install accelerator-tool-cli. You might be offline, or ' +
'the install script isn\'t working on your OS. Do you have NPM ' +
'installed? If you don\'t mind global packages, try npm i -g ' +
'accelerator-tool-cli.' +
err ? `\n\nThe error was: ${err}.` : '',
);