-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartNewDay.fsx
154 lines (120 loc) · 3.99 KB
/
StartNewDay.fsx
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#r "nuget: Nustache"
open System
open System.Diagnostics
open Nustache.Core
open System.IO
open System.Text
let day = fsi.CommandLineArgs |> Array.tail |> Array.exactlyOne |> int
let template = {| day = day |}
let createFolder nameTemplate =
let name = Render.StringToString(nameTemplate, template)
printfn $"📂 {name}"
if name |> Directory.Exists |> not then
Directory.CreateDirectory(name) |> ignore
let addFile (nameTemplate: string) (contentTemplate: string) =
let name = Render.StringToString(nameTemplate, template)
printfn $"📃 {name}"
let content = Render.StringToString(contentTemplate.TrimStart(), template)
File.WriteAllText(name, content, new UTF8Encoding(encoderShouldEmitUTF8Identifier = true))
let exec command argumentsTemplate =
let arguments = Render.StringToString(argumentsTemplate, template)
printfn $"📦 {command} {arguments}"
Process.Start(command, arguments).WaitForExit()
createFolder "AdventOfCode2021.Day{{{day}}}"
let templateMainProject =
@"AdventOfCode2021.Day{{{day}}}\AdventOfCode2021.Day{{{day}}}.fsproj"
addFile
templateMainProject
"
<Project Sdk=\"Microsoft.NET.Sdk\">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>25</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include=\"Solution.fs\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=\"..\\AdventOfCode2021.Common\\AdventOfCode2021.Common.fsproj\" />
</ItemGroup>
</Project>
"
addFile
@"AdventOfCode2021.Day{{{day}}}\Solution.fs"
"
namespace AdventOfCode2021.Day{{{day}}}
open AdventOfCode2021.Common
module Solution =
let calc inputs = -1
let part1 = calc
let part2 = calc
"
createFolder "AdventOfCode2021.Day{{{day}}}.Tests"
let templateTestProject =
@"AdventOfCode2021.Day{{{day}}}.Tests\AdventOfCode2021.Day{{{day}}}.Tests.fsproj"
addFile
templateTestProject
"
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Project Sdk=\"Microsoft.NET.Sdk\">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>25</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include=\"..\\AdventOfCode2021.Common\\AdventOfCode2021.Common.fsproj\" />
<ProjectReference Include=\"..\\AdventOfCode2021.Day{{{day}}}\\AdventOfCode2021.Day{{{day}}}.fsproj\" />
</ItemGroup>
<ItemGroup>
<Compile Include=\"UnitTests.fs\" />
<Content Include=\"inputs.txt\">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project=\"..\\.paket\\Paket.Restore.targets\" />
</Project>
"
addFile
@"AdventOfCode2021.Day{{{day}}}.Tests\paket.references"
"
NUnit
NUnit3TestAdapter
Microsoft.NET.Test.Sdk
Unquote
coverlet.collector
"
addFile
@"AdventOfCode2021.Day{{{day}}}.Tests\UnitTests.fs"
"
module AdventOfCode2021.Day{{{day}}}.Tests
open System.IO
open AdventOfCode2021.Common
open AdventOfCode2021.Day{{{day}}}
open NUnit.Framework
open Swensen.Unquote
let getSample () =
\"
TODO
\"
|> String.splitLines
|> Array.filter String.notNullOrEmpty
let getInputs () = \"inputs.txt\" |> File.ReadAllLines
[<Test>]
let ``1-1 Test part1 with sample`` () = (-1 , (Solution.part1 (getSample ()))) ||> shouldEqual
[<Test>]
let ``1-2 Test part1 with inputs`` () = (-1 , (Solution.part1 (getInputs ()))) ||> shouldEqual
[<Test>]
let ``2-1 Test part1 with sample`` () = (-1 , (Solution.part2 (getSample ()))) ||> shouldEqual
[<Test>]
let ``2-2 Test part1 with inputs`` () = (-1 , (Solution.part2 (getInputs ()))) ||> shouldEqual
[<EntryPoint>]
let main _ = 0
"
addFile @"AdventOfCode2021.Day{{{day}}}.Tests\inputs.txt" "TODO"
exec "dotnet" $"sln add \"{templateMainProject}\""
exec "dotnet" $"sln add \"{templateTestProject}\""