|
| 1 | +const { spawn } = require('node:child_process'); |
| 2 | +const waitOn = require('wait-on'); |
| 3 | +const path = require('node:path'); |
| 4 | + |
| 5 | +const root = path.resolve(__dirname, '..'); |
| 6 | + |
| 7 | +function run(cmd, args) { |
| 8 | + return spawn(cmd, args, { stdio: 'inherit', cwd: root, shell: true }); |
| 9 | +} |
| 10 | + |
| 11 | +async function main() { |
| 12 | + // Build consumers-react and exposes, then serve both groups; start Next consumers (dev) |
| 13 | + await new Promise((res, rej) => { |
| 14 | + const p = run('pnpm', ['--filter', '"@federated-css/*"', '-r', 'run', 'build']); |
| 15 | + p.on('exit', c => (c === 0 ? res() : rej(new Error('build consumers failed')))); |
| 16 | + }); |
| 17 | + await new Promise((res, rej) => { |
| 18 | + const p = run('pnpm', ['--filter', '"federated-css-mono_expose-*"', '-r', 'run', 'build']); |
| 19 | + p.on('exit', c => (c === 0 ? res() : rej(new Error('build exposes failed')))); |
| 20 | + }); |
| 21 | + |
| 22 | + const pReact = run('pnpm', ['--filter', '"@federated-css/*"', '-r', 'run', 'serve']); |
| 23 | + const pExposes = run('pnpm', ['--filter', '"federated-css-mono_expose-*"', '-r', 'run', 'serve']); |
| 24 | + const pNext = run('pnpm', ['--filter', '"@federated-css/next-*"', '-r', 'run', 'start']); |
| 25 | + |
| 26 | + await waitOn({ |
| 27 | + resources: [ |
| 28 | + // consumers-react ports |
| 29 | + 'http://localhost:3001', 'http://localhost:3002', 'http://localhost:3003', |
| 30 | + 'http://localhost:3004', 'http://localhost:3005', 'http://localhost:3006', 'http://localhost:3007', |
| 31 | + // exposes ports |
| 32 | + 'http://localhost:4000', 'http://localhost:4001', 'http://localhost:4002', 'http://localhost:4003', |
| 33 | + 'http://localhost:4004', 'http://localhost:4005', 'http://localhost:4006', 'http://localhost:4007', |
| 34 | + // next consumers |
| 35 | + 'http://localhost:8081', 'http://localhost:8082', 'http://localhost:8083', 'http://localhost:8084' |
| 36 | + ], |
| 37 | + timeout: 300000, |
| 38 | + validateStatus: s => s >= 200 && s < 500, |
| 39 | + }); |
| 40 | + |
| 41 | + const killAll = sig => { pReact.kill(sig); pExposes.kill(sig); pNext.kill(sig); }; |
| 42 | + process.on('SIGINT', () => killAll('SIGINT')); |
| 43 | + process.on('SIGTERM', () => killAll('SIGTERM')); |
| 44 | + |
| 45 | + await new Promise(() => {}); |
| 46 | +} |
| 47 | + |
| 48 | +main().catch(err => { console.error(err); process.exit(1); }); |
| 49 | + |
0 commit comments