X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=build-requirements.js;h=f73e3e89c642fbb315175cfd586e178108d8ac37;hb=314793aaf25bf1a99deb3f8209c09421235942ba;hp=ebcd5ef04680f340c030b7d84c2f1c7d70a13d52;hpb=1f7fa4de53a1b28324f362402f61b81b28d75c2c;p=e-mobility-charging-stations-simulator.git diff --git a/build-requirements.js b/build-requirements.js index ebcd5ef0..f73e3e89 100644 --- a/build-requirements.js +++ b/build-requirements.js @@ -1,15 +1,22 @@ -const chalk = require('chalk'); -// eslint-disable-next-line node/no-unpublished-require -const SemVer = require('semver'); +import chalk from 'chalk' +import { satisfies } from 'semver' +import packageJson from './package.json' assert { type: 'json' } +import { version, exit } from 'node:process' -const enginesNodeVersion = require('./package.json').engines.node; - -if (SemVer.satisfies(process.version, enginesNodeVersion) === false) { - console.error( - chalk.red( - `Required node version ${enginesNodeVersion} not satisfied with current version ${process.version}.` +/** + * 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()