| 1 | // a build that fans out to worker processes. each worker is this same file, |
| 2 | // started with a node of the build as its global progress root: what it |
| 3 | // starts and logs is drawn by the one process that has the terminal. |
| 4 | const [worker] = process.argv.slice(2); |
| 5 | const steps = ["parse", "transform", "minify"]; |
| 6 | |
| 7 | if (worker) { |
| 8 | log.info(`${worker}: found ${steps.length} steps`); |
| 9 | for (const step of steps) { |
| 10 | using task = progress.start(step, { total: 30 }); |
| 11 | for (let i = 0; i < 30; i += 1) { |
| 12 | await async.delay(20 + Math.random() * 60); |
| 13 | task.value += 1; |
| 14 | if (i === 15) task.log.warn(`${step} is taking a while`); |
| 15 | } |
| 16 | } |
| 17 | log.info(`${worker}: done`); |
| 18 | } else { |
| 19 | using build = progress.start("build"); |
| 20 | await Promise.all(["pages", "styles", "scripts"].map(async (name) => { |
| 21 | using node = build.start(name); |
| 22 | await subprocess.spawn([process.execPath, import.meta.filename, name], { progress: node }).wait(); |
| 23 | })); |
| 24 | log.info("built"); |
| 25 | } |
| 26 | |
| 27 | import * as async from "../async.ts"; |
| 28 | import * as log from "../log.ts"; |
| 29 | import * as progress from "../progress.ts"; |
| 30 | import * as subprocess from "../subprocess.ts"; |