import { spawnSync } from 'node:child_process'; import { mkdirSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; const qaVersion = process.env.PUBLIC_QA_VERSION ?? makeQaVersion(); runPnpmScript('verify:local-release'); runPnpmScript('qa:early'); writeReleaseManifest(qaVersion); runPnpmScript('deploy:nas:dist'); runPnpmScript('verify:public-deploy', { PUBLIC_QA_VERSION: qaVersion }); console.log(`Shipped and verified public deploy with PUBLIC_QA_VERSION=${qaVersion}`); function makeQaVersion() { const stamp = new Date().toISOString().replace(/[-:.TZ]/g, '').slice(0, 14); return `ship-${stamp}`; } function writeReleaseManifest(qaVersion) { const manifest = { app: 'heros_web', qaVersion, commit: gitValue(['rev-parse', 'HEAD'], 'unknown'), shortCommit: gitValue(['rev-parse', '--short', 'HEAD'], 'unknown'), branch: gitValue(['branch', '--show-current'], 'unknown'), generatedAt: new Date().toISOString(), verification: ['verify:local-release', 'qa:early', 'verify:public-deploy'] }; mkdirSync('dist', { recursive: true }); writeFileSync(join('dist', 'release-manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`, 'utf8'); console.log(`Wrote dist/release-manifest.json for ${manifest.shortCommit} (${qaVersion})`); } function gitValue(args, fallback) { const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8' }); if (result.status !== 0) { return fallback; } return result.stdout.trim() || fallback; } function runPnpmScript(scriptName, extraEnv = {}) { const label = `pnpm run ${scriptName}`; console.log(`\n$ ${label}`); const result = process.platform === 'win32' ? spawnSync(process.env.ComSpec ?? 'cmd.exe', ['/d', '/s', '/c', `pnpm.cmd run ${scriptName}`], { cwd: process.cwd(), env: { ...process.env, ...extraEnv }, stdio: 'inherit' }) : spawnSync('pnpm', ['run', scriptName], { cwd: process.cwd(), env: { ...process.env, ...extraEnv }, stdio: 'inherit' }); if (result.status !== 0) { throw new Error(`Command failed: ${label}`); } }