forked from exercism/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-exercise-tools.ps1
68 lines (55 loc) · 2.01 KB
/
update-exercise-tools.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<#
.SYNOPSIS
Add dotnet tools to exercises.
.DESCRIPTION
For each exercise, create a tool manifest and add/upgrade fantomas.
.PARAMETER FantomasVersion
Target version of the `fantomas-tool` NuGet package (defaults to current latest version).
.EXAMPLE
PS C:\> ./update-exercise-tools.ps1
.EXAMPLE
PS C:\> ./update-exercise-tools.ps1 4.4.0
#>
param (
[Parameter(Position = 0, Mandatory = $false)]
[string]$FantomasVersion="4.5.2"
)
# Import shared functionality
. ./shared.ps1
function Add-Tools {
Param ($Path="exercises")
# explicitly ignore dot directories as Windows will not treat them as hidden
$dir=Get-ChildItem -Directory $Path -Exclude @(".*", "bin", "obj")
# recur to bottom of directory tree
If ($dir.Count -eq 0) {
# make sure this directory contains a project
$isProjectDir=(Test-Path "$Path/*.fsproj")
$manifestPath="$Path/.config/dotnet-tools.json"
# check for an existing tool manifest
$hasManifest=(Test-Path $manifestPath)
# validate version number
$hasValidToolVersion=($FantomasVersion -match '^(\d+\.){2}\d+$')
# assume tools are out of date
$needsUpdate=$true
$versionArg=$null
If ($hasValidToolVersion -and $hasManifest) {
$currentVersion=(
Get-Content -Raw -Path $manifestPath | ConvertFrom-Json
).tools."fantomas-tool".version
$needsUpdate=($currentVersion -ne $FantomasVersion)
}
If ($isProjectDir -and $needsUpdate) {
If ($hasValidToolVersion) {
$versionArg="--version $FantomasVersion"
}
Write-Output "Writing tool manifest to $Path/.config"
Run-Command "dotnet new tool-manifest -o $Path --force"
Run-Command "dotnet tool install --tool-manifest $manifestPath fantomas-tool $versionArg"
}
} Else {
$dir | ForEach-Object {Add-Tools $_.FullName}
}
}
Write-Output "Adding dotnet tools"
Add-Tools
exit $LastExitCode