-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.js
41 lines (37 loc) · 1003 Bytes
/
build.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
40
41
import fs from 'fs/promises'
import path from 'path'
import { fileURLToPath } from 'url'
import { build } from 'esbuild'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
export async function* walk(rootPath) {
for (const fileName of await fs.readdir(rootPath)) {
const filePath = path.join(rootPath, fileName)
if ((await fs.stat(filePath)).isDirectory()) {
yield* walk(filePath)
} else {
yield filePath
}
}
}
const src = path.join(__dirname, 'src', 'index.ts')
const entryPoints = [src]
if (process.argv[2] === 'test') {
for await (const test of walk(path.join(__dirname, 'test'))) {
if (test.endsWith('.spec.ts')) entryPoints.push(test)
}
}
try {
await build({
bundle: true,
sourcemap: true,
format: 'esm',
outdir: path.join(__dirname, 'dist'),
outbase: __dirname,
outExtension: { '.js': '.mjs' },
entryPoints,
external: ['jest', '@jest'],
})
} catch {
process.exitCode = 1
}