build(simulator): cleanup TS configuration
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
CommitLineData
653b69b4 1/* eslint-disable n/no-unpublished-import */
eadc058c 2import * as os from 'node:os';
31b5738e 3
f412fe24 4import json from '@rollup/plugin-json';
8b6da988
JB
5import terser from '@rollup/plugin-terser';
6import typescript from '@rollup/plugin-typescript';
672551ed 7import { copy } from '@web/rollup-plugin-copy';
cb1948a3 8import analyze from 'rollup-plugin-analyzer';
44b07a21 9import del from 'rollup-plugin-delete';
44b07a21 10
eadc058c
JB
11const availableParallelism = () => {
12 // eslint-disable-next-line no-shadow
13 let availableParallelism = 1;
14 try {
15 availableParallelism = os.availableParallelism();
16 } catch {
17 const numberOfCpus = os.cpus();
18 if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) {
19 availableParallelism = numberOfCpus.length;
20 }
21 }
22 return availableParallelism;
23};
24
1d064457 25const isDevelopmentBuild = process.env.BUILD === 'development';
51022aa0 26const isAnalyzeBuild = process.env.ANALYZE;
92bee070 27const sourceMap = !!isDevelopmentBuild;
1d064457 28
44b07a21 29export default {
5a010bf0 30 input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
b768993d 31 strictDeprecations: true,
44a95b7f
JB
32 output: [
33 {
34 dir: 'dist',
2896e06d 35 format: 'esm',
92bee070 36 sourcemap: sourceMap,
eadc058c 37 plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
44a95b7f 38 },
44a95b7f 39 ],
e7aeea18 40 external: [
e3018bc4
JB
41 '@mikro-orm/core',
42 '@mikro-orm/reflection',
43 'ajv',
e3018bc4 44 'ajv-formats',
e7aeea18
JB
45 'basic-ftp',
46 'chalk',
a675e34b 47 'date-fns',
32f5e42d 48 'deep-clone',
852a4c5f 49 'http-status-codes',
088ee3c1 50 'just-merge',
f31d1d0c
JB
51 'mnemonist/lru-map-with-delete.js',
52 'mnemonist/queue.js',
e7aeea18 53 'mongodb',
01f4001e 54 'node:async_hooks',
0c7370da 55 'node:crypto',
942f9727 56 'node:events',
130783a7 57 'node:fs',
01f4001e 58 'node:http',
8334d329 59 'node:http2',
130783a7 60 'node:path',
01f4001e 61 'node:perf_hooks',
8a168938 62 'node:stream',
130783a7 63 'node:url',
0c7370da 64 'node:util',
01f4001e 65 'node:worker_threads',
e7aeea18 66 'poolifier',
e7aeea18 67 'tar',
e3018bc4 68 'winston',
e7aeea18 69 'winston-daily-rotate-file',
b768993d 70 'winston/lib/winston/transports/index.js',
e3018bc4 71 'ws',
e7aeea18 72 ],
44b07a21 73 plugins: [
84e52c2c 74 json(),
8b6da988 75 typescript({
0f454015 76 tsconfig: 'tsconfig.json',
c98873ea 77 compilerOptions: {
92bee070 78 sourceMap,
c98873ea 79 },
44b07a21
JB
80 }),
81 del({
045639f5
JB
82 targets: [
83 'dist/*',
84 '!dist/assets',
85 'dist/assets/*.json',
045639f5 86 'dist/assets/json-schemas',
0c995ea6
JB
87 'dist/assets/station-templates',
88 'dist/assets/ui-protocol',
045639f5 89 ],
c4a19794
JB
90 }),
91 copy({
672551ed
JB
92 rootDir: 'src',
93 patterns: 'assets/**/*.json',
94 exclude: [
95 'assets/config-template.json',
70b77dcd 96 'assets/*config[-_.]*.json',
672551ed 97 'assets/idtags-template.json',
5d1a7b7d 98 'assets/authorization-tags-template.json',
672551ed
JB
99 'assets/ui-protocol/**/*',
100 ],
cb1948a3 101 }),
51022aa0 102 isAnalyzeBuild && analyze(),
e7aeea18 103 ],
44b07a21 104};