/
_createFiles.mjs
76 lines (57 loc) · 1.89 KB
/
_createFiles.mjs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import fs from 'fs';
const yearStart = 2015;
const yearEnd = 2023;
for (let year = yearStart; year <= yearEnd; year++) {
let filePath = `./${year.toString()}`;
if (!fs.existsSync(filePath)) fs.mkdirSync(filePath);
for (let day = 1; day <= 25; day++) {
const sDay = 'day' + day.toString().padStart(2, '0');
const dayPath = `${filePath}/${sDay}`;
if (!fs.existsSync(dayPath)) fs.mkdirSync(dayPath);
if (!fs.existsSync(`${dayPath}/example.txt`))
fs.writeFileSync(`${dayPath}/example.txt`, '', 'utf8');
if (!fs.existsSync(`${dayPath}/input.txt`))
fs.writeFileSync(`${dayPath}/input.txt`, '', 'utf8');
if (!fs.existsSync(`${dayPath}/index.mjs`))
fs.writeFileSync(`${dayPath}/index.mjs`, `// https://adventofcode.com/${year}/day/${day}
import { readFileSync } from 'fs'
const readFile = (filePath) => {
const contents = readFileSync(filePath, 'utf-8');
return contents.trim().split('\\n');
}
export const getOutputPart1 = (fileName) => {
const inputs = readFile(fileName);
let result = 0;
// console.log({ result });
return result;
}
export const getOutputPart2 = (fileName) => {
const inputs = readFile(fileName);
let result = 0;
// console.log({ result });
return result;
}
// getOutputPart1("${dayPath}/example.txt");
// getOutputPart2("${dayPath}/example.txt");
`, 'utf8');
if (!fs.existsSync(`${dayPath}/index.spec.mjs`))
fs.writeFileSync(`${dayPath}/index.spec.mjs`, `import { expect } from 'chai';
import { getOutputPart1, getOutputPart2 } from './index.mjs';
const fileName = '${dayPath}/input.txt';
describe.skip('Advent ${year}, day ${day}', () => {
describe('part 1', () => {
const result = getOutputPart1(fileName);
it('should work', () => {
expect(result).to.equal(0);
});
});
describe('part 2', () => {
const result = getOutputPart2(fileName);
it('should work', () => {
expect(result).to.equal(0);
});
});
});`, 'utf8');
}
}
console.log('👍');