-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
85 lines (68 loc) · 2.21 KB
/
app.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require('./bootstrap');
const {terminal, fs, dirname} = global;
(() => {
global.headless = true;
mainMenu();
})();
function mainMenu() {
terminal.clear();
terminal.cyan('Menu principal\n');
terminal.cyan('Que souhaitez-vous faire ?\n');
const items = ['exercices', 'scraping', 'traitement', 'quitter'];
terminal.gridMenu(items, (error, response) => {
if (error) return;
const {selectedIndex, selectedText, x, y} = response;
if ('quitter' === selectedText) {
terminal("\r\nBye !\n\r\n");
process.exit();
return;
}
const choices = {
exercices: {
path: `${dirname(require.main.filename)}/exercices`,
message: 'Choisissez un exercice',
directories: true
},
scraping: {
path: `${dirname(require.main.filename)}/projet`,
message: 'Choisissez un projet',
directories: true
},
traitement: {
path: `${dirname(require.main.filename)}/scripts`,
message: 'Choisissez un script'
}
};
const choice = choices[selectedText] ?? {};
if (!!choice) return _genericMenu(choice);
process.exit();
});
}
function _genericMenu(
{
path = `${dirname(require.main.filename)}`,
message = "Choisissez une entrée",
directories = false,
back = true
}) {
terminal.clear();
terminal.cyan(`${message} :\n\r`);
let items = fs.readdirSync(path);
if (!directories) items = items.filter(e => -1 < e.indexOf('.js')).map(e => e.replace('.js', ''))
if (back) items.push('retour');
items.push('quitter');
terminal.gridMenu(items, (error, response) => {
const {selectedIndex, selectedText, x, y} = response;
if ('quitter' === selectedText) {
terminal("\r\nBye !\n\r\n");
process.exit();
return;
}
if ('retour' === selectedText) return mainMenu();
terminal.clear();
global.projectPath = `${path}/${selectedText}`;
require(projectPath);
terminal.clear();
process.exit();
});
}