-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-npm.ps1
86 lines (78 loc) · 3.13 KB
/
build-npm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<#
.SYNOPSIS
Compiles wj-config.
.DESCRIPTION
Automates all of the necessary steps to compile and optionally publish the wj-config package:
1. Increments the package version according to what is specified.
2. Compiles the TypeScript source code and outputs it to .\out.
3. Copies the wj-config.d.ts definition file.
4. Copies the package.json file.
5. Prepares the npmjs.org readme file by joining PublishNote.md and README.md.
6. If the Publish switch is specified, performs actual publishing to the NPM public registry.
NOTE: If the Publish switch is not specified, then npm publish is run in dry-mode, just to show the potential result of publishing.
Use the Verbose switch to turn on all messages.
.PARAMETER VerUpgrade
Specify a version change. See the documentation for the command 'npm version' for detailed information.
.PARAMETER PreId
Specify the pre-release ID to use. Common examples would be 'alpha', 'beta' or 'rc'. See the documentation for the command 'npm version' for detailed information.
.PARAMETER Publish
. Useful to examine the end results. Note that 'npm publish' will be run in dry mode.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[ValidateSet("major", "minor", "patch", "premajor", "preminor", "prepatch", "prerelease")]
[string] $VerUpgrade,
[Parameter(Mandatory = $false)]
[string] $PreId,
[Parameter(Mandatory = $false)]
[switch] $Publish
)
begin {
$ErrorActionPreference = 'Stop'
[string] $path = Resolve-Path .\src\package.json
if ($VerUpgrade -ne '') {
if ($PSCmdlet.ShouldProcess($path, "Package version increment: $VerUpgrade")) {
Set-Location .\src
if ($PreId -ne '') {
npm version $VerUpgrade --preid $PreId --no-git-tag-version
}
else {
npm version $VerUpgrade --no-git-tag-version
}
Set-Location ..\
}
}
else {
Write-Verbose "Version upgrade was not specified. The package's version will not be modified."
}
$path = Resolve-Path .\
if (Test-Path .\out) {
Remove-Item -Path .\out -Recurse
}
if ($PSCmdlet.ShouldProcess($path, "TypeScript compilation")) {
npx tsc
}
Copy-Item .\src\wj-config.d.ts .\out
Copy-Item .\src\package.json .\out
Copy-Item .\PublishNote.md .\out\README.md -Force
Get-Content .\README.md | Add-Content .\out\README.md -Encoding UTF8
if (!$Publish) {
Write-Output "Running npm publish in dry run mode."
npm publish .\out\ --dry-run
}
elseif ($PSCmdlet.ShouldProcess($path, "Publish NPM package")) {
npm publish .\out\
}
elseif ($WhatIfPreference) {
Write-Verbose "NOTE: Running npm publish in dry run mode using sample data for illustration purposes only."
if (-not (Test-Path .\out)) {
New-Item -Path .\out -ItemType Directory -WhatIf:$false
}
if (-not (Test-Path .\out\test.js)) {
New-Item -Path .\out\test.js -ItemType File -WhatIf:$false
}
Copy-Item .\src\package.json .\out -WhatIf:$false
npm publish .\out\ --dry-run
}
}