-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bun.ts
32 lines (25 loc) · 845 Bytes
/
.bun.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
import * as fs from 'node:fs/promises';
const directory = String(__dirname).replace(/\\/g, '/');
const isMjs = process.argv.includes('--mjs');
async function getFiles(path: string): Promise<string[]> {
const entries = await fs.readdir(path, {withFileTypes: true});
const files = entries
.filter(entry => entry.isFile() && entry.name.endsWith('.ts'))
.map(file => `${path}/${file.name}`);
const folders = entries.filter(entry => entry.isDirectory());
for (const folder of folders) {
files.push(...(await getFiles(`${path}/${folder.name}`)));
}
return files;
}
getFiles('./src').then(async files => {
for (const file of files) {
await Bun.build({
entrypoints: [`${directory}/${file}`],
external: isMjs ? ['*'] : [],
naming: isMjs ? '[dir]/[name].mjs' : undefined,
outdir: './dist',
root: './src',
});
}
});