pspm
所属分类:Windows编程
开发工具:PowerShell
文件大小:0KB
下载次数:0
上传日期:2023-12-26 15:25:50
上 传 者:
sh-1993
说明: PowerShell包管理器
(PowerShell Package Manager)
文件列表:
.vscode/
Class/
Tests/
functions/
LICENSE
pspm.psd1
pspm.psm1
publish.ps1
# pspm - PowerShell Package Manager
pspm is the management tools for PowerShell modules.
You can manage PowerShell modules [npm](https://www.npmjs.com/) like commands.
----
## Requirements
+ Windows PowerShell 5.1 or higher
+ PowerShell Core 6.0 or higher
+ Windows or macOS
> Testing platforms:
> Windows 11 Pro x64 22H2 with PowerShell 5.1 & PowerShell 7.3.1
> macOS Monterey 12.6 with PowerShell 7.3.1
----
## Installation
You can install pspm from [PowerShell Gallery](https://www.powershellgallery.com/packages/pspm/).
```Powershell
Install-Module -Name pspm
```
#### Option: Update PowerShellGet
We strongly recommend using the latest PowerShellGet module to improve compatibility and stability.
To update PowerShellGet use the following command and restart PowerShell.
```PowerShell
Install-Module PowerShellGet -Force -AllowClobber
```
----
## Usage
### Install & Import Modules
The command `pspm install` will download a module from [PSGallery](https://www.powershellgallery.com/).
```PowerShell
pspm install '
'
```
This will create the `Modules` folder in the current directory and will download the module to that folder, then import it to the current PS session.
#### Tips: Specify the Module version
If you want to install specific version of the Module.
You can specify the Module name with version or [semver](https://docs.npmjs.com/misc/semver#ranges) range syntax.
```PowerShell
pspm install '@' # e.g) pspm install 'Pester@4.1.0'
```
#### Tips: Specify the repository
If you want to install the module from specific repository (like Private repository)
You can specify the PSRepository name.
(You should register repositories before. See [Microsoft docs](https://docs.microsoft.com/en-us/powershell/module/powershellget/register-psrepository?view=powershell-7))
```PowerShell
pspm install '@/' # e.g) pspm install '@PrivateRepo/MyModule'
```
#### Tips: Get modules from GitHub :octocat:
You can download modules from GitHub repos.
Just `/` or `/#[`, or `/#][::path/to/subdir`.
`][` as `branch` or `commit-hash` or `Tag`
```PowerShell
pspm install '/'
pspm install '/#]['
pspm install '/#][::path/to/subdir'
# e.g) pspm install 'pester/Pester#7aa9e63'
```
You can specify `Credential` or `GitHubToken` If you want to get modules from **private** repos.
Also, if an environment variable `GITHUB_TOKEN` is present, pspm uses it as GitHub Personal Access Token.
(Priority: `Credential` > `GitHubToken` > `GITHUB_TOKEN`)
```PowerShell
# Authenticate with Credential (username & password)
pspm install '/' -Credential (Get-Credential)
# Authenticate with Personal Access Token
# You should convert token to [SecureString]
$SecureToken = ConvertTo-SecureString '' -AsPlainText -Force
pspm install '/' -GitHubToken $SecureToken
```
#### Tips: Install multiple Modules at once
If you want to install multiple modules at once or manage modules as code.
You can create `package.json` and run the `pspm install` without module name.
If there is a `package.json` file in the working directory, pspm installs all modules in the list.
About `package.json`, please refer [the section](#packagejson) below.
#### Option: Global installation
Install a module as global.
Module will save to the `$env:ProgramFiles\WindowsPowerShell\Modules` (on Windows)
```PowerShell
pspm install '' -Global
pspm install '' -g
pspm install '' -Scope Global
```
#### Option: User installation
Install a module to current user profile.
Module will save to the `$env:UserProfile\WindowsPowerShell\Modules` (on Windows)
```PowerShell
pspm install '' -Scope CurrentUser
```
#### Option: Clean installation
When `-Clean` switch specified, pspm will remove **ALL modules** in the `Modules` folder before install process.
```PowerShell
pspm install '' -Clean
# WARNING: -Clean option will remove all modules in the Modules folder, NOT just the specified.
```
#### Option: Disable modules import
`pspm install` will import modules automatically after install.
If you don't like this behavior, Specify `-NoImport` switch.
```PowerShell
pspm install '' -NoImport
```
----
### Update Modules
The command `pspm update` will update modules.
```PowerShell
pspm update '' # specify the name of module
pspm update # with package.json
```
**NOTICE:** The `pspm update` will change `package.json` to save the new version as the minimum required dependency. If you don't wanna update, use `pspm update -Save:$false`
#### Tips: What's the difference between install and update ?
Thought as below scenarios.
+ The module `Example@1.0.0` is installed in the system.
+ Latest version of `Example` is `1.2.0`.
In this scenario. If you run the command `pspm install 'Example@1.x'`, pspm will NOT update the module that because `1.0.0` is satisfied `1.x`.
But if you run `pspm update 'Example@1.x'`, pspm will update the `Example` to `1.2.0`.
----
### Uninstall Modules
To remove a module from your `Modules` folder, use:
```PowerShell
pspm uninstall ''
```
----
### Run scripts
pspm supports the `"scripts"` property of the `package.json`.
```PowerShell
pspm run '
]