|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +# Build and pack motely-wasm and motely-node packages |
| 3 | +# Version is controlled by Directory.Packages.props |
| 4 | + |
| 5 | +$ErrorActionPreference = "Stop" |
| 6 | + |
| 7 | +Write-Host "=== MOTELY BUILD AND PACK ===" -ForegroundColor Cyan |
| 8 | + |
| 9 | +# Get version |
| 10 | +$propsPath = "Directory.Packages.props" |
| 11 | +if (-not (Test-Path $propsPath)) { |
| 12 | + throw "Directory.Packages.props not found" |
| 13 | +} |
| 14 | + |
| 15 | +$propsContent = Get-Content $propsPath -Raw |
| 16 | +if ($propsContent -match '<MotelyVersion>([^<]+)</MotelyVersion>') { |
| 17 | + $version = $matches[1].Trim() |
| 18 | + Write-Host "Version: $version" -ForegroundColor Green |
| 19 | +} else { |
| 20 | + throw "Could not find MotelyVersion in Directory.Packages.props" |
| 21 | +} |
| 22 | + |
| 23 | +# Phase B: motely-wasm |
| 24 | +Write-Host "`n=== Phase B: motely-wasm ===" -ForegroundColor Cyan |
| 25 | + |
| 26 | +# Clean old framework folders |
| 27 | +Write-Host "Cleaning old _framework folders..." -ForegroundColor Yellow |
| 28 | +if (Test-Path "motely-wasm\_framework") { Remove-Item "motely-wasm\_framework" -Recurse -Force } |
| 29 | +if (Test-Path "motely-wasm\_framework_st") { Remove-Item "motely-wasm\_framework_st" -Recurse -Force } |
| 30 | + |
| 31 | +# Build single-thread WASM |
| 32 | +Write-Host "Building single-thread WASM..." -ForegroundColor Yellow |
| 33 | +dotnet clean Motely.BrowserWasm/Motely.BrowserWasm.csproj -c Release |
| 34 | +dotnet publish Motely.BrowserWasm/Motely.BrowserWasm.csproj -c Release -p:SingleThread=true |
| 35 | +if ($LASTEXITCODE -ne 0) { throw "Single-thread WASM build failed" } |
| 36 | + |
| 37 | +# Stage single-thread |
| 38 | +Write-Host "Staging single-thread framework..." -ForegroundColor Yellow |
| 39 | +node stage-packages.mjs browser |
| 40 | +if ($LASTEXITCODE -ne 0) { throw "Stage single-thread failed" } |
| 41 | + |
| 42 | +# Rename to _framework_st |
| 43 | +if (Test-Path "motely-wasm\_framework") { |
| 44 | + Move-Item "motely-wasm\_framework" "motely-wasm\_framework_st" |
| 45 | +} |
| 46 | + |
| 47 | +# Build multi-thread WASM (skip if YamlDotNet atomics error) |
| 48 | +Write-Host "Building multi-thread WASM..." -ForegroundColor Yellow |
| 49 | +dotnet clean Motely.BrowserWasm/Motely.BrowserWasm.csproj -c Release |
| 50 | +$multiThreadSuccess = $true |
| 51 | +try { |
| 52 | + dotnet publish Motely.BrowserWasm/Motely.BrowserWasm.csproj -c Release |
| 53 | + if ($LASTEXITCODE -ne 0) { |
| 54 | + Write-Host "Multi-thread build failed (YamlDotNet atomics issue), using single-thread only" -ForegroundColor Yellow |
| 55 | + $multiThreadSuccess = $false |
| 56 | + } else { |
| 57 | + node stage-packages.mjs browser |
| 58 | + if ($LASTEXITCODE -ne 0) { throw "Stage multi-thread failed" } |
| 59 | + } |
| 60 | +} catch { |
| 61 | + Write-Host "Multi-thread build failed: $_" -ForegroundColor Yellow |
| 62 | + $multiThreadSuccess = $false |
| 63 | +} |
| 64 | + |
| 65 | +# If multi-thread failed, copy single-thread to _framework |
| 66 | +if (-not $multiThreadSuccess) { |
| 67 | + Write-Host "Copying single-thread to _framework (fallback)..." -ForegroundColor Yellow |
| 68 | + Copy-Item "motely-wasm\_framework_st" "motely-wasm\_framework" -Recurse |
| 69 | +} |
| 70 | + |
| 71 | +# Build motely-wasm package |
| 72 | +Write-Host "Building motely-wasm package..." -ForegroundColor Yellow |
| 73 | +Push-Location motely-wasm |
| 74 | +npm install |
| 75 | +npm run build |
| 76 | +if ($LASTEXITCODE -ne 0) { throw "motely-wasm build failed" } |
| 77 | + |
| 78 | +# Pack motely-wasm |
| 79 | +Write-Host "Packing motely-wasm..." -ForegroundColor Yellow |
| 80 | +npm pack |
| 81 | +if ($LASTEXITCODE -ne 0) { throw "motely-wasm pack failed" } |
| 82 | +Pop-Location |
| 83 | + |
| 84 | +Write-Host "✓ motely-wasm-$version.tgz ready" -ForegroundColor Green |
| 85 | + |
| 86 | +# Phase C: motely-node |
| 87 | +Write-Host "`n=== Phase C: motely-node ===" -ForegroundColor Cyan |
| 88 | + |
| 89 | +# Build linux-x64 addon |
| 90 | +Write-Host "Building linux-x64 addon via Docker..." -ForegroundColor Yellow |
| 91 | +.\build-linux.ps1 |
| 92 | +if ($LASTEXITCODE -ne 0) { throw "Linux build failed" } |
| 93 | + |
| 94 | +# Verify binary exists |
| 95 | +$nodeBinary = "motely-node\bin\linux-x64\Motely.NodeAddon.node" |
| 96 | +if (-not (Test-Path $nodeBinary)) { |
| 97 | + throw "Linux binary not found: $nodeBinary" |
| 98 | +} |
| 99 | +Write-Host "✓ Linux binary exists: $nodeBinary" -ForegroundColor Green |
| 100 | + |
| 101 | +# Copy jaml-schema files |
| 102 | +Write-Host "Copying jaml-schema files..." -ForegroundColor Yellow |
| 103 | +Copy-Item "motely-wasm\jaml-schema.js" "motely-node\" -Force |
| 104 | +Copy-Item "motely-wasm\jaml-schema.d.ts" "motely-node\" -Force |
| 105 | +Copy-Item "motely-wasm\jaml.schema.json" "motely-node\" -Force |
| 106 | + |
| 107 | +# Pack motely-node |
| 108 | +Write-Host "Packing motely-node..." -ForegroundColor Yellow |
| 109 | +Push-Location motely-node |
| 110 | +npm pack |
| 111 | +if ($LASTEXITCODE -ne 0) { throw "motely-node pack failed" } |
| 112 | +Pop-Location |
| 113 | + |
| 114 | +Write-Host "✓ motely-node-$version.tgz ready" -ForegroundColor Green |
| 115 | + |
| 116 | +# Summary |
| 117 | +Write-Host "`n=== BUILD COMPLETE ===" -ForegroundColor Cyan |
| 118 | +Write-Host "Version: $version" -ForegroundColor Green |
| 119 | +Write-Host "Packages ready:" -ForegroundColor Green |
| 120 | +Write-Host " - motely-wasm\motely-wasm-$version.tgz" -ForegroundColor White |
| 121 | +Write-Host " - motely-node\motely-node-$version.tgz" -ForegroundColor White |
| 122 | +Write-Host "`nTo publish:" -ForegroundColor Yellow |
| 123 | +Write-Host " cd motely-wasm && npm publish motely-wasm-$version.tgz --access public" -ForegroundColor White |
| 124 | +Write-Host " cd motely-node && npm publish motely-node-$version.tgz --access public" -ForegroundColor White |
| 125 | +Write-Host "`nTo update JAMMY:" -ForegroundColor Yellow |
| 126 | +Write-Host " cd x:\JAMMY && pnpm add motely-wasm@$version motely-node@$version" -ForegroundColor White |
0 commit comments