-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.mjs
64 lines (62 loc) · 1.5 KB
/
plopfile.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
export default function (
/** @type {import('npm:plop').NodePlopAPI} */
plop
) {
const date = new Date();
const currentYear = date.getFullYear().toString();
const currentDay = date.getDate().toString();
plop.setHelper("pad", (s, size) => {
return s.padStart(size, "0");
});
plop.setGenerator("day", {
description: "Advent of Code day",
prompts: [
{
type: "input",
message: "Year",
name: "year",
default: currentYear,
validate(input) {
if (input.length !== 4) {
return "Year must be 4 digits";
}
if (isNaN(parseInt(input))) {
return "Year must be a number";
}
return true;
},
},
{
type: "input",
message: "Day",
name: "day",
default: currentDay.padStart(2, "0"),
validate(input) {
if (input.length !== 2) {
return "Day must be 2 digits";
}
if (isNaN(parseInt(input))) {
return "Day must be a number";
}
return true;
},
},
],
actions: [
{
type: "add",
path: "{{year}}/{{pad day 2}}/solution.ts",
templateFile: "./templates/solution.hbs",
},
{
type: "add",
path: "{{year}}/{{pad day 2}}/solution.test.ts",
templateFile: "./templates/solution.test.hbs",
},
{
type: "add",
path: "{{year}}/{{pad day 2}}/example.txt",
},
],
});
}