-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_files.js
56 lines (47 loc) · 1.72 KB
/
generate_files.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
import { dirname, join as pathJoin } from 'path';
import { fileURLToPath } from 'url';
import { promises as fs, existsSync as fsExists } from 'fs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const year = 2021;
async function generate_file(day, year = 2021) {
const entryFileName = pathJoin(__dirname, year.toString(), day.toString().padStart(2, '0') + '.js');
try {
await fs.mkdir(pathJoin(__dirname, year.toString()));
} catch(e) {}
if (await fsExists(entryFileName)) return;
await fs.writeFile(entryFileName, `import { Advent as AdventLib } from '../lib/advent.js';
const Advent = new AdventLib(${day}, ${year});
// UI library
// import Window from '../lib/window.js';
async function Run() {
const input = await Advent.GetInput();
// await Advent.Submit(null);
// await Advent.Submit(null, 2);
}
Run();
`);
console.log(`Written solution file ${day}: ${entryFileName}`);
}
async function generateSampleInput(day, year = 2021) {
// generate sample input file
const inputFileName = pathJoin(__dirname, 'inputs', year.toString(), day.toString().padStart(2, '0') + '-sample.txt');
try {
await fs.mkdir(pathJoin(__dirname, 'inputs', year.toString()));
}
catch(e) {}
if (await fsExists(inputFileName)) return;
await fs.writeFile(inputFileName, '');
}
const run = async () => {
const inputsDir = pathJoin(__dirname, 'inputs');
if (!await fsExists(inputsDir)) {
await fs.mkdir(inputsDir);
}
// get year from command line (or just use current year)
const year = Number(process.argv[2] || new Date().getFullYear());
for (let i = 1; i <= 25; i++) {
generate_file(i, year);
generateSampleInput(i, year);
}
};
run();