|
| 1 | +import yargs from 'yargs'; |
| 2 | +import { hideBin } from 'yargs/helpers'; |
| 3 | +import { promises as fs } from 'fs'; |
| 4 | +import { fork } from 'child_process'; |
| 5 | +import { URL, fileURLToPath } from 'url'; |
| 6 | +import { once } from 'events'; |
| 7 | + |
| 8 | +async function getPathChoices() { |
| 9 | + const dirents = await fs.readdir(new URL('.', import.meta.url), { |
| 10 | + withFileTypes: true |
| 11 | + }); |
| 12 | + |
| 13 | + const choices = []; |
| 14 | + for (const dirent of dirents) { |
| 15 | + if (!dirent.isDirectory()) continue; |
| 16 | + |
| 17 | + choices.push(dirent.name); |
| 18 | + } |
| 19 | + |
| 20 | + return choices; |
| 21 | +} |
| 22 | + |
| 23 | +const argv = hideBin(process.argv); |
| 24 | + |
| 25 | +async function getName() { |
| 26 | + return yargs(argv) |
| 27 | + .option('name', { |
| 28 | + demandOption: true, |
| 29 | + choices: await getPathChoices() |
| 30 | + }) |
| 31 | + .parseSync().name; |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +const runnerPath = fileURLToPath(new URL('runner.js', import.meta.url)), |
| 36 | + path = new URL(`${await getName()}/`, import.meta.url), |
| 37 | + metadata = await import(new URL('index.js', path)); |
| 38 | + |
| 39 | +for (const file of await fs.readdir(path)) { |
| 40 | + if (file === 'index.js') continue; |
| 41 | + |
| 42 | + const benchmarkProcess = fork(runnerPath, [ |
| 43 | + ...argv, |
| 44 | + '--path', |
| 45 | + fileURLToPath(path) + file |
| 46 | + ]); |
| 47 | + |
| 48 | + await once(benchmarkProcess, 'message'); |
| 49 | + benchmarkProcess.send(metadata); |
| 50 | + await once(benchmarkProcess, 'close'); |
| 51 | +} |
0 commit comments