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