|
| 1 | +#!/usr/bin/env node |
| 2 | +import { spawn } from 'node:child_process'; |
| 3 | + |
| 4 | +const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm'; |
| 5 | + |
| 6 | +function runScript(script, extraEnv = {}) { |
| 7 | + return new Promise((resolve, reject) => { |
| 8 | + const child = spawn(npmCommand, ['run', script], { |
| 9 | + env: { ...process.env, ...extraEnv }, |
| 10 | + stdio: 'inherit', |
| 11 | + }); |
| 12 | + |
| 13 | + child.on('error', reject); |
| 14 | + child.on('exit', (code, signal) => { |
| 15 | + if (code === 0) { |
| 16 | + resolve(); |
| 17 | + return; |
| 18 | + } |
| 19 | + reject(new Error(`${script} failed (${signal ?? `exit ${code}`})`)); |
| 20 | + }); |
| 21 | + }); |
| 22 | +} |
| 23 | + |
| 24 | +async function runPhase(label, tasks) { |
| 25 | + const results = await Promise.allSettled(tasks.map(({ script, env }) => runScript(script, env))); |
| 26 | + const failures = results |
| 27 | + .map((result, index) => ({ result, script: tasks[index].script })) |
| 28 | + .filter(({ result }) => result.status === 'rejected'); |
| 29 | + |
| 30 | + if (failures.length > 0) { |
| 31 | + const summary = failures.map(({ script, result }) => `${script}: ${result.reason}`).join('\n'); |
| 32 | + throw new Error(`${label} phase failed:\n${summary}`); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +await runPhase('source validation', [ |
| 37 | + { script: 'orbit:test:content' }, |
| 38 | + { script: 'check' }, |
| 39 | + { script: 'og:generate' }, |
| 40 | +]); |
| 41 | + |
| 42 | +await runScript('worker:assets:production:live'); |
| 43 | + |
| 44 | +await runPhase('built artifact validation', [ |
| 45 | + { script: 'site:test', env: { ORBIT_DIST_DIR: 'dist/client' } }, |
| 46 | + { script: 'browser:test', env: { ORBIT_DIST_DIR: 'dist/client' } }, |
| 47 | + { script: 'production:config:check' }, |
| 48 | + { script: 'worker:bundle:production:live' }, |
| 49 | +]); |
0 commit comments