Skip to content

Commit 45c891b

Browse files
committed
fix(note): ship frontend assets with CLI installers
1 parent e093a7d commit 45c891b

2 files changed

Lines changed: 118 additions & 9 deletions

File tree

vix-site/public/install.ps1

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ Usage:
3737
install.ps1
3838
3939
Environment:
40-
VIX_VERSION Release version. Example: v2.7.0. Default: latest
41-
VIX_REPO GitHub repo. Default: vixcpp/vix
42-
VIX_INSTALL_DIR CLI bin dir. Default: %LOCALAPPDATA%\Vix\bin
40+
VIX_VERSION Release version. Example: v2.7.0. Default: latest
41+
VIX_REPO GitHub repo. Default: vixcpp/vix
42+
VIX_INSTALL_DIR CLI bin dir. Default: %LOCALAPPDATA%\Vix\bin
43+
VIX_INSTALL_SHARE_DIR Runtime assets dir. Default: %LOCALAPPDATA%\Vix\share
4344
4445
After install:
4546
vix upgrade
@@ -91,6 +92,13 @@ $BinDir = if ($env:VIX_INSTALL_DIR) {
9192
Join-Path $env:LOCALAPPDATA "Vix\bin"
9293
}
9394

95+
$ShareDir = if ($env:VIX_INSTALL_SHARE_DIR) {
96+
$env:VIX_INSTALL_SHARE_DIR
97+
} else {
98+
$installRoot = Split-Path -Parent $BinDir
99+
Join-Path $installRoot "share"
100+
}
101+
94102
$BinName = "vix.exe"
95103

96104
function Resolve-LatestTag([string]$repo) {
@@ -304,12 +312,20 @@ function Install-Cli([string]$archivePath, [string]$tmpDir) {
304312

305313
New-Item -ItemType Directory -Force -Path $extractDir | Out-Null
306314
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
315+
New-Item -ItemType Directory -Force -Path $ShareDir | Out-Null
307316

308317
Step "Installing to $BinDir\$BinName"
309318

310-
Expand-Archive -LiteralPath $archivePath -DestinationPath $extractDir -Force
319+
Expand-Archive `
320+
-LiteralPath $archivePath `
321+
-DestinationPath $extractDir `
322+
-Force
311323

312-
$exeCandidate = Get-ChildItem -LiteralPath $extractDir -Recurse -File -Filter $BinName |
324+
$exeCandidate = Get-ChildItem `
325+
-LiteralPath $extractDir `
326+
-Recurse `
327+
-File `
328+
-Filter $BinName |
313329
Select-Object -First 1
314330

315331
if (-not $exeCandidate) {
@@ -323,9 +339,71 @@ function Install-Cli([string]$archivePath, [string]$tmpDir) {
323339
$exe,
324340
[System.StringComparison]::OrdinalIgnoreCase
325341
)) {
326-
Copy-Item -LiteralPath $exeCandidate.FullName -Destination $exe -Force
342+
Copy-Item `
343+
-LiteralPath $exeCandidate.FullName `
344+
-Destination $exe `
345+
-Force
346+
}
347+
348+
$noteSource = Join-Path $extractDir "share\vix\note"
349+
$noteDestination = Join-Path $ShareDir "vix\note"
350+
$noteParent = Split-Path -Parent $noteDestination
351+
352+
$noteIndex = Join-Path $noteSource "index.html"
353+
$noteCss = Join-Path $noteSource "assets\note.css"
354+
$noteJs = Join-Path $noteSource "assets\note.js"
355+
356+
if (-not (Test-Path -LiteralPath $noteIndex -PathType Leaf)) {
357+
Die "CLI archive does not contain Vix Note index.html"
358+
}
359+
360+
if (-not (Test-Path -LiteralPath $noteCss -PathType Leaf)) {
361+
Die "CLI archive does not contain Vix Note note.css"
362+
}
363+
364+
if (-not (Test-Path -LiteralPath $noteJs -PathType Leaf)) {
365+
Die "CLI archive does not contain Vix Note note.js"
366+
}
367+
368+
Step "Installing Vix Note assets to $noteDestination"
369+
370+
New-Item `
371+
-ItemType Directory `
372+
-Force `
373+
-Path $noteParent |
374+
Out-Null
375+
376+
if (Test-Path -LiteralPath $noteDestination) {
377+
Remove-Item `
378+
-LiteralPath $noteDestination `
379+
-Recurse `
380+
-Force
381+
}
382+
383+
Copy-Item `
384+
-LiteralPath $noteSource `
385+
-Destination $noteDestination `
386+
-Recurse `
387+
-Force
388+
389+
$installedIndex = Join-Path $noteDestination "index.html"
390+
$installedCss = Join-Path $noteDestination "assets\note.css"
391+
$installedJs = Join-Path $noteDestination "assets\note.js"
392+
393+
if (-not (Test-Path -LiteralPath $installedIndex -PathType Leaf)) {
394+
Die "failed to install Vix Note index.html"
395+
}
396+
397+
if (-not (Test-Path -LiteralPath $installedCss -PathType Leaf)) {
398+
Die "failed to install Vix Note note.css"
327399
}
328400

401+
if (-not (Test-Path -LiteralPath $installedJs -PathType Leaf)) {
402+
Die "failed to install Vix Note note.js"
403+
}
404+
405+
Ok "Vix Note assets installed"
406+
329407
return $exe
330408
}
331409

vix-site/public/install.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ MINISIGN_PUBKEY="RWSIfpPSznK9A1gWUc8Eg2iXXQwU5d9BYuQNKGOcoujAF2stPu5rKFjQ"
66
VIX_REPO="${VIX_REPO:-vixcpp/vix}"
77
VIX_VERSION="${VIX_VERSION:-latest}"
88
VIX_INSTALL_BIN_DIR="${VIX_INSTALL_BIN_DIR:-$HOME/.local/bin}"
9+
VIX_INSTALL_SHARE_DIR="${VIX_INSTALL_SHARE_DIR:-$HOME/.local/share}"
910

1011
BIN_NAME="vix"
1112

@@ -75,9 +76,10 @@ Usage:
7576
install.sh
7677
7778
Environment:
78-
VIX_VERSION Release version. Example: v2.7.0. Default: latest
79-
VIX_REPO GitHub repo. Default: vixcpp/vix
80-
VIX_INSTALL_BIN_DIR CLI install dir. Default: \$HOME/.local/bin
79+
VIX_VERSION Release version. Example: v2.7.0. Default: latest
80+
VIX_REPO GitHub repo. Default: vixcpp/vix
81+
VIX_INSTALL_BIN_DIR CLI install dir. Default: \$HOME/.local/bin
82+
VIX_INSTALL_SHARE_DIR Runtime assets dir. Default: \$HOME/.local/share
8183
8284
After install:
8385
vix upgrade
@@ -238,6 +240,35 @@ install_cli() {
238240
cp "$src" "$VIX_INSTALL_BIN_DIR/$BIN_NAME"
239241
chmod +x "$VIX_INSTALL_BIN_DIR/$BIN_NAME"
240242

243+
note_src="$extract_dir/share/vix/note"
244+
note_dest="$VIX_INSTALL_SHARE_DIR/vix/note"
245+
246+
[ -f "$note_src/index.html" ] \
247+
|| die "missing Vix Note asset: index.html"
248+
249+
[ -f "$note_src/assets/note.css" ] \
250+
|| die "missing Vix Note asset: note.css"
251+
252+
[ -f "$note_src/assets/note.js" ] \
253+
|| die "missing Vix Note asset: note.js"
254+
255+
step "Installing Vix Note assets to $note_dest"
256+
257+
mkdir -p "$VIX_INSTALL_SHARE_DIR/vix"
258+
rm -rf "$note_dest"
259+
cp -R "$note_src" "$note_dest"
260+
261+
[ -f "$note_dest/index.html" ] \
262+
|| die "failed to install Vix Note index.html"
263+
264+
[ -f "$note_dest/assets/note.css" ] \
265+
|| die "failed to install Vix Note note.css"
266+
267+
[ -f "$note_dest/assets/note.js" ] \
268+
|| die "failed to install Vix Note note.js"
269+
270+
ok "Vix Note assets installed"
271+
241272
DEST="$VIX_INSTALL_BIN_DIR/$BIN_NAME"
242273
}
243274

0 commit comments

Comments
 (0)