fix: ensure charging schedule periods are sorted by startPeriod
[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;
1d064457 27
44b07a21 28export default {
5a010bf0 29 input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
b768993d 30 strictDeprecations: true,
44a95b7f
JB
31 output: [
32 {
33 dir: 'dist',
2896e06d 34 format: 'esm',
31b5738e 35 sourcemap: !!isDevelopmentBuild,
eadc058c 36 plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
44a95b7f 37 },
44a95b7f 38 ],
e7aeea18 39 external: [
e3018bc4
JB
40 '@mikro-orm/core',
41 '@mikro-orm/reflection',
42 'ajv',
e3018bc4 43 'ajv-formats',
e7aeea18
JB
44 'basic-ftp',
45 'chalk',
a675e34b 46 'date-fns',
852a4c5f 47 'http-status-codes',
088ee3c1
JB
48 'just-clone',
49 'just-merge',
f31d1d0c
JB
50 'mnemonist/lru-map-with-delete.js',
51 'mnemonist/queue.js',
e7aeea18 52 'mongodb',
01f4001e 53 'node:async_hooks',
0c7370da 54 'node:crypto',
942f9727 55 'node:events',
130783a7 56 'node:fs',
01f4001e 57 'node:http',
130783a7 58 'node:path',
01f4001e 59 'node:perf_hooks',
8a168938 60 'node:stream',
130783a7 61 'node:url',
0c7370da 62 'node:util',
01f4001e 63 'node:worker_threads',
e7aeea18 64 'poolifier',
e7aeea18 65 'tar',
e3018bc4 66 'winston',
e7aeea18 67 'winston-daily-rotate-file',
b768993d 68 'winston/lib/winston/transports/index.js',
e3018bc4 69 'ws',
e7aeea18 70 ],
44b07a21 71 plugins: [
84e52c2c 72 json(),
8b6da988 73 typescript({
0f454015 74 tsconfig: 'tsconfig.json',
c98873ea
JB
75 compilerOptions: {
76 sourceMap: !!isDevelopmentBuild,
77 },
44b07a21
JB
78 }),
79 del({
045639f5
JB
80 targets: [
81 'dist/*',
82 '!dist/assets',
83 'dist/assets/*.json',
045639f5 84 'dist/assets/json-schemas',
0c995ea6
JB
85 'dist/assets/station-templates',
86 'dist/assets/ui-protocol',
045639f5 87 ],
c4a19794
JB
88 }),
89 copy({
672551ed
JB
90 rootDir: 'src',
91 patterns: 'assets/**/*.json',
92 exclude: [
93 'assets/config-template.json',
70b77dcd 94 'assets/*config[-_.]*.json',
672551ed 95 'assets/idtags-template.json',
5d1a7b7d 96 'assets/authorization-tags-template.json',
672551ed
JB
97 'assets/ui-protocol/**/*',
98 ],
cb1948a3 99 }),
51022aa0 100 isAnalyzeBuild && analyze(),
e7aeea18 101 ],
44b07a21 102};