choco icon indicating copy to clipboard operation
choco copied to clipboard

Feature Request: Add script to `choco new` templates to remove comments from `ps1` and `nuspec` files

Open corbob opened this issue 5 years ago • 3 comments

Currently there is a comment at the top of the chocolateyinstall.ps1 and chocolateyuninstall.ps1 files:

# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:
#   $f='c:\path\to\thisFile.ps1'
#   gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f

Would it be possible to move this code to a PowerShell script beside the nuspec file that runs on all of the ps1 files? This script could also remove all comments from the nuspec file as well.

Or, as another option: could this action be done as part of the choco pack process? Akin to minifying javascript before deploying to a website.

If this is something that would be desired, I have been working on a script in my own repo that I could contribute.

corbob avatar Apr 19 '20 22:04 corbob

Removing by pack could be a definite option! However curious how to only remove the template comments versus something folks have added themselves?

ferventcoder avatar May 16 '20 03:05 ferventcoder

Perhaps you could add a chocolatey-specific token to the help lines, or move the lines to a document / example markdown with powershell? It would likely make sense to reduce noise in the scaffolding files. Perhaps the option to generate more detailed scaffolding could be non-default new option?

This should be part of the nuget / choco new as it doesn't seem like happy path to a clean package with best practices from the default choco new command.

After the package is ready for build, a choco linter/scanner and set of Pester tests could be used to verify the template was changed properly and meets good practice for publishing?

asears avatar Aug 13 '20 10:08 asears

Perhaps the option to generate more detailed scaffolding could be non-default new option?

The problem with this is the folks that would need this wouldn't know to do this. However if there is a feature switch, folks could simply switch it off and then they would get choco new templates without all the comments.

ferventcoder avatar Sep 01 '20 22:09 ferventcoder