moon
moon copied to clipboard
[feature] Generator command execution
I am currently attempting to setup a .NET monorepo with templates for generating new projects, but to actually completely instantiate the project, I would need to both create the project files and add the project to the .sln file at the top level of the repository.
The best way to handle this would be to actually forgo the templating entirely, and instead prompt the user for inputs such as project name, root namespace, dotnet template, etc. and compose a dotnet new command from those inputs. Similar to what nx-dotnet does for nx.
My ideal generator would look something like this:
template.yml:
title: "Class Library"
description: "Scaffolds a class library project, including source and test projects"
destination: "/"
variables:
project_name:
type: string
required: true
prompt: "Enter a name for the project:"
project_template:
type: string
required: true
prompt: "Enter the project template:"
test_project_template:
type: string
required: true
prompt: "Enter the test project template:"
command: >
"dotnet new {{project_template}} -o 'lib/src/{{project_name | lower_case}}' -n '{{project_name | pascal_case}}' &&"
"dotnet new {{test_project_template}} -o 'lib/test/{{project_name | lower_case}}.test' -n '{{project_name | pascal_case}}' &&"
"dotnet solution add 'lib/src/{{project_name | lower_case}}/{{project_name | pascal_case}}.csproj' &&"
"dotnet solution add 'lib/test/{{project_name | lower_case}}.test/{{project_name | pascal_case}}.Test.csproj'"
Used as follows:
$ moon g library
library ──────────────────────────────────────────────────────────────────────────────
Class Library
Scaffolds a class library project, including source and test projects
✔ Enter a name for the project: SomeLibrary
✔ Enter the project template: classlib
✔ Enter the test project template: nunit
Executing command: dotnet new classlib -o 'lib/src/somelibrary' -n SomeLibrary && dotnet new nunit -o 'lib/test/somelibrary.test' -n 'SomeLibrary.Test' && dotnet solution add 'lib/src/somelibrary/SomeLibrary.csproj' && dotnet solution add 'lib/test/somelibrary.test/SomeLibrary.Test.csproj'
Another option would be to implement this as a task, but tasks do not have a builtin mechanism for prompting the user, so they would have to be implemented with shell commands and interactive: true, but that may introduce portability issues.