-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-msix.ps1
More file actions
204 lines (178 loc) · 7.6 KB
/
build-msix.ps1
File metadata and controls
204 lines (178 loc) · 7.6 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
# Build MSIX Package Script for EasyDist
# This script builds the MSIX package using Windows SDK tools
# to avoid compatibility issues with electron-builder's bundled tools
param(
[switch]$SkipBuild
)
$ErrorActionPreference = "Stop"
# Configuration
$WinSDKPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64"
$ProjectPath = $PSScriptRoot
$DistPath = Join-Path $ProjectPath "dist"
$AppxPath = Join-Path $DistPath "__appx-x64"
$AppxContentPath = Join-Path $AppxPath "appx"
$WinUnpackedPath = Join-Path $DistPath "win-unpacked"
Write-Host "=== EasyDist MSIX Builder ===" -ForegroundColor Cyan
# Step 1: Build Next.js and electron app
if (-not $SkipBuild) {
Write-Host "`n[1/6] Building Next.js...`n" -ForegroundColor Yellow
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Error "Next.js build failed"
exit 1
}
Write-Host "`n[2/6] Packaging Electron app (NSIS only)...`n" -ForegroundColor Yellow
# Build NSIS only - this creates win-unpacked folder without APPX issues
npx electron-builder --win nsis
if ($LASTEXITCODE -ne 0) {
Write-Error "Electron packaging failed"
exit 1
}
}
# Step 2: Create APPX directory structure
Write-Host "`n[3/6] Creating APPX structure..." -ForegroundColor Yellow
# Clean and recreate appx directories
if (Test-Path $AppxPath) {
Remove-Item $AppxPath -Recurse -Force
}
New-Item -ItemType Directory -Path $AppxPath -Force | Out-Null
New-Item -ItemType Directory -Path $AppxContentPath -Force | Out-Null
New-Item -ItemType Directory -Path (Join-Path $AppxContentPath "app") -Force | Out-Null
New-Item -ItemType Directory -Path (Join-Path $AppxContentPath "assets") -Force | Out-Null
# Copy app files
Write-Host "Copying application files..."
Copy-Item (Join-Path $WinUnpackedPath "*") (Join-Path $AppxContentPath "app") -Recurse -Force
# Step 3: Copy assets from existing icons
Write-Host "Copying assets..."
$AssetsSource = Join-Path $ProjectPath "build\appx"
$AssetsDest = Join-Path $AppxContentPath "assets"
if (Test-Path $AssetsSource) {
Copy-Item (Join-Path $AssetsSource "*") $AssetsDest -Recurse -Force
}
else {
# Create placeholder assets from icon.png
$iconPath = Join-Path $ProjectPath "icon.png"
if (Test-Path $iconPath) {
Copy-Item $iconPath (Join-Path $AssetsDest "StoreLogo.png") -Force
Copy-Item $iconPath (Join-Path $AssetsDest "Square44x44Logo.png") -Force
Copy-Item $iconPath (Join-Path $AssetsDest "Square150x150Logo.png") -Force
Copy-Item $iconPath (Join-Path $AssetsDest "Wide310x150Logo.png") -Force
}
}
# Step 4: Create AppxManifest.xml
Write-Host "`n[4/6] Creating AppxManifest.xml..." -ForegroundColor Yellow
$Version = (Get-Content (Join-Path $ProjectPath "package.json") | ConvertFrom-Json).version
$AppVersion = "$Version.0"
$ManifestContent = @"
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities">
<Identity Name="Saayan.EasyDist"
ProcessorArchitecture="x64"
Publisher="CN=37E2AF47-D2FC-489C-BDC1-02C989A7B989"
Version="$AppVersion" />
<Properties>
<DisplayName>EasyDist</DisplayName>
<PublisherDisplayName>Saayan</PublisherDisplayName>
<Description>EasyDist - Distribution Helper Tool</Description>
<Logo>assets\StoreLogo.png</Logo>
</Properties>
<Resources>
<Resource Language="en-US" />
</Resources>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22621.0" />
</Dependencies>
<Capabilities>
<rescap:Capability Name="runFullTrust"/>
</Capabilities>
<Applications>
<Application Id="EasyDist" Executable="app\EasyDist.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements
BackgroundColor="#1f1f23"
DisplayName="EasyDist"
Square150x150Logo="assets\Square150x150Logo.png"
Square44x44Logo="assets\Square44x44Logo.png"
Description="EasyDist - Distribution Helper Tool">
<uap:DefaultTile Wide310x150Logo="assets\Wide310x150Logo.png">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="wide310x150Logo" />
<uap:ShowOn Tile="square150x150Logo" />
</uap:ShowNameOnTiles>
</uap:DefaultTile>
</uap:VisualElements>
</Application>
</Applications>
</Package>
"@
$ManifestPath = Join-Path $AppxContentPath "AppxManifest.xml"
$ManifestContent | Out-File -FilePath $ManifestPath -Encoding utf8
# Step 5: Generate resources.pri using Windows SDK makepri.exe
Write-Host "`n[5/6] Generating resources.pri with Windows SDK..." -ForegroundColor Yellow
$MakePriPath = Join-Path $WinSDKPath "makepri.exe"
if (-not (Test-Path $MakePriPath)) {
Write-Error "makepri.exe not found at $MakePriPath. Please install Windows SDK or update the path."
exit 1
}
# Create priconfig.xml
$PriConfigPath = Join-Path $AppxPath "priconfig.xml"
$PriConfigContent = @"
<?xml version="1.0" encoding="UTF-8"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
<packaging>
<autoResourcePackage qualifier="Language"/>
<autoResourcePackage qualifier="Scale"/>
<autoResourcePackage qualifier="DXFeatureLevel"/>
</packaging>
<index root="\" startIndexAt="\">
<default>
<qualifier name="Language" value="en-US"/>
<qualifier name="Contrast" value="standard"/>
<qualifier name="Scale" value="100"/>
<qualifier name="HomeRegion" value="001"/>
<qualifier name="TargetSize" value="256"/>
<qualifier name="LayoutDirection" value="LTR"/>
<qualifier name="Theme" value="dark"/>
<qualifier name="AlternateForm" value=""/>
<qualifier name="DXFeatureLevel" value="DX9"/>
<qualifier name="Configuration" value=""/>
<qualifier name="DeviceFamily" value="Desktop"/>
<qualifier name="Custom" value=""/>
</default>
<indexer-config type="folder" foldernameAsQualifier="true" filenameAsQualifier="true" qualifierDelimiter="."/>
<indexer-config type="resw" convertDotsToSlashes="true" initialPath=""/>
<indexer-config type="resjson" initialPath=""/>
<indexer-config type="PRI"/>
</index>
</resources>
"@
$PriConfigContent | Out-File -FilePath $PriConfigPath -Encoding utf8
$ResourcesPriOutput = Join-Path $AppxContentPath "resources.pri"
& $MakePriPath new /Overwrite /Manifest $ManifestPath /ProjectRoot $AppxContentPath /ConfigXml $PriConfigPath /OutputFile $ResourcesPriOutput /IndexName "EasyDist"
if ($LASTEXITCODE -ne 0) {
Write-Warning "makepri.exe returned non-zero exit code, but continuing..."
}
# Step 6: Create MSIX package
Write-Host "`n[6/6] Creating MSIX package..." -ForegroundColor Yellow
$MakeAppxPath = Join-Path $WinSDKPath "makeappx.exe"
$MsixOutput = Join-Path $DistPath "EasyDist $Version.msix"
if (-not (Test-Path $MakeAppxPath)) {
Write-Error "makeappx.exe not found at $MakeAppxPath. Please install Windows SDK or update the path."
exit 1
}
# Remove old msix if exists
if (Test-Path $MsixOutput) {
Remove-Item $MsixOutput -Force
}
& $MakeAppxPath pack /d $AppxContentPath /p $MsixOutput /o /nv
if ($LASTEXITCODE -ne 0) {
Write-Error "makeappx.exe failed"
exit 1
}
Write-Host "`n=== Build Complete! ===" -ForegroundColor Green
Write-Host "MSIX Package: $MsixOutput" -ForegroundColor Cyan
Write-Host "`nNote: The MSIX is not signed. For Microsoft Store submission," -ForegroundColor Yellow
Write-Host "the Store will sign it automatically when you upload." -ForegroundColor Yellow