generated from MJGTwo/advent-of-code-nodets-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
75 lines (62 loc) · 2.3 KB
/
setup.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
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
import { run, position } from "promise-path";
import { reportGenerator, replaceInFile } from "./util.ts";
import { fileURLToPath } from 'url'
import path from 'path'
const __filename = fileURLToPath(import.meta.url)
const report = reportGenerator(__filename);
const fromHere = position(path.dirname(__filename));
const setup = async (): Promise<void> => {
const currentPath: string = fromHere("/");
console.log(currentPath);
const currentFolder: string = currentPath.split("/").reverse()[1];
report("Setting up template from:", currentFolder);
const currentYear: string | undefined = currentFolder.split("-").pop();
if (currentYear === "template") {
console.error(" No current year provided.");
console.error(
" Please re-run setup after renaming the repo, e.g.: advent-of-code-2020, advent-of-code-2021, advent-of-code-2022, etc."
);
console.error("");
process.exit(0);
}
report("Replacing strings in templates");
await replaceInFile(
"README.md",
"If using the Advent of Code Template repo; click [**`Use this template`**](https://github.com/johnbeech/advent-of-code-nodejs-template/generate) and set a new repository name.\n",
""
);
await replaceInFile(
"README.md",
"If this a brand new repository, run: `node setup` to configure it for Current Year and check in the changes.\n",
""
);
await replaceInFile(
"package.json",
/Advent of Code Template/g,
`Advent of Code ${currentYear}`
);
await replaceInFile(
"README.md",
"# Advent of Code Template",
`# Advent of Code ${currentYear}`
);
await replaceInFile(
"package.json",
"Advent of Code Template using Node JS for Current Year.",
`My solutions for Advent of Code ${currentYear}.`
);
await replaceInFile(
"README.md",
"Advent of Code Template using Node JS for Current Year.",
`My solutions for Advent of Code ${currentYear}.`
);
await replaceInFile("package.json", "advent-of-code-template", currentFolder);
report("Removing setup script");
await run(`rm ${fromHere("setup.js")}`);
report("Committing changes and pushing to remote");
await run("git add .");
await run(`git commit -m "Setup template for Current Year (${currentYear})"`);
await run("git push");
report(`All done! ${currentYear} setup and ready to go~`);
};
setup();