-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (55 loc) · 2.02 KB
/
index.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
63
64
65
66
import inquirer from 'inquirer';
import { spawn } from 'child_process';
import { config, SCRIPTS_DIRECTORY } from './scripts.js';
const categoryQuestion = [
{
type: 'list',
name: 'category',
message: 'Category',
choices: Object.keys(config),
default: 'app'
}
];
function ask() {
inquirer.prompt(categoryQuestion).then((categoryAnswer) => {
const scriptsInCategory = Object.keys(config[categoryAnswer.category]);
const mainQuestions = [
{
type: 'list',
name: 'script',
message: `Script`,
choices: scriptsInCategory,
default: scriptsInCategory[0]
}
];
inquirer.prompt(mainQuestions).then((mainAnswer) => {
const selectedScript = config[categoryAnswer.category][mainAnswer.script];
inquirer.prompt(selectedScript.questions).then((answers) => {
const params = selectedScript.params(answers);
const scriptPath = `${SCRIPTS_DIRECTORY}/${selectedScript.script}`;
const script = spawn('sh', [scriptPath, answers.workdir, ...params]);
script.stdout.on('data', (data) => {
console.log(`${data}`);
});
script.stderr.on('data', (data) => {
console.error(`${data}`);
});
script.on('close', (code) => {
if (code === 0 && answers.appName) {
console.log(`open ~/Projects/${answers.appName}`);
}
});
}).catch(err => {
// Exit silently on interrupt or other errors
process.exit();
});
}).catch(err => {
// Exit silently on interrupt or other errors
process.exit();
});
}).catch(err => {
// Exit silently on interrupt or other errors
process.exit();
});
}
ask();