build(simulator): print to stdout building information
[e-mobility-charging-stations-simulator.git] / bundle.js
1 /* eslint-disable n/no-unpublished-import */
2 import { env } from 'node:process';
3
4 import chalk from 'chalk';
5 import { build } from 'esbuild';
6 import { clean } from 'esbuild-plugin-clean';
7 import { copy } from 'esbuild-plugin-copy';
8
9 const isDevelopmentBuild = env.BUILD === 'development';
10 const sourcemap = !!isDevelopmentBuild;
11
12 console.info(chalk.green(`Building in ${isDevelopmentBuild ? 'development' : 'production'} mode`));
13 console.time('Build time');
14 (async () => {
15 await build({
16 entryPoints: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'],
17 bundle: true,
18 platform: 'node',
19 format: 'esm',
20 external: [
21 '@mikro-orm/*',
22 'ajv',
23 'ajv-formats',
24 'basic-ftp',
25 'chalk',
26 'date-fns',
27 'http-status-codes',
28 'just-merge',
29 'logform',
30 'mnemonist/*',
31 'mongodb',
32 'node:*',
33 'poolifier',
34 'tar',
35 'winston',
36 'winston/*',
37 'winston-daily-rotate-file',
38 'ws',
39 ],
40 minify: true,
41 sourcemap,
42 entryNames: '[name]',
43 outdir: './dist',
44 banner: {
45 js: "import { createRequire } from 'module';const require = createRequire(import.meta.url);",
46 },
47 plugins: [
48 clean({
49 patterns: [
50 './dist/*',
51 '!./dist/assets',
52 './dist/assets/*.json',
53 './dist/assets/json-schemas',
54 './dist/assets/station-templates',
55 './dist/assets/ui-protocol',
56 ],
57 }),
58 copy({
59 assets: [
60 {
61 from: ['./src/assets/config.json'],
62 to: ['./assets'],
63 },
64 {
65 from: ['./src/assets/idtags!(-template)*.json'],
66 to: ['./assets'],
67 },
68 {
69 from: ['./src/assets/json-schemas/**/*.json'],
70 to: ['./assets/json-schemas'],
71 },
72 {
73 from: ['./src/assets/station-templates/**/*.json'],
74 to: ['./assets/station-templates'],
75 },
76 ],
77 }),
78 ],
79 });
80 })();
81 console.timeEnd('Build time');