fix: scripts support win32 (#12613)

Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
huangkairan
2026-03-03 19:19:56 +08:00
committed by GitHub
parent 138788b1d4
commit 1cf0257326
10 changed files with 40 additions and 12 deletions

21
scripts/copySpaBuild.mts Normal file
View File

@@ -0,0 +1,21 @@
import { cpSync, existsSync, mkdirSync } from 'node:fs';
import path from 'node:path';
const root = path.resolve(import.meta.dirname, '..');
const spaDir = path.resolve(root, 'public/spa');
const distDirs = ['desktop', 'mobile'] as const;
const copyDirs = ['assets', 'i18n', 'vendor'] as const;
mkdirSync(spaDir, { recursive: true });
for (const distDir of distDirs) {
for (const dir of copyDirs) {
const sourceDir = path.resolve(root, `dist/${distDir}/${dir}`);
const targetDir = path.resolve(spaDir, dir);
if (!existsSync(sourceDir)) continue;
cpSync(sourceDir, targetDir, { recursive: true });
console.log(`Copied dist/${distDir}/${dir} -> public/spa/${dir}`);
}
}

View File

@@ -1,7 +1,7 @@
import { type ChildProcess, spawn } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import net from 'node:net';
import { resolve } from 'node:path';
const NEXT_HOST = 'localhost';
@@ -17,7 +17,9 @@ const resolveNextPort = (): number => {
const match = devNext.match(/(?:--port|-p)\s+(\d+)/);
if (match) return Number(match[1]);
}
} catch { /* fallback */ }
} catch {
/* fallback */
}
return 3010;
};
@@ -36,6 +38,7 @@ const runNpmScript = (scriptName: string) =>
spawn(npmCommand, ['run', scriptName], {
env: process.env,
stdio: 'inherit',
shell: process.platform === 'win32',
});
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));