Files
blitzkit/scripts/build.js
T

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-06-12 02:01:32 +00:00
import { build } from 'esbuild';
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');
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
2023-06-30 17:38:44 +00:00
console.log('🟡 Removing dist...');
await rm('dist', { recursive: true, force: true });
console.log('✅ Dist removed');
2023-06-30 17:38:44 +00:00
console.log('🟡 Creating dist...');
await mkdir('dist');
console.log('✅ Dist created');
2023-06-30 17:38:44 +00:00
console.log('🟡 Copying package.json...');
copyFile('package.dist.json', 'dist/package.json').then(() =>
console.log('✅ package.json copied'),
);
}
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-06-30 17:38:44 +00:00
console.log('🟡 Building bot...');
2023-06-26 17:25:28 +00:00
build({
...commonOptions,
entryPoints: ['src/bot.ts'],
outfile: 'dist/bot.cjs',
}).then(() => {
2023-06-30 17:38:44 +00:00
console.log('✅ Bot built');
2023-06-26 17:25:28 +00:00
});
}
if (buildServer) {
2023-06-30 17:38:44 +00:00
console.log('🟡 Building server...');
2023-06-26 17:25:28 +00:00
build({
...commonOptions,
entryPoints: ['src/server.ts'],
outfile: 'dist/server.cjs',
}).then(() => {
2023-06-30 17:38:44 +00:00
console.log('✅ Server built');
2023-06-26 17:25:28 +00:00
});
}