-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (51 loc) · 1.37 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
const { readdirSync } = require('fs');
const prompts = require('prompts');
const [dayOrAction, maybeAction] = process.argv.slice(2);
const isDayFirst = !(dayOrAction === 'test' || dayOrAction === 'main');
const actionArg = maybeAction || (!isDayFirst ? dayOrAction : undefined);
const dayArg = isDayFirst ? dayOrAction : undefined;
(async () => {
// read folders from current directory
const days = readdirSync('./').filter((file) => file.startsWith('day'));
// prompt user for day
const day =
dayArg ||
(
await prompts({
type: 'select',
name: 'day',
message: 'Select day',
choices: ['all', ...days.map((day) => ({ title: day, value: day }))],
})
).day;
// prompt user for action
const action =
actionArg ||
(
await prompts({
type: 'select',
name: 'action',
message: 'Select action',
choices: [
{ title: 'Run main', value: 'main' },
{ title: 'Run test', value: 'test' },
],
})
).action;
if (day === 'all') {
for (const day of days) {
console.log(`Running ${day}...`);
await run(day, action);
}
return;
}
run(day, action);
})();
async function run(day, action) {
const { main, test } = await import(`./${day}/index.js`);
if (action === 'main') {
main();
} else if (action === 'test') {
test();
}
}