-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ts
49 lines (42 loc) · 1.24 KB
/
build.ts
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
42
43
44
45
46
47
48
49
/* eslint-disable no-console */
import { readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
const target = process.argv.slice(2)[0] ?? 'node'
if (process.env['DEBUG']) {
console.log(`Target: ${target}`)
}
const getTsRecursive = (path: string) => {
const files = readdirSync(path)
// eslint-disable-next-line functional/prefer-readonly-type
let tsFiles: string[] = []
// eslint-disable-next-line no-restricted-syntax
for (const file of files) {
const filepath = join(path, file)
const tat = statSync(filepath)
if (tat.isDirectory()) {
tsFiles = [...tsFiles, ...getTsRecursive(filepath)]
} else if (file.endsWith('.ts') && !file.endsWith('.test.ts') && !file.endsWith('.d.ts')) {
tsFiles = [...tsFiles, filepath]
}
}
return tsFiles
}
void Bun.build({
entrypoints: getTsRecursive(process.cwd()),
target: 'bun',
outdir: '.',
}).then((stdout) => {
if (stdout.logs.length > 0) {
console.log(stdout.logs)
}
if (process.env['DEBUG']) {
if (stdout.success) {
console.log('success!')
}
if (stdout.outputs.length > 0) {
console.log(stdout.outputs.map((output) => output.path.replace(process.cwd(), '')).join('\n'))
}
}
}, (err) => {
console.error(err)
})