-
Notifications
You must be signed in to change notification settings - Fork 0
/
Add-NewDay.ps1
33 lines (27 loc) · 1.01 KB
/
Add-NewDay.ps1
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
Param(
[parameter(Mandatory=$true)]
[ValidateRange(1, 25)]
[int]
$Day,
[String]
$SourcePackage="dayx"
)
$TargetPackage = "day$Day"
$TargetToml = "$TargetPackage/Cargo.toml"
$TargetMain= "$TargetPackage/src/main.rs"
$WorkspaceToml = "Cargo.toml"
$TempFile = ".tempFile"
$CommitMsg ="$Day`: Add Skeleton"
Copy-Item -Recurse $SourcePackage -Destination $TargetPackage
(Get-Content -Path $TargetToml ) -Replace $SourcePackage, $TargetPackage | Add-Content -Path $TempFile
Remove-Item $TargetToml
Move-Item -Force -Path $TempFile -Destination $TargetToml
(Get-Content -Path $TargetMain ) -Replace $SourcePackage, $TargetPackage | Add-Content -Path $TempFile
Move-Item -Force -Path $TempFile -Destination $TargetMain
$Search="`"$SourcePackage`""
$Replace ="`"$SourcePackage`",`r`n `"$TargetPackage`""
(Get-Content -Path $WorkspaceToml) -Replace $Search, $Replace | Add-Content -Path $TempFile
Move-Item -Force -Path $TempFile -Destination $WorkspaceToml
git add $TargetPackage
git add $WorkspaceToml
git commit -m $CommitMsg