-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_reset-all.js
56 lines (40 loc) · 1.29 KB
/
_reset-all.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
const fs = require('fs/promises');
const createJs = (day = 1) =>
`const fs = require('fs/promises');
const path = require('path');
/** @returns {Promise<string[]>} */
const getParsedData = async (file = 'data.txt') => {
const data = await fs.readFile(path.resolve(__dirname, file), 'utf8');
return data.split(/\\r?\\n/);
};
const day${day} = async () => {
const lines = await getParsedData();
console.log(lines)
};
module.exports = day${day};
`;
const createReadme = (day = 1) => `[Back](../README.md)
# Day ${day}: [Problem Name]
[Code](./index.js)
## Part One
> **PROMPT _PART 1_**
---
## Part Two
> **PROMPT _PART 2_**
`;
const main = async () => {
const folders = await fs.readdir(__dirname);
const dayFolders = folders.filter(folder => folder.startsWith('day'));
for (const dayFolder of dayFolders) {
const day = dayFolder.match(/\d+/gi)[0].padStart(2, '0');
const jsPath = `${__dirname}/${dayFolder}/index.js`;
const readmePath = `${__dirname}/${dayFolder}/README.md`;
const txtPath = `${__dirname}/${dayFolder}/data.txt`;
await fs.writeFile(jsPath, createJs(day));
await fs.writeFile(readmePath, createReadme(day));
await fs.writeFile(txtPath, '');
console.log('Reset day: ', day);
}
console.log('Done!');
};
main();