-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·60 lines (51 loc) · 1.54 KB
/
cli.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
#!/usr/bin/env node
const fs = require("fs");
const readline = require("readline");
const { init, banner, getValidName, setupOptions } = require("./installer.js");
const projectFolder = process.argv.slice(2)[0];
if (!projectFolder) {
console.log(':: Invalid folder name! Please, pick another name.');
process.exit(1);
}
else if (fs.existsSync(projectFolder)) {
console.log(':: Directory already exists! Please, pick another name.');
process.exit(1);
}
else {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const projectFileTree = {
[projectFolder]: {}
}
console.log(banner);
const based = async () => {
try {
if (!setupOptions.length) {
init(projectFileTree);
}
setupOptions.forEach((option) => {
question(option);
});
} catch (err) {
console.log(`:: Something went wrong!! Please try again...${err.message}`);
process.exit(1);
}
}
const question = async (option) => {
await rl.question(option.question, (folderName) => {
const _folderName = getValidName(folderName, option.default);
projectFileTree[projectFolder][option.parent ?? _folderName] = _folderName;
if (option.child) {
rl.question(option.child.question, (fileName) => {
projectFileTree[projectFolder][_folderName] = getValidName(fileName, option.child.default);
question(setupOptions[setupOptions.indexOf(option) + 1]);
});
}
setupOptions.shift();
based();
});
}
based();
}