Skip to content

Commit 9b1c47a

Browse files
committed
Use spawn fn to create an other nodejs process and install dependencies
1 parent e1f10a7 commit 9b1c47a

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

lib/cli.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ora = require("ora");
77
const path = require("path");
88
const replaceInfile = require("replace-in-file");
99
const fs = require("fs");
10+
const { spawn } = require("child_process");
1011

1112
const { tree } = require("./structure.json");
1213

@@ -52,9 +53,7 @@ function checkErrors(command) {
5253
if (!commandsAvailables.includes(command[0]))
5354
return Promise.reject(
5455
new Error(
55-
chalk`\nThe {yellow ${
56-
command[0]
57-
}} command is not available for now, run the {yellow --help}.\n`
56+
chalk`\nThe {yellow ${command[0]}} command is not available for now, run the {yellow --help}.\n`
5857
)
5958
);
6059
return true;
@@ -220,9 +219,42 @@ async function run(command) {
220219
}
221220
}).start();
222221

223-
await createTree({ devMode: false }, answers);
224-
spinner.succeed("It's done, your project has been created 👌");
222+
await createTree({ devMode: false}, answers);
223+
224+
spinner.text = `Start installing NodeJs dependencies.`;
225+
const child = spawn(
226+
"npm",
227+
[
228+
"install",
229+
"-D",
230+
"ava",
231+
"eslint",
232+
"eslint-config-airbnb-base",
233+
"eslint-config-prettier",
234+
"eslint-plugin-import",
235+
"eslint-plugin-prettier",
236+
"eslint-watch",
237+
"prettier"
238+
]
239+
);
240+
241+
child.stdout.on("data", data => {
242+
spinner.text = chalk`Install {yellow ${data.toString()}} dependencies.`;
243+
});
244+
245+
child.on("close", code => {
246+
if (code !== 0) {
247+
spinner.fail();
248+
return Promise.reject(
249+
new Error(chalk`{red process fail with code ${code}}`)
250+
);
251+
}
252+
253+
spinner.succeed(chalk`{green Your project has been created, you can close the process with CTRL + C}.`);
254+
return Promise.resolve();
255+
});
225256
}
257+
226258
return true;
227259
}
228260

0 commit comments

Comments
 (0)