Files
blitzkit/packages/scripts/src/buildBot.ts
T

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-11-26 21:03:01 -06:00
import { build } from 'esbuild';
2024-11-27 19:59:53 -06:00
import { cp, readdir, rm } from 'fs/promises';
2024-11-27 20:09:31 -06:00
import { argv } from 'process';
2024-11-26 21:03:01 -06:00
2024-11-28 13:08:06 -06:00
const projectDir = '../..';
const srcRoot = `${projectDir}/packages/bot`;
const distRoot = `${projectDir}/dist/bot`;
const modulesRoot = `${projectDir}/node_modules`;
2024-11-27 19:59:53 -06:00
const workers = await readdir(`${srcRoot}/src/workers`);
2024-11-27 20:09:31 -06:00
const dev = argv.includes('--dev');
2024-11-27 19:59:53 -06:00
await rm(distRoot, { recursive: true, force: true });
2024-11-26 21:03:01 -06:00
build({
entryPoints: [
2024-11-27 19:59:53 -06:00
`${srcRoot}/src/main.ts`,
...workers.map((worker) => `${srcRoot}/src/workers/${worker}`),
2024-11-26 21:03:01 -06:00
],
bundle: true,
outdir: '../../dist/bot',
platform: 'node',
format: 'esm',
loader: {
'.ttf': 'file',
2024-11-27 19:59:53 -06:00
'.node': 'empty',
2024-11-29 12:06:23 -06:00
'.json': 'json',
2024-11-26 21:03:01 -06:00
},
2024-11-29 12:28:36 -06:00
external: ['sharp'],
2024-11-27 20:09:31 -06:00
minifyIdentifiers: false, // causes goofy ahh issues
minifySyntax: !dev,
minifyWhitespace: !dev,
sourcemap: !dev,
2024-11-29 12:50:15 -06:00
jsxImportSource: 'react',
jsx: 'automatic',
2024-11-26 21:03:01 -06:00
});
2024-11-27 19:59:53 -06:00
2024-11-28 13:08:06 -06:00
for (const module of await readdir(`${modulesRoot}/@resvg`)) {
readdir(`${modulesRoot}/@resvg/${module}`).then((files) =>
files
.filter((file) => file.endsWith('.node'))
.map((file) =>
cp(
2024-11-27 19:59:53 -06:00
`${modulesRoot}/@resvg/${module}/${file}`,
`${distRoot}/workers/${file}`,
2024-11-28 13:08:06 -06:00
),
),
);
}
if (!dev) {
await cp(`${projectDir}/prisma`, `${distRoot}/prisma`, { recursive: true });
for (const file of await readdir(`${modulesRoot}/prisma`).then((files) =>
files.filter((file) => file.endsWith('.node')),
)) {
cp(`${modulesRoot}/prisma/${file}`, `${distRoot}/prisma/${file}`);
}
}