Files
blitzkit/scripts/build.ts
T

63 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2023-07-15 01:21:59 +00:00
import { BuildOptions, build } from 'esbuild';
2023-08-04 02:13:21 +00:00
import { copyFile, mkdirSync, rmSync } from 'fs';
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');
const buildBot = argv.includes('--build=bot') || buildAll;
const buildServer = argv.includes('--build=server') || buildAll;
2023-06-12 02:01:32 +00:00
if (isProd) {
// only remove in production to ensure no time is wasted in dev
console.log('Removing dist...');
2023-08-04 02:13:21 +00:00
rmSync('dist', { recursive: true, force: true });
console.log('Dist removed');
console.log('Creating dist...');
2023-08-04 02:13:21 +00:00
mkdirSync('dist');
console.log('Dist created');
console.log('Copying package.json...');
2023-08-04 02:13:21 +00:00
copyFile('package.dist.json', 'dist/package.json', () =>
console.log('package.json copied'),
2023-06-30 17:38:44 +00:00
);
}
2023-06-12 02:01:32 +00:00
2023-07-15 01:21:59 +00:00
const commonOptions: BuildOptions = {
2023-06-12 02:01:32 +00:00
platform: 'node',
loader: {
'.node': 'copy',
'.ttf': 'file',
},
2023-08-04 02:13:21 +00:00
format: 'cjs',
2023-06-12 02:01:32 +00:00
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) {
console.log('Building bot...');
2023-06-26 17:25:28 +00:00
build({
...commonOptions,
entryPoints: ['src/bot.ts'],
outfile: 'dist/bot.cjs',
2023-07-18 00:17:00 +00:00
}).then(() => console.log('Bot built'));
2023-06-26 17:25:28 +00:00
}
if (buildServer) {
console.log('Building server...');
2023-06-26 17:25:28 +00:00
build({
...commonOptions,
entryPoints: ['src/server.ts'],
outfile: 'dist/server.cjs',
}).then(() => {
console.log('Server built');
2023-06-26 17:25:28 +00:00
});
}