build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / build-requirements.js
index ebcd5ef04680f340c030b7d84c2f1c7d70a13d52..501933c4fa5ae659809f3ab8f96f13f710d4caa4 100644 (file)
@@ -1,15 +1,26 @@
-const chalk = require('chalk');
-// eslint-disable-next-line node/no-unpublished-require
-const SemVer = require('semver');
+import { readFileSync } from 'node:fs'
+import { exit, version } from 'node:process'
 
-const enginesNodeVersion = require('./package.json').engines.node;
+import chalk from 'chalk'
+// eslint-disable-next-line n/no-unpublished-import
+import { satisfies } from 'semver'
 
-if (SemVer.satisfies(process.version, enginesNodeVersion) === false) {
-  console.error(
-    chalk.red(
-      `Required node version ${enginesNodeVersion} not satisfied with current version ${process.version}.`
+const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'))
+
+/**
+ * Check if the current node version match the required engines version.
+ */
+export const checkNodeVersion = () => {
+  const enginesNodeVersion = packageJson.engines.node
+  if (satisfies(version, enginesNodeVersion) === false) {
+    console.error(
+      chalk.red(
+        `Required node version ${enginesNodeVersion} not satisfied with current version ${version}`
+      )
     )
-  );
-  // eslint-disable-next-line no-process-exit
-  process.exit(1);
+    // eslint-disable-next-line n/no-process-exit
+    exit(1)
+  }
 }
+
+checkNodeVersion()