Skip to content

Commit b35d65f

Browse files
Simplify add practice exercise
1 parent 988df1e commit b35d65f

File tree

4 files changed

+66
-69
lines changed

4 files changed

+66
-69
lines changed

.github/ISSUE_TEMPLATE/new_exercise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
There is a new exercise, [EXERCISE-NAME](https://github.com/exercism/problem-specifications/blob/master/exercises/EXERCISE-NAME/description.md), which data can be found here: https://github.com/exercism/problem-specifications/tree/master/exercises/EXERCISE-NAME
22

3-
To implement the `EXERCISE-NAME` exercise, first run the `./add-new-exercise EXERCISE-NAME` script that will create and update the files required for the new exercise. After this script has run, it will have done the following:
3+
To implement the `EXERCISE-NAME` exercise, first run the `./add-practice-exercise EXERCISE-NAME` script that will create and update the files required for the new exercise. After this script has run, it will have done the following:
44

55
- Added a new entry for the exercise to the [config.json](https://github.com/exercism/csharp/blob/master/config.json) file.
66
- Created a default generator in the [generator/Generators/Exercise] directory, which is used to automatically convert the [canonical data](https://github.com/exercism/problem-specifications/blob/master/exercises/EXERCISE-NAME/canonical-data.json) to a test file. For more information on how this works, check the [generators docs](https://github.com/exercism/csharp/blob/master/docs/GENERATORS.md).

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ Exercism exercises in C#
88

99
Please see the [contributing guide](https://exercism.org/docs/building)
1010

11-
### Adding a new exercise
11+
### Adding a new practice exercise
1212

13-
To add a new exercise, run the `bin/add-new-exercise.ps1` PowerShell script:
13+
To add a new exercise, run the `bin/add-practice-exercise.ps1` PowerShell script:
1414

1515
```shell
16-
pwsh bin/add-new-exercise.ps1 bob
16+
pwsh bin/add-practice-exercise.ps1 bob
1717
```
1818

19-
This will create all the necessary files and tests for you.
20-
Then you just need to implement the `Example.cs` file and to check if the generated tests make sense.
21-
Parameters and examples for running the script can be found in the script file.
19+
This will add the exercise's files and output what remains to be done.
2220

2321
## Support
2422

bin/add-new-exercise.ps1

Lines changed: 0 additions & 62 deletions
This file was deleted.

bin/add-practice-exercise.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)