forked from exercism/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-track-files.ps1
54 lines (43 loc) · 1.64 KB
/
copy-track-files.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<#
.SYNOPSIS
Copy track files.
.DESCRIPTION
Copy global, track-specific files that are applicable to each exercise.
.PARAMETER Exercise
The slug of the exercise to be analyzed (optional).
.EXAMPLE
The example below will copy the track-specific files to all exercises
PS C:\> ./copy-track-files.ps1
.EXAMPLE
The example below will copy the track-specific files to the "acronym" exercise
PS C:\> ./copy-track-files.ps1 acronym
#>
param (
[Parameter(Position = 0, Mandatory = $false)]
[string]$Exercise
)
# Import shared functionality
. ./shared.ps1
function Copy-TrackFilesForExercise ($ExerciseDirectory) {
$exerciseName = (Get-Culture).TextInfo.ToTitleCase($ExerciseDirectory.Name).Replace("-", "")
$defaultEditorConfigSettings = Get-Content -Path ".editorconfig"
$editorConfigSettings = $defaultEditorConfigSettings.Replace( "[*.cs]", "[${exerciseName}.cs]")
$exerciseEditorConfigPath = Join-Path $ExerciseDirectory.FullName ".editorconfig"
Set-Content -Path $exerciseEditorConfigPath $editorConfigSettings
}
function Copy-TrackFilesForTrack {
param (
[Parameter(Position = 0, Mandatory = $false)]
[string]$Exercise
)
Write-Output "Copying generic track files"
$filter = if ($Exercise) { $($Exercise) } else { @() }
Get-Childitem -Path "exercises\practice" -Filter $filter -Directory | ForEach-Object {
Copy-TrackFilesForExercise -ExerciseDirectory $_
}
Get-Childitem -Path "exercises\concept" -Filter $filter -Directory | ForEach-Object {
Copy-TrackFilesForExercise -ExerciseDirectory $_
}
}
Copy-TrackFilesForTrack $Exercise
exit $LastExitCode