forked from rgerum/unofficial-duolingo-stories
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_build.js
39 lines (33 loc) · 928 Bytes
/
init_build.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
const { spawn } = require("child_process");
async function runCommand(command, args = []) {
return new Promise((resolve, reject) => {
const child = spawn(command, args);
child.stdout.on("data", (data) => {
console.log(`stdout: ${data}`);
});
child.stderr.on("data", (data) => {
console.error(`stderr: ${data}`);
});
child.on("error", (error) => {
reject(error);
});
child.on("close", (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Command failed with exit code ${code}`));
}
});
});
}
// Usage
(async () => {
try {
// Replace 'ls' and ['.', '-lh'] with your command and its arguments
await runCommand("npm", ["run", "init"]);
await runCommand("npm", ["run", "build"]);
console.log("Command executed successfully");
} catch (error) {
console.error(`Error: ${error.message}`);
}
})();