X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=build-requirements.js;h=c92b20953402121217bb38ed224222498cac1852;hb=HEAD;hp=7f36a4876c4ade6c23e0aa8548c2cb5c8be97527;hpb=67623aa62669b072125219bb51cb46321a7342a9;p=e-mobility-charging-stations-simulator.git diff --git a/build-requirements.js b/build-requirements.js index 7f36a487..501933c4 100644 --- a/build-requirements.js +++ b/build-requirements.js @@ -1,24 +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' + +const packageJson = JSON.parse(readFileSync('./package.json', 'utf8')) /** - * + * Check if the current node version match the required engines version. */ -function checkNodeVersion() { - if (SemVer.satisfies(process.version, enginesNodeVersion) === false) { +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 ${process.version}.` + `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(); - -module.exports = { checkNodeVersion }; +checkNodeVersion()