refactor: remove uneeded helper in reservation code
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
1 /* eslint-disable n/no-unpublished-import */
2 import * as os from 'node:os';
3
4 import json from '@rollup/plugin-json';
5 import terser from '@rollup/plugin-terser';
6 import typescript from '@rollup/plugin-typescript';
7 import { copy } from '@web/rollup-plugin-copy';
8 import analyze from 'rollup-plugin-analyzer';
9 import del from 'rollup-plugin-delete';
10
11 const 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
25 const isDevelopmentBuild = process.env.BUILD === 'development';
26 const isAnalyzeBuild = process.env.ANALYZE;
27 const sourceMap = !!isDevelopmentBuild;
28
29 export default {
30 input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
31 strictDeprecations: true,
32 output: [
33 {
34 dir: 'dist',
35 format: 'esm',
36 sourcemap: sourceMap,
37 plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
38 },
39 ],
40 external: [
41 '@mikro-orm/core',
42 '@mikro-orm/reflection',
43 'ajv',
44 'ajv-formats',
45 'basic-ftp',
46 'chalk',
47 'date-fns',
48 'deep-clone',
49 'http-status-codes',
50 'just-merge',
51 'mnemonist/lru-map-with-delete.js',
52 'mnemonist/queue.js',
53 'mongodb',
54 'node:async_hooks',
55 'node:crypto',
56 'node:events',
57 'node:fs',
58 'node:http',
59 'node:http2',
60 'node:path',
61 'node:perf_hooks',
62 'node:stream',
63 'node:url',
64 'node:util',
65 'node:worker_threads',
66 'poolifier',
67 'tar',
68 'winston',
69 'winston-daily-rotate-file',
70 'winston/lib/winston/transports/index.js',
71 'ws',
72 ],
73 plugins: [
74 json(),
75 typescript({
76 tsconfig: 'tsconfig.json',
77 compilerOptions: {
78 sourceMap,
79 },
80 }),
81 del({
82 targets: [
83 'dist/*',
84 '!dist/assets',
85 'dist/assets/*.json',
86 'dist/assets/json-schemas',
87 'dist/assets/station-templates',
88 'dist/assets/ui-protocol',
89 ],
90 }),
91 copy({
92 rootDir: 'src',
93 patterns: 'assets/**/*.json',
94 exclude: [
95 'assets/config-template.json',
96 'assets/*config[-_.]*.json',
97 'assets/idtags-template.json',
98 'assets/authorization-tags-template.json',
99 'assets/ui-protocol/**/*',
100 ],
101 }),
102 isAnalyzeBuild && analyze(),
103 ],
104 };