Merge pull request #1048 from SAP/dependabot/github_actions/sonarsource/sonarcloud...
[e-mobility-charging-stations-simulator.git] / build-requirements.js
... / ...
CommitLineData
1import { readFileSync } from 'node:fs'
2import { exit, version } from 'node:process'
3
4import chalk from 'chalk'
5// eslint-disable-next-line n/no-unpublished-import
6import { satisfies } from 'semver'
7
8const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'))
9
10/**
11 * Check if the current node version match the required engines version.
12 */
13export const checkNodeVersion = () => {
14 const enginesNodeVersion = packageJson.engines.node
15 if (satisfies(version, enginesNodeVersion) === false) {
16 console.error(
17 chalk.red(
18 `Required node version ${enginesNodeVersion} not satisfied with current version ${version}`
19 )
20 )
21 // eslint-disable-next-line n/no-process-exit
22 exit(1)
23 }
24}
25
26checkNodeVersion()