-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
50 lines (32 loc) · 858 Bytes
/
generate.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
const { mkdir, writeFile } = require('fs').promises;
const { resolve } = require('path');
const PART_1_NAME = '1.js';
const PART_1_TEMPLATE = (day) => (
`// --- Day ${day.replace(/^0+/, '')} ---
module.exports = (inputs) => {
return inputs;
};
`
);
const PART_2_NAME = '2.js';
const PART_2_TEMPLATE = () => (
`// --- Part Two ---
module.exports = (inputs) => {
return inputs;
};
`
);
const INPUT_NAME = 'input.txt';
const INPUT_TEMPLATE = () => '';
const main = async () => {
const day = process.argv[2];
const dayDir = resolve(process.cwd(), day);
await mkdir(dayDir);
writeFile(resolve(dayDir, PART_1_NAME), PART_1_TEMPLATE(day));
writeFile(resolve(dayDir, PART_2_NAME), PART_2_TEMPLATE(day));
writeFile(resolve(dayDir, INPUT_NAME), INPUT_TEMPLATE(day));
};
if (require.main === module) {
main();
}
module.exports = {};