@@ -72,76 +72,3 @@ tasks {
7272 useJUnitPlatform()
7373 }
7474}
75-
76- tasks.register(" prepareNextDay" ) {
77- var day = 0
78- var packageId = " "
79-
80- doFirst {
81- day = properties[" day" ]?.toString()?.toInt() ? : 0
82- packageId = properties[" packageId" ]?.toString() ? : " tr.emreone.adventofcode"
83- }
84-
85- doLast {
86- val nextDay = day.toString().padStart(2 , ' 0' )
87- val withTest = true
88- val packageIdPath = packageId.replace(" ." , " /" )
89-
90- val mainFile = " ${projectDir} /src/main/kotlin/${packageIdPath} /Main.kt"
91- val readmeFile = " ${projectDir} /README.md"
92- val newSrcFile = " ${projectDir} /src/main/kotlin/${packageIdPath} /days/Day${nextDay} .kt"
93- val newTestFile = " ${projectDir} /src/test/kotlin/${packageIdPath} /days/Day${nextDay} Test.kt"
94-
95- if (file(newSrcFile).exists()) {
96- println (" WARNING: Files for Day$nextDay already exists. Do you really want to overwrite it?" )
97- } else {
98- file(newSrcFile).writeText(
99- file(" ${projectDir} /template/DayX.kt" )
100- .readText()
101- .replace(" $1" , nextDay)
102- )
103-
104- file(" ${projectDir} /src/main/resources/day${nextDay} .txt" )
105- .writeText(" " )
106-
107- file(mainFile).writeText(
108- file(mainFile).readText()
109- .replace(
110- " // $1" , """
111- | fun solveDay${nextDay} () {
112- | val input = Resources.resourceAsList(fileName = "day${nextDay} .txt")
113- |
114- | val solution1 = Day${nextDay} .part1(input)
115- | logger.info { "Solution1: ${" $" } solution1" }
116- |
117- | val solution2 = Day${nextDay} .part2(input)
118- | logger.info { "Solution2: ${" $" } solution2" }
119- | }
120- |// ${" $1" }
121- """ .trimMargin()
122- )
123- )
124-
125- file(readmeFile).writeText(
126- file(readmeFile).readText()
127- .replace(
128- " <!-- $1 -->" , """
129- |[Day ${nextDay} ](https://adventofcode.com/2022/day/${nextDay} ) | [Day${nextDay} Test.kt](https://github.com/EmRe-One/advent-of-code-2022/blob/master/src/test/kotlin/tr/emreone/adventofcode/days/Day${nextDay} Test.kt) | [Day${nextDay} .kt](https://github.com/EmRe-One/advent-of-code-2022/blob/master/src/main/kotlin/tr/emreone/adventofcode/days/Day${nextDay} .kt) | | |
130- ${" <!-- $1 -->" }
131- """ .trimIndent()
132- )
133- )
134-
135- if (withTest) {
136- file(newTestFile).writeText(
137- file(" ${projectDir} /template/DayXTest.kt" )
138- .readText()
139- .replace(" $1" , nextDay)
140- )
141-
142- file(" ${projectDir} /src/test/resources/day${nextDay} _example.txt" )
143- .writeText(" " )
144- }
145- }
146- }
147- }
0 commit comments