forked from csaunders-ldt/advent2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.ts
36 lines (33 loc) · 964 Bytes
/
next.ts
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
import {
mkdirSync,
readdirSync,
writeFileSync,
copyFile,
existsSync,
rmSync,
} from 'fs';
import { config } from 'dotenv';
import { map, sortBy } from 'lodash';
config();
const files = readdirSync('.');
const existingDays = files.filter((file) => file.startsWith('day'));
const dayNumbers = map(existingDays, (day) =>
parseInt(day.replace('day', ''), 10),
);
const lastDayNumber = sortBy(dayNumbers)[dayNumbers.length - 1] || 0;
const day = lastDayNumber + 1;
const folder = `day${day}`;
mkdirSync(folder);
copyFile('_template/index.ts', `${folder}/index.ts`, () => {});
writeFileSync(`${folder}/solutions.txt`, '');
fetch(`https://adventofcode.com/2022/day/${day}/input`, {
headers: {
cookie: `session=${process.env.SESSION}`,
},
})
.then((res) => res.text())
.then((text) => writeFileSync(`${folder}/input.txt`, text));
if (existsSync('./index.ts')) {
rmSync('./index.ts');
}
writeFileSync('./index.ts', `import './day${day}';`);