dotnet / Scaffolding

Code generators to speed up development.
MIT License
638 stars 229 forks source link

adding 'dotnet-scaffold' #2727

Closed deepchoudhery closed 5 months ago

deepchoudhery commented 5 months ago

Adding (technically updating) the dotnet-scaffold global tool.

dotnet-scaffold changes summary - dotnet-scaffold now uses **Spectre.Console** to build the commandline application instead of System.Commandline. - Using Spectre.Console.Flow to setup 'Flow' steps and then running the flow using IFlowProvider. - Flow steps provide a step-by-step paradigm to process the specific commands in very flexible manner. It allows to validate cmdline input, and provide interactivity (optional) to gather more info from the user). - Setting up the following steps: 1. StartupFlowStep - initialize MSBuild, gather environment variables 2. SourceProjectFlowStep - use the provided or user-selected project to initialize IProjectService (Roslyn and Microsoft.Build helpers) 3. CommandPickerFlowStep - use/find an appropriate command to execute from all the existing components (dotnet tools) - invoke all components with 'get-commands' - gather all commands, from all the components, and find the user selected one. - gather all the 'Parameters' from the get-commands output and then create 'ParameterBasedFlowStep'. - execute the 'ParameterBasedFlowStep's (holds info about the next step), and use/get (interactively) values for all the parameters. 4. CommandExecuteFlowStep - gather all the user input (interactive or stdin) and execute chosen command. Print the output after the execution. - For a tool to be picked up **dotnet-scaffold**, it needs to fulfill the following requirements: 1. Be a dotnet tool and be installed globally 2. Have an implementation for 'get-commands' where the output is serialized json `List`
Microsoft.DotNet.Scaffolding.Shared.Helpers changes summary
Folder structure for added projects ``` ├───src │ └───Shared │ ├───Microsoft.DotNet.Scaffolding.ComponentModel (library for that new components (dotnet tools) will have to use to make itself compatible with dotnet-scaffold │ ├───Microsoft.DotNet.Scaffolding.Helpers(optional helper library with msbuild, roslyn, system helpers) │ ├───Extensions │ │ └───Roslyn (Syntax and Workspace extensions) │ ├───General (String, CLI, Project helpers) │ ├───Roslyn (includes `ProjectModifier`, `DocumentBuilder` mainly, helps modifying and add to. c# projects). │ │ └───CodeChange (files related to config based project modification) │ ├───Services (important helper services related to System, Roslyn, MSBuild) │ │ ├───Environment (services relating to environment info and variables) │ │ └───Logging (services related to console logging) │ └───T4Templating (services needed to use the T4 generator) └───tools ├───dotnet-aspnet-codegenerator (legacy scaffolding tool) ├───dotnet-msidentity (entra-id global tool) └───dotnet-scaffold (NEW global tool) ├───AppBuilder ├───Command ├───Flow │ └───Steps │ └───Project └───Services ```
dotnet-scaffold usage (with examples) ``` 1. Install tool globally, 'dotnet tool install -g Microsoft.dotnet-scaffold' 2. Use interactively using 'dotnet scaffold' in the command line tool of your choice. ```

dotnet-scaffold help: image