refactor: use classic setter in configuration class
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
index 7f0e577421bfea9af77707e0ddb060b63ebd55a5..c28aaf0460dd35fa7100ffffcba00c60c3c5b978 100644 (file)
+/* eslint-disable n/no-unpublished-import */
+import * as os from 'node:os';
+
+import json from '@rollup/plugin-json';
+import terser from '@rollup/plugin-terser';
+import typescript from '@rollup/plugin-typescript';
+import { copy } from '@web/rollup-plugin-copy';
+import { defineConfig } from 'rollup';
 import analyze from 'rollup-plugin-analyzer';
-import copy from 'rollup-plugin-copy';
 import del from 'rollup-plugin-delete';
-import istanbul from 'rollup-plugin-istanbul';
-import json from '@rollup/plugin-json';
-import { terser } from 'rollup-plugin-terser';
-import ts from 'rollup-plugin-ts';
+
+const availableParallelism = () => {
+  // eslint-disable-next-line no-shadow
+  let availableParallelism = 1;
+  try {
+    availableParallelism = os.availableParallelism();
+  } catch {
+    const cpus = os.cpus();
+    if (Array.isArray(cpus) && cpus.length > 0) {
+      availableParallelism = cpus.length;
+    }
+  }
+  return availableParallelism;
+};
 
 const isDevelopmentBuild = process.env.BUILD === 'development';
+const isAnalyzeBuild = process.env.ANALYZE;
+const sourceMap = !!isDevelopmentBuild;
 
-export default {
-  input: ['src/start.ts', 'src/ui/httpd/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
-  output: {
-    dir: 'dist',
-    format: 'cjs',
-    exports: 'auto',
-    sourcemap: true,
-    preserveModules: true,
-    preserveModulesRoot: 'src',
-    ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }),
-  },
+export default defineConfig({
+  input: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'],
+  strictDeprecations: true,
+  output: [
+    {
+      dir: './dist',
+      format: 'esm',
+      sourcemap: sourceMap,
+      plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
+    },
+  ],
   external: [
-    'basic-ftp',
-    'chalk',
-    'crypto',
-    'express',
-    'fs',
     '@mikro-orm/core',
     '@mikro-orm/reflection',
-    'mnemonist/lru-map-with-delete',
-    'moment',
+    'ajv',
+    'ajv-formats',
+    'basic-ftp',
+    'chalk',
+    'date-fns',
+    'deep-clone',
+    'http-status-codes',
+    'just-merge',
+    'mnemonist/lru-map-with-delete.js',
+    'mnemonist/queue.js',
     'mongodb',
-    'path',
-    'perf_hooks',
+    'node:async_hooks',
+    'node:crypto',
+    'node:events',
+    'node:fs',
+    'node:http',
+    'node:http2',
+    'node:path',
+    'node:perf_hooks',
+    'node:stream',
+    'node:url',
+    'node:util',
+    'node:worker_threads',
     'poolifier',
-    'proper-lockfile',
-    'reflect-metadata',
     'tar',
-    'url',
-    'uuid',
-    'ws',
+    'winston',
     'winston-daily-rotate-file',
     'winston/lib/winston/transports/index.js',
-    'winston',
-    'worker_threads',
+    'ws',
   ],
   plugins: [
     json(),
-    ts({
-      tsconfig: 'tsconfig.json',
-      browserslist: false,
+    typescript({
+      tsconfig: './tsconfig.json',
+      compilerOptions: {
+        sourceMap,
+      },
     }),
-    isDevelopmentBuild && istanbul(),
     del({
-      targets: ['dist/*', '!dist/assets', 'dist/assets/*.json', 'dist/assets/station-templates'],
+      targets: [
+        './dist/*',
+        '!./dist/assets',
+        './dist/assets/*.json',
+        './dist/assets/json-schemas',
+        './dist/assets/station-templates',
+        './dist/assets/ui-protocol',
+      ],
     }),
     copy({
-      targets: [{ src: 'src/assets', dest: 'dist/' }],
+      rootDir: './src',
+      patterns: 'assets/**/*.json',
+      exclude: [
+        'assets/config-template.json',
+        'assets/*config[-_.]*.json',
+        'assets/idtags-template.json',
+        'assets/authorization-tags-template.json',
+        'assets/ui-protocol/**/*',
+      ],
     }),
-    isDevelopmentBuild && analyze(),
+    isAnalyzeBuild && analyze(),
   ],
-};
+});