-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-day.civet
48 lines (37 loc) · 1.12 KB
/
create-day.civet
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
fs from fs
path from path
process from process
axios from axios
dotenv from dotenv
dotenv.config()
unless process.env.SESSION
console.error 'Error: SESSION environment variable not set'
process.exit 1
unless process.env.YEAR
console.error 'Error: YEAR environment variable not set'
process.exit 1
unless process.argv.2
console.error 'Error: day number not provided'
process.exit 1
dirName := process.argv.2.padStart 2, '0'
dirPath := path.join process.cwd(), 'src', dirName
unless fs.existsSync dirPath
fs.mkdirSync dirPath, recursive: true
fs.writeFileSync
path.join(dirPath, 'index.civet'),
`{ log, getLines } from ../utils.civet\n\nlines := getLines import.meta.url\n`
console.log `✅ ${dirName}/index.civet`
fs.writeFileSync
path.join(dirPath, 'story.md'),
''
console.log `✅ ${dirName}/story.md`
day := parseInt dirName
year := parseInt process.env.YEAR
axios.get `https://adventofcode.com/${year}/day/${day}/input`,
headers:
Cookie: `session=${process.env.SESSION}`
.then { data } =>
fs.writeFileSync
path.join(dirPath, 'input.txt'),
data
console.log `✅ ${dirName}/input.txt`