37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
const { execSync } = require("child_process");
|
|
const fs = require("fs");
|
|
|
|
const isWin = process.platform === "win32";
|
|
const isMac = process.platform === "darwin";
|
|
const src = "dist";
|
|
const dstWin = "Z:\\docker\\webpage\\frontend\\";
|
|
const dstMac = "/Volumes/gahusb.synology.me/docker/webpage/frontend/";
|
|
const dst = isWin ? dstWin : dstMac;
|
|
|
|
if (!fs.existsSync(src)) {
|
|
console.error("dist not found. Run build first.");
|
|
process.exit(1);
|
|
}
|
|
if (!fs.existsSync(dst)) {
|
|
console.error("NAS path not found. Check mount: " + dst);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (isWin) {
|
|
const cmd =
|
|
'powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference=\\"Stop\\"; $src=\\"dist\\"; $dst=\\"Z:\\\\docker\\\\webpage\\\\frontend\\\\\\"; if(!(Test-Path $src)){ throw \\"dist not found. Run build first.\\" }; if(!(Test-Path $dst)){ throw \\"NAS drive not found. Check Z: mapping.\\" }; $log = Join-Path (Get-Location) \\"robocopy.log\\"; robocopy $src $dst /MIR /R:1 /W:1 /E /NFL /NDL /NP /V /TEE /LOG:$log; $rc = $LASTEXITCODE; if($rc -ge 8){ Write-Host \\"robocopy failed with code $rc. See $log\\"; exit $rc } else { exit 0 }"';
|
|
execSync(cmd, { stdio: "inherit" });
|
|
} else {
|
|
const baseArgs = ["rsync", "-r", "--delete", "--delete-delay"];
|
|
const macSafeArgs = [
|
|
"--omit-dir-times",
|
|
"--no-perms",
|
|
"--no-owner",
|
|
"--no-group",
|
|
"--no-times",
|
|
];
|
|
const args = isMac ? baseArgs.concat(macSafeArgs) : baseArgs.concat(["-t"]);
|
|
const cmd = `${args.join(" ")} ${src}/ ${dst}`;
|
|
execSync(cmd, { stdio: "inherit" });
|
|
}
|