PowerShell / PowerShell/PowerShell
Enhance standalone script installation
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Issue
I have a script which I would like to be able to directly install using the Install-Script from a (PowerShell Gallery) repository. The way it was setup is to download the script and dot-source the script.
As recommended by @mklement0, I should actually create *.ps1 file instead of embedded script.
My current script looks like:
<#PSScriptInfo
.VERSION 3.3.6
.GUID 5f167621-6abe-4153-a26c-f643e1716720
.AUTHOR Ronald Bode (iRon)
.DESCRIPTION Stringifys an object to a PowerShell expression (PSON, PowerShell Object Notation).
.COMPANYNAME
.COPYRIGHT
.TAGS PSON PowerShell Object Notation Expression Serialize Stringify
.LICENSE https://github.com/iRon7/ConvertTo-Expression/LICENSE.txt
.PROJECTURI https://github.com/iRon7/ConvertTo-Expression
.ICON https://raw.githubusercontent.com/iRon7/ConvertTo-Expression/master/ConvertTo-Expression.png
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
function ConvertTo-Expression {
[CmdletBinding()][OutputType([scriptblock])] param()
begin {}
process {}
}; Set-Alias ctex ConvertTo-Expression
If I change the current script to just a *.ps1 script (preserving the metadata and only the inner script body), I will lose the alias (Set-Alias ctex ConvertTo-Expression).
Also noted by @mklement0: another problem with using *.ps1 files directly as commands is that on case-sensitive file-systems - notably on Linux by default - you'll only be able to invoke the script if you match the file name's case exactly - which is both inconvenient and unexpected.
And I noticed that I do not see information like Version in the Get-Command ConvertTo-Expression (although it is shown in the Get-InstalledScript ConvertTo-Expression)
Summary of the new feature/enhancement
- Automatically build a manifest from the script's metadata required for publishing
- Add
aliasesinformation tonew-scriptfileinfo/new-scriptfileinfocmdlets - Possibly let the
Install-Scriptcmdlet automatically transform a script into a simplified module using its metadata of the script
I see no reason why the the manual steps provided in How to Write a PowerShell Script Module couldn't be automated (all mandatory steps are straight forward and optional configuration data is already available in the metadata)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Install-Script and New-ScriptFileInfo/Update-ScriptFileInfo cmdlets described in the issue, then read the linked script-module documentation. Done should be defined before coding: the proposal includes generating publishable manifest metadata, preserving aliases, and possibly transforming installed scripts into simplified modules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100