-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Description
Not sure if this has been already discussed, but Plaster could benefit from becoming a DSL in Powershell.
Some of the benefits from doing this would be:
- PlasterManifest.xml could become *.Plaster.ps1 (head nod to Pester, PSDeploy, psake, and other modules)
- The manifest Content section could then use
foreachloops to create multiple files from array input. (Since this is now a .ps1 file.) (It would resolve Ability to loop through multi-choice parameter #332, Accept collections in plaster parameters #274, and i think New XML Parameter type - Array #312) - Readability of the manifest file, and creation of the manifest becomes simpler.
- Powershell's Data Sections allows you to scope specific cmdlets to be used in sections. Making the DSL magic happen. (Link: https://technet.microsoft.com/en-us/library/dd347678.aspx)
The XML nodes in the PlasterManifest.xml are already mostly DSL words, here is an example manifest:
Manifest "Plaster Manifest Template" {
Metadata {
Name "NewPlasterTemplate"
ID "bcd7b44b-0fda-4a08-9857-3e064abd6e2b"
Version 0.0.1
Title "A new Plaster Manifest"
Description "A short description"
Author "Brent W"
Tags Tag1, Tag2, Tag3, etc...
}
Parameters {
Text "ModuleName" "Enter the name of the module"
Choices "License" "Select a license for your module" "Apache" {
Choice '&Apache' "Adds an Apache license file." "Apache"
Choice '&MIT' "Adds an MIT license file." "MIT"
Choice '&None' "No license specified." "None"
}
MultiChoice 'Options' 'Select desired options' @("Pester", "PSake","Git") {
Choice '&Pester test support' "Adds Tests directory and a starter Pester Tests file." "Pester"
Choice 'P&Sake build script' "Adds a PSake build script that generates the module directory for publishing to the PSGallery." "PSake"
Choice '&Git' "Adds a .gitignore file." "Git"
Choice '&None' "No options specified." "None"
}
MultiChoice 'FruitSelection' 'Please pick some fruit' @("Apple", "Banana") {
Choice '&Apple' "Pick an Apple" "Apple"
Choice '&Banana' "Pick a Banana" "Banana"
Choice '&Grapes' "Pick a cluster of grapes" "Grapes"
}
Other 'FullName' 'Enter your full name' 'user-fullname'
}
Content {
File 'ReleaseNotes.md' ''
Directory "src\bin"
File 'Tests\*.tests.ps1' 'test\' {
$PLASTER_PARAM_Options -contains "Pester"
}
TemplateFile 'en-US\about_Module.help.txt' 'en-US\about_${PLASTER_PARAM_ModuleName}.help.txt'
foreach ($fruit in $PLASTER_PARAM_FruitSelection) {
TemplateFile '$fruit.json.txt' 'Fruits\$fruit.json'
}
}
Kevin Marquette wrote some good articles on creating a DSL:
https://kevinmarquette.github.io/2017-02-26-Powershell-DSL-intro-to-domain-specific-languages-part-1/
I think the Data Sections could help scope cmdlets as well, not sure if it could replace the constrained runspaces (It would require all scaffolded files to become DSL formatted as well, which is a big ask.)
Metadata
Metadata
Assignees
Labels
No labels