|
1 |
| -import { readdirSync, readFileSync, existsSync } from 'fs' |
2 |
| -import { execa } from 'execa' |
| 1 | +import { existsSync, readFileSync, readdirSync } from 'node:fs' |
| 2 | +import { spawn } from 'node:child_process' |
| 3 | + |
| 4 | +function exec(command, params, ops) { |
| 5 | + const p = spawn(command, params, ops) |
| 6 | + |
| 7 | + return new Promise((resolve) => { |
| 8 | + p.on('exit', (code) => { |
| 9 | + resolve(code) |
| 10 | + }) |
| 11 | + }) |
| 12 | +} |
3 | 13 |
|
4 | 14 | const examples = readdirSync('examples')
|
5 |
| - .filter((f) => existsSync(`examples/${f}/package.json`)) |
6 |
| - .map((f) => ({ |
| 15 | + .filter(f => existsSync(`examples/${f}/package.json`)) |
| 16 | + .map(f => ({ |
7 | 17 | folder: `examples/${f}`,
|
8 | 18 | package: JSON.parse(readFileSync(`examples/${f}/package.json`)),
|
9 | 19 | }))
|
10 | 20 |
|
11 |
| -async function buildExamples () { |
12 |
| - await execa('pnpm', ['i'], { stdio: 'inherit' }) |
13 |
| - await execa('pnpm', ['build'], { stdio: 'inherit' }) |
| 21 | +async function buildExamples() { |
| 22 | + await exec('pnpm', ['i'], { stdio: 'inherit' }) |
| 23 | + await exec('pnpm', ['build'], { stdio: 'inherit' }) |
| 24 | + await exec('pnpm', ['rimraf', 'node_modules'], { stdio: 'inherit' }) |
14 | 25 |
|
15 | 26 | for (const example of examples) {
|
16 | 27 | console.log(`building ${example.folder}...`)
|
17 |
| - await execa('pnpm', ['add', `link:../../`], { stdio: 'inherit', cwd: example.folder }) |
18 |
| - await execa('pnpm', ['i'], { stdio: 'inherit', cwd: example.folder }) |
19 |
| - await execa('pnpm', ['build'], { stdio: 'inherit', cwd: example.folder }) |
| 28 | + await exec('pnpm', ['add', 'file:../../'], { stdio: 'inherit', cwd: example.folder }) |
| 29 | + await exec('pnpm', ['i'], { stdio: 'inherit', cwd: example.folder }) |
| 30 | + await exec('pnpm', ['build'], { stdio: 'inherit', cwd: example.folder }) |
20 | 31 | }
|
21 | 32 |
|
22 |
| - for (const typescriptExample of examples.filter((ex) => ex.package.scripts.typecheck != null)) { |
| 33 | + for (const typescriptExample of examples.filter(ex => ex.package.scripts.typecheck != null)) { |
23 | 34 | console.log(`typechecking ${typescriptExample.folder}...`)
|
24 |
| - await execa('pnpm', ['typecheck'], { stdio: 'inherit', cwd: typescriptExample.folder }) |
| 35 | + await exec('pnpm', ['typecheck'], { stdio: 'inherit', cwd: typescriptExample.folder }) |
25 | 36 | }
|
26 | 37 | }
|
27 | 38 |
|
|
0 commit comments