Skip to content

Commit

Permalink
Create template dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Oct 20, 2024
1 parent 704a8a0 commit 1168b94
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/new_exercise.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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

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:
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:

- Added a new entry for the exercise to the [config.json](https://github.com/exercism/fsharp/blob/master/config.json) file.
- Add a default generator to the [generator/Generators.fs] file, 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/fsharp/blob/master/docs/GENERATORS.md).
Expand Down
110 changes: 0 additions & 110 deletions add-new-exercise.ps1

This file was deleted.

66 changes: 66 additions & 0 deletions add-practice-exercise.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<#
.SYNOPSIS
Add a new exercise.
.DESCRIPTION
Add the files need to add a new exercise.
.PARAMETER Exercise
The slug of the exercise to add.
.PARAMETER Author
The author of the exercise.
.PARAMETER Difficulty
The difficulty of the exercise on a scale from 1 to 10 (optional, default: 1).
.EXAMPLE
The example below will add the "acronym" exercise
PS C:\> ./add-practice-exercise.ps1 acronym
#>

[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Position = 0, Mandatory = $true)][string]$Exercise,
[Parameter(Mandatory = $true)][string]$Author,
[Parameter()][int]$Difficulty = 1
)

$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true

# Use configlet to create the exercise
& bin/fetch-configlet
& bin/configlet create --practice-exercise $Exercise --difficulty $Difficulty --author $Author

# Create project
$exerciseName = (Get-Culture).TextInfo.ToTitleCase($Exercise).Replace("-", "")
$exerciseDir = "exercises/practice/${Exercise}"
$project = "${exerciseDir}/${ExerciseName}.fsproj"
& dotnet new xunit --force -lang "F#" --target-framework-override net8.0 -o $exerciseDir -n $ExerciseName
& dotnet sln exercises/Exercises.sln add $project

# Update project packages
& dotnet remove $project package coverlet.collector
& dotnet add $project package Exercism.Tests --version 0.1.0-beta1
& dotnet add $project package xunit.runner.visualstudio --version 2.4.3
& dotnet add $project package xunit --version 2.4.1
& dotnet add $project package Microsoft.NET.Test.Sdk --version 16.8.3

# Add tools
& dotnet new tool-manifest -o $exerciseDir
& dotnet tool install --tool-manifest "${exerciseDir}/.config/dotnet-tools.json" fantomas-tool

Remove-Item -Path "${exerciseDir}/Program.fs"
Remove-Item -Path "${exerciseDir}/Tests.fs"
Set-Content -Path "${exerciseDir}/${exerciseName}.fs" -Value "module ${exerciseName}"
Set-Content -Path "${exerciseDir}/.meta/Example.fs" -Value "module ${exerciseName}"

# Fix the includes
[xml]$proj = Get-Content $project
$proj.Project.ItemGroup[0].Compile[0].Include = "${exerciseName}.fs"
$proj.Project.ItemGroup[0].Compile[1].Include = "${exerciseName}Tests.fs"
$proj.Save($project)

# Add and run generator (this will update the tests file)
Add-Content -Path generators/Generators.fs -Value @"
type ${exerciseName}() =
inherit ExerciseGenerator()
"@
& dotnet run --project generators --exercise $Exercise
93 changes: 0 additions & 93 deletions bin/add-practice-exercise

This file was deleted.

8 changes: 0 additions & 8 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2117,14 +2117,6 @@
"lists"
],
"difficulty": 5
},
{
"slug": "resistor-color",
"name": "Resistor Color",
"uuid": "c9d95eb0-7185-489f-be04-f3e98423a50c",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
],
"foregone": [
Expand Down
7 changes: 0 additions & 7 deletions exercises/Exercises.sln
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ZebraPuzzle", "practice\zeb
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Zipper", "practice\zipper\Zipper.fsproj", "{73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ResistorColor", "practice\resistor-color\ResistorColor.fsproj", "{3B4E64ED-1090-4E2A-87D3-D758D42694A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -834,10 +832,6 @@ Global
{73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}.Release|Any CPU.Build.0 = Release|Any CPU
{3B4E64ED-1090-4E2A-87D3-D758D42694A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B4E64ED-1090-4E2A-87D3-D758D42694A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B4E64ED-1090-4E2A-87D3-D758D42694A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B4E64ED-1090-4E2A-87D3-D758D42694A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9815492D-D8F9-439C-B73C-711693755626} = {9D239135-8242-4AC0-94AE-7CCD8408B531}
Expand Down Expand Up @@ -976,6 +970,5 @@ Global
{FA29F301-0448-47A3-941C-ABB8A8ED367A} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
{F6217F6F-DD9C-4DBD-8A7A-894E05FCF78E} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
{73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
{3B4E64ED-1090-4E2A-87D3-D758D42694A8} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
EndGlobalSection
EndGlobal

0 comments on commit 1168b94

Please sign in to comment.