|
| 1 | +.SYNOPSIS |
| 2 | + Add a new exercise. |
| 3 | +.DESCRIPTION |
| 4 | + Add the files need to add a new exercise. |
| 5 | +.PARAMETER Exercise |
| 6 | + The slug of the exercise to add. |
| 7 | +.PARAMETER Author |
| 8 | + The author of the exercise. |
| 9 | +.PARAMETER Difficulty |
| 10 | + The difficulty of the exercise on a scale from 1 to 10 (optional, default: 1). |
| 11 | +.EXAMPLE |
| 12 | + The example below will add the "acronym" exercise |
| 13 | + PS C:\> ./bin/add-practice-exercise.ps1 acronym |
| 14 | +#> |
| 15 | + |
| 16 | +[CmdletBinding(SupportsShouldProcess)] |
| 17 | +param ( |
| 18 | + [Parameter(Position = 0, Mandatory = $true)][string]$Exercise, |
| 19 | + [Parameter(Mandatory = $true)][string]$Author, |
| 20 | + [Parameter()][int]$Difficulty = 1 |
| 21 | +) |
| 22 | + |
| 23 | +$ErrorActionPreference = "Stop" |
| 24 | +$PSNativeCommandUseErrorActionPreference = $true |
| 25 | + |
| 26 | +# Use configlet to create the exercise |
| 27 | +& bin/fetch-configlet |
| 28 | +& bin/configlet create --practice-exercise $Exercise --difficulty $Difficulty --author $Author |
| 29 | + |
| 30 | +# Create project |
| 31 | +$exerciseName = (Get-Culture).TextInfo.ToTitleCase($Exercise).Replace("-", "") |
| 32 | +$exerciseDir = "exercises/practice/${Exercise}" |
| 33 | +$project = "${exerciseDir}/${ExerciseName}.csproj" |
| 34 | +& dotnet new xunit --force -lang "C#" --target-framework-override net8.0 -o $exerciseDir -n $ExerciseName |
| 35 | +& dotnet sln exercises/Exercises.sln add $project |
| 36 | + |
| 37 | +# Update project packages |
| 38 | +& dotnet remove $project package coverlet.collector |
| 39 | +& dotnet add $project package Exercism.Tests --version 0.1.0-beta1 |
| 40 | +& dotnet add $project package xunit.runner.visualstudio --version 2.4.3 |
| 41 | +& dotnet add $project package xunit --version 2.4.1 |
| 42 | +& dotnet add $project package Microsoft.NET.Test.Sdk --version 16.8.3 |
| 43 | + |
| 44 | +# Remove and update files |
| 45 | +Remove-Item -Path "${exerciseDir}/UnitTest1.cs" |
| 46 | +Remove-Item -Path "${exerciseDir}/GlobalUsings.cs" |
| 47 | +(Get-Content -Path ".editorconfig") -Replace "\[\*\.cs\]", "[${exerciseName}.cs]" | Set-Content -Path (Join-Path "${exerciseDir}" -ChildPath ".editorconfig") |
| 48 | + |
| 49 | +# Add and run generator (this will update the tests file) |
| 50 | +Add-Content -Path "generators/Exercises/Generators/${ExerciseName}.cs" -Value @" |
| 51 | +using System; |
| 52 | +
|
| 53 | +using Exercism.CSharp.Output; |
| 54 | +
|
| 55 | +namespace Exercism.CSharp.Exercises.Generators; |
| 56 | +
|
| 57 | +internal class ${ExerciseName} : ExerciseGenerator |
| 58 | +{ |
| 59 | +} |
| 60 | +"@ |
| 61 | +& dotnet run --project generators --exercise $Exercise |
0 commit comments