-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.ts
29 lines (24 loc) · 1.03 KB
/
create.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
import { exists, writeFile } from './lib/util'
import { mkdirSync } from 'fs';
const baseDate = new Date(2021, 10, 30, 7, 0, 0), // I'm in CET so using this will give me the current puzzle # that is unlocked
now = new Date(),
timeDiff = now.getTime() - baseDate.getTime(),
currentPuzzleDay = Math.floor(timeDiff / (1000 * 3600 * 24));
const puzzleTemplate = (day: number): string => {
return `
import { getPuzzleInput } from '../../lib/util';
getPuzzleInput(${day}).then((input) => {
const lines = input.split("\\n")
})
`
}
const puzzleFilename = ( puzzleNum: number): string => `./days/day${currentPuzzleDay}/puzzle${puzzleNum}.ts`
exists(puzzleFilename(1)).then(async (puzzleFileExists) => {
if(puzzleFileExists) {
console.log(`Files for day ${currentPuzzleDay} already exist. Wait until the next puzzle is published.`);
} else {
mkdirSync(`./days/day${currentPuzzleDay}`)
await writeFile(puzzleFilename(1), puzzleTemplate(currentPuzzleDay))
await writeFile(puzzleFilename(2), puzzleTemplate(currentPuzzleDay))
}
})