代码提交
This commit is contained in:
1 parent
5901246030
commit
47faa9bcdf
7 files changed
+767
-227
No files matched your search
@@ -0,0 +1,32 @@
|
||||
# Package frontend node_modules for offline development.
|
||||
# Uses tar -h to dereference pnpm junctions so the archive is self-contained.
|
||||
param(
|
||||
[string]$OutputDir = (Join-Path (Split-Path $PSScriptRoot -Parent) "dist")
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = Split-Path $PSScriptRoot -Parent
|
||||
$Frontend = Join-Path $Root "frontend-web"
|
||||
$Archive = Join-Path $OutputDir "frontend-offline-deps.tar.gz"
|
||||
|
||||
if (-not (Test-Path (Join-Path $Frontend "node_modules\.pnpm"))) {
|
||||
throw "frontend-web/node_modules is missing or incomplete. Run 'pnpm install' in frontend-web first."
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
|
||||
if (Test-Path $Archive) { Remove-Item $Archive -Force }
|
||||
|
||||
Write-Host "Packaging frontend dependencies..."
|
||||
Write-Host " Source: $Frontend"
|
||||
Write-Host " Output: $Archive"
|
||||
|
||||
$start = Get-Date
|
||||
tar -czhf $Archive -C $Frontend node_modules package.json pnpm-lock.yaml
|
||||
$elapsed = ((Get-Date) - $start).TotalSeconds
|
||||
$sizeMb = [math]::Round((Get-Item $Archive).Length / 1MB, 2)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Done in ${elapsed}s — ${sizeMb} MB"
|
||||
Write-Host ""
|
||||
Write-Host "Copy to offline machine, then run:"
|
||||
Write-Host " scripts\restore-frontend-offline-deps.ps1 -Archive <path-to-archive>"
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
FRONTEND="${ROOT}/frontend-web"
|
||||
OUTPUT_DIR="${1:-${ROOT}/dist}"
|
||||
ARCHIVE="${OUTPUT_DIR}/frontend-offline-deps.tar.gz"
|
||||
|
||||
if [[ ! -d "${FRONTEND}/node_modules/.pnpm" ]]; then
|
||||
echo "frontend-web/node_modules is missing or incomplete. Run 'pnpm install' in frontend-web first." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "${OUTPUT_DIR}"
|
||||
rm -f "${ARCHIVE}"
|
||||
|
||||
echo "Packaging frontend dependencies..."
|
||||
echo " Source: ${FRONTEND}"
|
||||
echo " Output: ${ARCHIVE}"
|
||||
|
||||
tar -czhf "${ARCHIVE}" -C "${FRONTEND}" node_modules package.json pnpm-lock.yaml
|
||||
|
||||
SIZE_MB=$(du -m "${ARCHIVE}" | awk '{print $1}')
|
||||
echo ""
|
||||
echo "Done — ${SIZE_MB} MB"
|
||||
echo ""
|
||||
echo "Copy to offline machine, then run:"
|
||||
echo " scripts/restore-frontend-offline-deps.sh <path-to-archive>"
|
||||
@@ -0,0 +1,42 @@
|
||||
# Restore frontend node_modules from an offline dependency archive.
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Archive
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = Split-Path $PSScriptRoot -Parent
|
||||
$Frontend = Join-Path $Root "frontend-web"
|
||||
|
||||
if (-not (Test-Path $Archive)) {
|
||||
throw "Archive not found: $Archive"
|
||||
}
|
||||
|
||||
Write-Host "Restoring frontend dependencies to $Frontend ..."
|
||||
|
||||
# Back up existing node_modules if present
|
||||
$backup = Join-Path $Frontend "node_modules.bak"
|
||||
if (Test-Path (Join-Path $Frontend "node_modules")) {
|
||||
if (Test-Path $backup) { Remove-Item $backup -Recurse -Force }
|
||||
Rename-Item (Join-Path $Frontend "node_modules") "node_modules.bak"
|
||||
Write-Host " Existing node_modules backed up to node_modules.bak"
|
||||
}
|
||||
|
||||
tar -xzf $Archive -C $Frontend
|
||||
|
||||
# Quick sanity check
|
||||
$required = @(
|
||||
"node_modules\.pnpm",
|
||||
"node_modules\react\package.json",
|
||||
"node_modules\vite\package.json"
|
||||
)
|
||||
foreach ($rel in $required) {
|
||||
if (-not (Test-Path (Join-Path $Frontend $rel))) {
|
||||
throw "Restore incomplete — missing $rel"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Restore complete. You can now run:"
|
||||
Write-Host " cd frontend-web"
|
||||
Write-Host " pnpm dev"
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "Usage: $0 <path-to-frontend-offline-deps.tar.gz>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ARCHIVE="$1"
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
FRONTEND="${ROOT}/frontend-web"
|
||||
|
||||
if [[ ! -f "${ARCHIVE}" ]]; then
|
||||
echo "Archive not found: ${ARCHIVE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Restoring frontend dependencies to ${FRONTEND} ..."
|
||||
|
||||
if [[ -d "${FRONTEND}/node_modules" ]]; then
|
||||
rm -rf "${FRONTEND}/node_modules.bak"
|
||||
mv "${FRONTEND}/node_modules" "${FRONTEND}/node_modules.bak"
|
||||
echo " Existing node_modules backed up to node_modules.bak"
|
||||
fi
|
||||
|
||||
tar -xzf "${ARCHIVE}" -C "${FRONTEND}"
|
||||
|
||||
for rel in node_modules/.pnpm node_modules/react/package.json node_modules/vite/package.json; do
|
||||
if [[ ! -e "${FRONTEND}/${rel}" ]]; then
|
||||
echo "Restore incomplete — missing ${rel}" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Restore complete. You can now run:"
|
||||
echo " cd frontend-web"
|
||||
echo " pnpm dev"
|
||||
Reference in new issue
Block a user