-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnpm-install.js
62 lines (55 loc) · 1.48 KB
/
npm-install.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
54
55
56
57
58
59
60
61
62
var { exec } = require('child_process'); // native in nodeJs
// commands list
const commands = [
{
name: 'Frontend',
command: `cd ./frontend && npm i`
},
{
name: 'Api',
command: 'cd ./api && npm i'
},
{
name: 'Admin',
command: 'cd ./admin && npm i'
},
{
name: 'Image',
command: 'cd ./image && npm i --no-optional'
},
{
name: 'Auth',
command: 'cd ./auth && npm i'
},
];
async function execWaitForOutput(command, execOptions = {}) {
return new Promise((resolve, reject) => {
const childProcess = exec(command, execOptions);
// stream process output to console
childProcess.stderr.on('data', data => console.error(data));
childProcess.stdout.on('data', data => console.log(data));
// handle exit
childProcess.on('exit', () => resolve());
childProcess.on('close', () => resolve());
// handle errors
childProcess.on('error', error => reject(error));
})
}
// main calling function
async function main() {
commands.forEach(async (element) => {
await execWaitForOutput(element.command);
/*
console.log('element', element)
runCommand(element.command, element.name, (err, res) => {
if (err) {
console.error(err);
} else {
console.log('running:', res);
}
});
*/
});
}
// call main
main();