Skip to content

Commit 960c66a

Browse files
committed
feat(build): ✨ Introduce build.ps1 for streamlined packaging and installation
* Replaced `package-and-install.ps1` and `package-and-install.bat` with a unified `build.ps1` script. * Added support for bootstrapping dependencies and running various tasks (e.g., `Test`, `Install`, `Package`). * Updated `README.md` and `PACKAGING.md` to reflect new build process. * Enhanced `package.json` scripts for improved task execution. * Added `psake.ps1` for build task management and CI integration. * Introduced `requirements.psd1` for dependency management. * Added tests for `package.json` validation.
1 parent 1967291 commit 960c66a

10 files changed

Lines changed: 321 additions & 238 deletions

PACKAGING.md

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,51 @@
33
This document explains how to package and install the PowerShell Localization
44
extension for development and testing purposes.
55

6+
> [!NOTE]
7+
> Tasks are split between psake and yarn. This is due to the fact that
8+
> psake can setup more robust dependencies. Several tasks can only be called via
9+
> Node so those calls stay in the package.json
10+
611
## Quick Start
712

8-
### Option 1: PowerShell Script (Recommended)
13+
### Bootstrap
14+
15+
To install all the necessary dependencies ensure that you bootstrap your
16+
environment.
917

1018
```powershell
11-
.\package-and-install.ps1
19+
.\build.ps1 -Bootstrap
1220
```
1321

14-
### Option 2: Batch File (Windows)
22+
### Option 1: PowerShell Build Script (Recommended)
1523

16-
```cmd
17-
package-and-install.bat
24+
```powershell
25+
# To run through the compile, lint, and test
26+
.\build.ps1 -Task Test
27+
# To run all the tests + Install
28+
.\build.ps1 -Task Install
29+
# To see all the possible tasks
30+
.\build.ps1 -Help
1831
```
1932

20-
### Option 3: NPM Scripts
33+
This will configure the environment and perform a clean build, compile, lint,
34+
package, and install the extension.
2135

22-
```bash
23-
# Package and install
24-
yarn package-install
36+
#### To install
2537

26-
# Package only (skip installation)
27-
yarn package-only
38+
### Option 2: NPM Scripts
2839

29-
# Package using vsce directly
40+
```bash
41+
# Package (calls psake)
3042
yarn package
43+
44+
# Get a list of packages
45+
yarn run
3146
```
3247

3348
## Script Features
3449

35-
The `package-and-install.ps1` script provides the following functionality:
50+
The `build.ps1` script provides the following functionality (via `psake.ps1`):
3651

3752
-**Dependency Check**: Automatically installs `vsce` if not present
3853
- 🧹 **Clean Build**: Removes previous builds and packages
@@ -43,18 +58,23 @@ The `package-and-install.ps1` script provides the following functionality:
4358

4459
## Script Parameters
4560

61+
See
62+
[Parameters & Properties](https://psake.dev/docs/tutorial-basics/parameters-properties)
63+
for a more detailed explanation. It is highly unlikely you'll need to modify any
64+
of the properties.
65+
4666
```powershell
47-
# Package and install (default)
48-
.\package-and-install.ps1
67+
# Test (default)
68+
.\build.ps1
4969
50-
# Package only, skip installation
51-
.\package-and-install.ps1 -SkipInstall
70+
# Package only to a different output directory
71+
.\build.ps1 -Task Package -Parameters @{ OutDir = '/path/to/dir' }
5272
5373
# Force installation even if already installed
54-
.\package-and-install.ps1 -Force
74+
.\build.ps1 -Parameters @{ Force = $true }
5575
5676
# Combine parameters
57-
.\package-and-install.ps1 -SkipInstall -Force
77+
.\build.ps1 -Parameters @{ SkipInstall = $true; Force = $true }
5878
```
5979

6080
## Manual Steps
@@ -82,12 +102,12 @@ If you prefer to run the steps manually:
82102
4. **Package extension**:
83103

84104
```bash
85-
vsce package
105+
vsce package --allow-missing-repository --out $script:outDir
86106
```
87107

88108
5. **Install extension**:
89109

90-
```bash
110+
```shell
91111
code --install-extension powershelllocalization-*.vsix
92112
```
93113

@@ -116,22 +136,19 @@ After installation:
116136
1. Reload VS Code (`Ctrl+Shift+P` → "Developer: Reload Window")
117137
2. Open a PowerShell file (`.ps1`, `.psm1`, or `.psd1`)
118138
3. Check that the extension is active in the Extensions panel
139+
4. You should see logs in the Output panel.
119140

120-
### Clean Installation
141+
### Continuous Integration
121142

122-
To completely clean and reinstall:
143+
For GitHub Actions or other CI systems, use the `CI` task to output build/package information:
123144

124145
```powershell
125-
# Remove old packages
126-
Remove-Item *.vsix -Force
127-
128-
# Clean compiled output
129-
Remove-Item -Recurse out -Force
130-
131-
# Run full package and install
132-
.\package-and-install.ps1 -Force
146+
.\build.ps1 -Task CI
133147
```
134148

149+
This will output the VSIX path, name, and Changelog information to
150+
`$env:GITHUB_OUTPUT` for use in workflows.
151+
135152
## Development Workflow
136153

137154
For active development, you can use the watch mode:

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ A Visual Studio Code extension that displays PowerShell localization variable
44
values as decorations in your editor, making it easier to develop and debug
55
internationalized PowerShell modules.
66

7-
![Example showing the inline decorator](static/image.png)
7+
<!-- Full image URL with https required for vscode -->
8+
![Example showing the inline decorator](https://github.com/PSInclusive/PowerShellLocalization/raw/main/static/image.png)
89

910
## Features
1011

@@ -53,15 +54,15 @@ This extension contributes the following settings:
5354

5455
To build and install this extension:
5556

56-
```bash
57-
# Using PowerShell script
58-
.\package-and-install.ps1
59-
60-
# Using npm scripts
61-
yarn package-install
62-
63-
# Package only
64-
yarn package-only
57+
```pwsh
58+
# Using pwsh (all OS's)
59+
./build.ps1 -Task Test
60+
# Use the -Bootstrap flag to install all the dependancies.
61+
./build.ps1 -Task Test -Bootstrap
62+
# You can also list all the available tasks with -Help
63+
./build.ps1 -Help
64+
# To install a local build
65+
./build.ps1 -Task Install
6566
```
6667

6768
## Usage

build.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[CmdletBinding(DefaultParameterSetName = 'Task')]
2+
param(
3+
# Build task(s) to execute
4+
[parameter(ParameterSetName = 'task', position = 0)]
5+
[string[]]$Task = 'default',
6+
7+
# Bootstrap dependencies
8+
[switch]$Bootstrap,
9+
10+
# List available build tasks
11+
[parameter(ParameterSetName = 'Help')]
12+
[switch]$Help,
13+
14+
# Optional properties to pass to psake
15+
[hashtable]$Properties,
16+
17+
# Optional parameters to pass to psake
18+
[hashtable]$Parameters
19+
)
20+
21+
$ErrorActionPreference = 'Stop'
22+
23+
# Bootstrap dependencies
24+
if ($Bootstrap.IsPresent) {
25+
Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null
26+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
27+
if ((Test-Path -Path ./requirements.psd1)) {
28+
if (-not (Get-Module -Name PSDepend -ListAvailable)) {
29+
Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force
30+
}
31+
Import-Module -Name PSDepend -Verbose:$false
32+
Invoke-PSDepend -Path './requirements.psd1' -Install -Import -Force -WarningAction SilentlyContinue
33+
} else {
34+
Write-Warning 'No [requirements.psd1] found. Skipping build dependency installation.'
35+
}
36+
} else {
37+
Invoke-PSDepend -Path './requirements.psd1' -Import -Force -WarningAction SilentlyContinue
38+
}
39+
40+
# Execute psake task(s)
41+
$psakeFile = './psake.ps1'
42+
if ($PSCmdlet.ParameterSetName -eq 'Help') {
43+
Get-PSakeScriptTasks -BuildFile $psakeFile |
44+
Format-Table -Property Name, Description, Alias, DependsOn
45+
} else {
46+
Invoke-psake -buildFile $psakeFile -taskList $Task -nologo -properties $Properties -parameters $Parameters
47+
exit ([int](-not $psake.build_success))
48+
}

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"powershell"
77
],
88
"words": [
9+
"psake",
910
"psinclusive",
1011
"powershelllocalization"
1112
],

package-and-install.bat

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)