-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.mjs
executable file
·80 lines (75 loc) · 1.66 KB
/
menu.mjs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env -S node --experimental-modules
import { exec } from 'child_process' ;
import inquirer from 'inquirer';
const prompt = inquirer.prompt;
let operate = 1;
const questions = [
{
type: 'list',
name: 'action',
message: 'What would you like to do?',
choices: [
{
key: 'a',
name: 'Add New Research Item',
value: './bin/new/index.mjs'
},
{
key: 'u',
name: 'Update Everything',
value: './bin/make/index.mjs'
},
{
key: 'p',
name: 'Publish To Github',
value: './bin/publish/index.sh'
},
// {
// key: 'r',
// name: 'Resize Images',
// value: './bin/resize/index.sh'
// },
// {
// key: 'j',
// name: 'Convert PNG to JPG',
// value: './bin/tojpg/index.sh'
// },
{
key: 'x',
name: 'Exit Menu',
value: 'exit-menu',
},
],
},
];
function execute(answers){
return new Promise(function(OK, NO){
if(answers.action === 'exit-menu'){
operate = false;
return OK();
}
console.log(`Executing ${answers.action}`);
exec(answers.action, (err, stdout, stderr) => {
if (err) {
if(stderr) console.log(`${stderr}`);
NO(err);
} else {
if(stdout) console.log(`${stdout}`);
if(stderr) console.log(`${stderr}`);
}
})
.on('exit', (code) => {
console.log('');
operate++;
OK();
});
});
}
async function main(){
await execute({action: './bin/banner/index.mjs'})
while(operate){
const anwsers = await prompt(questions);
await execute(anwsers);
}
}
main();