-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-package.ps1
More file actions
302 lines (258 loc) · 9.19 KB
/
build-package.ps1
File metadata and controls
302 lines (258 loc) · 9.19 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# ============================================
# DASE - Build Package Script
# Generates a VSIX package locally
# ============================================
param(
[string]$Version = "",
[switch]$SkipTests,
[switch]$SkipTFX,
[switch]$Help
)
$ErrorActionPreference = "Stop"
# Colors
function Write-Info { Write-Host $args -ForegroundColor Cyan }
function Write-Success { Write-Host $args -ForegroundColor Green }
function Write-Warn { Write-Host $args -ForegroundColor Yellow }
function Write-Err { Write-Host $args -ForegroundColor Red }
# Help
if ($Help) {
Write-Host @"
DASE Build Package Script
=========================
Usage: .\build-package.ps1 [options]
Options:
-Version <string> Version for the package (default: from package.json + timestamp)
-SkipTests Skip running tests
-SkipTFX Skip rebuilding TFX (use existing dist/)
-Help Show this help message
Examples:
.\build-package.ps1 # Build with auto-generated version
.\build-package.ps1 -Version 1.2.3 # Build with specific version
.\build-package.ps1 -SkipTests # Build without running tests
.\build-package.ps1 -SkipTFX -SkipTests # Quick rebuild (DASE only, no tests)
Output:
DASE/dase-<version>.vsix
"@
exit 0
}
# Header
Write-Host ""
Write-Host "============================================" -ForegroundColor Magenta
Write-Host " DASE - Build Package" -ForegroundColor Magenta
Write-Host "============================================" -ForegroundColor Magenta
Write-Host ""
$RootDir = $PSScriptRoot
$TfxDir = Join-Path $RootDir "TFX"
$DaseDir = Join-Path $RootDir "DASE"
# Check directories
if (-not (Test-Path $TfxDir)) {
Write-Err "TFX directory not found: $TfxDir"
exit 1
}
if (-not (Test-Path $DaseDir)) {
Write-Err "DASE directory not found: $DaseDir"
exit 1
}
# ============================================
# Step 1: Build TFX
# ============================================
if (-not $SkipTFX) {
Write-Info "[1/5] Building TFX..."
Push-Location $TfxDir
try {
Write-Host " Installing dependencies..."
npm ci --silent 2>$null
if ($LASTEXITCODE -ne 0) {
npm install --silent
}
Write-Host " Compiling TypeScript..."
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Err "TFX build failed!"
exit 1
}
Write-Success " TFX built successfully"
}
finally {
Pop-Location
}
} else {
Write-Warn "[1/5] Skipping TFX build (--SkipTFX)"
}
# ============================================
# Step 2: Test TFX
# ============================================
if (-not $SkipTests -and -not $SkipTFX) {
Write-Info "[2/5] Testing TFX..."
Push-Location $TfxDir
try {
npm run test
if ($LASTEXITCODE -ne 0) {
Write-Err "TFX tests failed!"
exit 1
}
Write-Success " TFX tests passed"
}
finally {
Pop-Location
}
} else {
Write-Warn "[2/5] Skipping TFX tests"
}
# ============================================
# Step 3: Build DASE
# ============================================
Write-Info "[3/5] Building DASE..."
Push-Location $DaseDir
try {
Write-Host " Installing dependencies..."
npm ci --silent 2>$null
if ($LASTEXITCODE -ne 0) {
npm install --silent
}
# Copy TFX to node_modules (required for VSIX packaging)
# npm creates symlinks for file: dependencies which vsce doesn't follow
Write-Host " Copying TFX to node_modules (replacing symlink)..."
$TfxTarget = Join-Path $DaseDir "node_modules\@tootega\tfx"
# Remove symlink/junction (special handling for Windows junctions)
if (Test-Path $TfxTarget) {
$item = Get-Item $TfxTarget -Force
if ($item.LinkType) {
# It's a symlink/junction - use cmd to remove it
cmd /c "rmdir `"$TfxTarget`"" 2>$null
} else {
Remove-Item $TfxTarget -Recurse -Force
}
}
# Create directory and copy files (maintain dist/ structure as package.json expects)
New-Item -ItemType Directory -Path $TfxTarget -Force | Out-Null
$TfxDistTarget = Join-Path $TfxTarget "dist"
New-Item -ItemType Directory -Path $TfxDistTarget -Force | Out-Null
Copy-Item (Join-Path $TfxDir "dist\*") $TfxDistTarget -Recurse -Force
Copy-Item (Join-Path $TfxDir "package.json") $TfxTarget -Force
# Verify copy
$tfxIndex = Join-Path $TfxDistTarget "index.js"
if (-not (Test-Path $tfxIndex)) {
Write-Err "TFX copy failed - dist/index.js not found!"
exit 1
}
Write-Host " TFX copied successfully to node_modules"
# Update package.json to use actual TFX version (not file: reference)
# This prevents npm from flagging it as "invalid" during vsce packaging
$PackageJsonPath = Join-Path $DaseDir "package.json"
$PackageJson = Get-Content $PackageJsonPath -Raw | ConvertFrom-Json
$TfxPackageJson = Get-Content (Join-Path $TfxTarget "package.json") -Raw | ConvertFrom-Json
$TfxVersion = $TfxPackageJson.version
$PackageJson.dependencies.'@tootega/tfx' = $TfxVersion
$PackageJson | ConvertTo-Json -Depth 10 | Set-Content $PackageJsonPath -Encoding UTF8
Write-Host " Updated @tootega/tfx dependency to version $TfxVersion"
# Determine version
if ([string]::IsNullOrEmpty($Version)) {
$PackageJson = Get-Content "package.json" | ConvertFrom-Json
$BaseVersion = $PackageJson.version
# Use timestamp as build number for local builds
$Timestamp = [DateTimeOffset]::Now.ToUnixTimeSeconds()
$BuildNumber = $Timestamp % 100000
$VersionParts = $BaseVersion -split '\.'
$Version = "$($VersionParts[0]).$($VersionParts[1]).$BuildNumber"
}
Write-Host " Version: $Version"
# Update package.json version
npm version $Version --no-git-tag-version --allow-same-version 2>$null
Write-Host " Compiling TypeScript..."
npm run compile
if ($LASTEXITCODE -ne 0) {
Write-Err "DASE build failed!"
exit 1
}
Write-Success " DASE built successfully"
}
finally {
Pop-Location
}
# ============================================
# Step 4: Test DASE
# ============================================
if (-not $SkipTests) {
Write-Info "[4/5] Testing DASE..."
Push-Location $DaseDir
try {
npm test
if ($LASTEXITCODE -ne 0) {
Write-Err "DASE tests failed!"
exit 1
}
Write-Success " DASE tests passed"
}
finally {
Pop-Location
}
} else {
Write-Warn "[4/5] Skipping DASE tests"
}
# ============================================
# Step 5: Package VSIX
# ============================================
Write-Info "[5/5] Packaging VSIX..."
Push-Location $DaseDir
try {
# Check if vsce is installed
$VsceInstalled = Get-Command vsce -ErrorAction SilentlyContinue
if (-not $VsceInstalled) {
Write-Host " Installing vsce..."
npm install -g @vscode/vsce
}
# Remove old VSIX files
Get-ChildItem "dase-*.vsix" -ErrorAction SilentlyContinue | Remove-Item -Force
# Verify TFX is in node_modules before packaging
$tfxCheck = Join-Path $DaseDir "node_modules\@tootega\tfx\dist\index.js"
if (-not (Test-Path $tfxCheck)) {
Write-Err "TFX not found in node_modules - cannot package!"
exit 1
}
# Package (include dependencies)
$VsixFile = "dase-$Version.vsix"
$PackagingFailed = $false
try {
vsce package --out $VsixFile --allow-missing-repository --allow-star-activation
if ($LASTEXITCODE -ne 0) {
$PackagingFailed = $true
}
}
finally {
# Restore original file: reference in package.json (always, even on failure)
$PackageJsonPath = Join-Path $DaseDir "package.json"
$PackageJson = Get-Content $PackageJsonPath -Raw | ConvertFrom-Json
$PackageJson.dependencies.'@tootega/tfx' = "file:../TFX"
$PackageJson | ConvertTo-Json -Depth 10 | Set-Content $PackageJsonPath -Encoding UTF8
Write-Host " Restored @tootega/tfx dependency to file:../TFX"
}
if ($PackagingFailed) {
Write-Err "Packaging failed!"
exit 1
}
$VsixPath = Join-Path $DaseDir $VsixFile
$VsixSize = [math]::Round((Get-Item $VsixPath).Length / 1KB, 2)
Write-Success " Package created: $VsixFile ($VsixSize KB)"
}
finally {
Pop-Location
}
# ============================================
# Summary
# ============================================
Write-Host ""
Write-Host "============================================" -ForegroundColor Green
Write-Host " Build Complete!" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Green
Write-Host ""
Write-Host " Version: $Version" -ForegroundColor White
Write-Host " Package: DASE\$VsixFile" -ForegroundColor White
Write-Host " Size: $VsixSize KB" -ForegroundColor White
Write-Host ""
Write-Host "To install:" -ForegroundColor Cyan
Write-Host " 1. Open VS Code"
Write-Host " 2. Press Ctrl+Shift+P"
Write-Host " 3. Type 'Extensions: Install from VSIX...'"
Write-Host " 4. Select: DASE\$VsixFile"
Write-Host ""