2023-06-12 02:01:32 +00:00
|
|
|
import { build } from 'esbuild';
|
2023-07-05 02:09:36 +00:00
|
|
|
import { copyFile, mkdir, rm } from 'fs/promises';
|
2023-06-16 02:01:06 +00:00
|
|
|
import { argv } from 'process';
|
|
|
|
|
|
2023-06-26 15:05:05 +00:00
|
|
|
const isProd = !argv.includes('--dev');
|
|
|
|
|
const buildAll = argv.includes('--build=all');
|
2023-07-14 01:32:20 +00:00
|
|
|
const buildBot = argv.includes('--build=bot') || buildAll;
|
|
|
|
|
const buildServer = argv.includes('--build=server') || buildAll;
|
2023-06-12 02:01:32 +00:00
|
|
|
|
2023-06-26 18:08:07 +00:00
|
|
|
if (isProd) {
|
|
|
|
|
// only remove in production to ensure no time is wasted in dev
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Removing dist...');
|
2023-06-30 17:38:44 +00:00
|
|
|
await rm('dist', { recursive: true, force: true });
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Dist removed');
|
2023-06-26 18:08:07 +00:00
|
|
|
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Creating dist...');
|
2023-06-30 17:38:44 +00:00
|
|
|
await mkdir('dist');
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Dist created');
|
2023-06-26 18:08:07 +00:00
|
|
|
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Copying package.json...');
|
2023-06-30 17:38:44 +00:00
|
|
|
copyFile('package.dist.json', 'dist/package.json').then(() =>
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('package.json copied'),
|
2023-06-30 17:38:44 +00:00
|
|
|
);
|
2023-06-26 18:08:07 +00:00
|
|
|
}
|
2023-06-12 02:01:32 +00:00
|
|
|
|
2023-06-26 15:05:05 +00:00
|
|
|
const commonOptions = {
|
2023-06-12 02:01:32 +00:00
|
|
|
platform: 'node',
|
|
|
|
|
loader: {
|
|
|
|
|
'.node': 'copy',
|
|
|
|
|
'.ttf': 'file',
|
|
|
|
|
},
|
|
|
|
|
|
2023-06-17 18:05:04 +00:00
|
|
|
bundle: true,
|
2023-06-19 17:35:28 +00:00
|
|
|
sourcemap: true,
|
2023-06-12 02:01:32 +00:00
|
|
|
minifyIdentifiers: false, // causes errors
|
2023-06-16 17:41:48 +00:00
|
|
|
minifySyntax: isProd,
|
|
|
|
|
minifyWhitespace: isProd,
|
2023-06-17 18:05:04 +00:00
|
|
|
|
|
|
|
|
logLevel: isProd ? 'info' : 'silent',
|
2023-06-26 15:05:05 +00:00
|
|
|
};
|
|
|
|
|
|
2023-06-26 17:25:28 +00:00
|
|
|
if (buildBot) {
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Building bot...');
|
2023-06-26 17:25:28 +00:00
|
|
|
build({
|
|
|
|
|
...commonOptions,
|
|
|
|
|
|
|
|
|
|
entryPoints: ['src/bot.ts'],
|
|
|
|
|
outfile: 'dist/bot.cjs',
|
2023-06-26 18:08:07 +00:00
|
|
|
}).then(() => {
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Bot built');
|
2023-06-26 17:25:28 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildServer) {
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Building server...');
|
2023-06-26 17:25:28 +00:00
|
|
|
build({
|
|
|
|
|
...commonOptions,
|
|
|
|
|
|
|
|
|
|
entryPoints: ['src/server.ts'],
|
|
|
|
|
outfile: 'dist/server.cjs',
|
2023-06-26 18:08:07 +00:00
|
|
|
}).then(() => {
|
2023-07-14 01:32:20 +00:00
|
|
|
console.log('Server built');
|
2023-06-26 17:25:28 +00:00
|
|
|
});
|
|
|
|
|
}
|