roles-bot/scripts/build.mjs
2022-10-16 13:18:25 +02:00

34 lines
No EOL
1,012 B
JavaScript

import esbuild from 'esbuild';
import { rmSync, existsSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
if (existsSync(join(__dirname, '..', 'dist')))
rmSync(join(__dirname, '..', 'dist'), { recursive: true });
const watch = process.argv.includes('--watch');
const dev = process.argv.includes('--dev');
Promise.all([
esbuild.build({
bundle: true,
logLevel: 'info',
format: 'esm',
mainFields: ['browser', 'module', 'main'],
platform: 'neutral',
target: 'es2020',
entryPoints: ['./src/index.ts'],
outfile: './dist/worker.mjs',
sourcemap: dev,
charset: 'utf8',
minify: !dev,
watch: watch
})
]).catch(err => {
console.error('Roles Bot failed to build');
console.error(err.message);
}).then(() =>{
console.log(watch ? 'Waiting for your changes...' : 'Roles Bot has been built');
});