-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_npm_packages.ps1
111 lines (92 loc) · 3.57 KB
/
build_npm_packages.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
[cmdletbinding()]
param(
[switch]$publish,
[switch]$skipBuild,
[switch]$publishLatestTag,
[string]$version = $null
)
$nodejs_dir = "pkg_njs"
$bundle_dir = "pkg_bundle"
$web_dir = "pkg_web"
$latest_dir = "pkg_latest"
if($skipBuild -ne $true) {
if(Test-Path $nodejs_dir) {
Remove-Item $nodejs_dir/ -Recurse -Force -ErrorAction Stop
}
if(Test-Path $bundle_dir) {
Remove-Item $bundle_dir/ -Recurse -Force -ErrorAction Stop
}
if(Test-Path $web_dir) {
Remove-Item $web_dir/ -Recurse -Force -ErrorAction Stop
}
if(Test-Path $latest_dir) {
Remove-Item $latest_dir/ -Recurse -Force -ErrorAction Stop
}
# Build for NodeJS
wasm-pack build --all-features --release --target nodejs --out-dir $nodejs_dir/pkg
$j = Get-Content $nodejs_dir/pkg/package.json |convertfrom-json
if($null -ne $version -and $version.Length -gt 1) {
$j.version = $version + "-nodejs"
} else {
$j.version = $j.version + "-nodejs"
}
$j | convertto-json | out-file .\$nodejs_dir/pkg/package.json
$njsv = $j.version
#wasm-pack pack $nodejs_dir
# Build for Web
wasm-pack build --all-features --release --target web --out-dir $web_dir/pkg
$j = Get-Content $web_dir/pkg/package.json |convertfrom-json
if($null -ne $version -and $version.Length -gt 0) {
$j.version = $version + "-web"
} else {
$j.version = $j.version + "-web"
}
$j | convertto-json | out-file .\$web_dir/pkg/package.json
$webv = $j.version
$file = ".\$web_dir\pkg\marlowe_lang.js"
$offendingline = "new URL\('marlowe_lang_bg.wasm', import.meta.url\)"
$fixedline = "'marlowe_lang_bg.wasm'"
$newContent = (Get-Content $file) -replace $offendingline , $fixedline
Set-Content -Value $newContent -Path $file
#wasm-pack pack $web_dir
# Build bundle
wasm-pack build --all-features --release --target bundler --out-dir $bundle_dir/pkg
$j = Get-Content $bundle_dir/pkg/package.json |convertfrom-json
if($null -ne $version -and $version.Length -gt 0) {
$j.version = $version + "-bundle"
} else {
$j.version = $j.version + "-bundle"
}
$j | convertto-json | out-file .\$bundle_dir/pkg/package.json
$bundlev = $j.version
#wasm-pack pack $bundle_dir
# Build latest
wasm-pack build --all-features --release --target nodejs --out-dir $latest_dir/pkg
$j = Get-Content $latest_dir/pkg/package.json |convertfrom-json
if($null -ne $version -and $version.Length -gt 0) {
$j.version = $version
} else {
$j.version = $j.version
}
$j | convertto-json | out-file .\$latest_dir/pkg/package.json
$latestlev = $j.version
#wasm-pack pack $bundle_dir
Write-Host -ForegroundColor Green "---> $njsv"
Write-Host -ForegroundColor Green "---> $webv"
Write-Host -ForegroundColor Green "---> $bundlev"
Write-Host -ForegroundColor Green "---> $latestlev"
} else {
Write-Warning "Build skipped"
}
if($publish) {
write-host -ForegroundColor Green "Publishing web... $web_dir $webv"
wasm-pack publish -t web --tag web $web_dir
write-host -ForegroundColor Green "Publishing nodejs... $nodejs_dir $njsv"
wasm-pack publish -t nodejs --tag nodejs $nodejs_dir
write-host -ForegroundColor Green "Publishing bundle... $bundle_dir $bundlev"
wasm-pack publish -t bundler --tag bundle $bundle_dir
if($publishLatestTag) {
write-host -ForegroundColor Green "Publishing latest... $latest_dir $latestlev"
wasm-pack publish -t nodejs --tag latest $latest_dir
}
}