Commit | Line | Data |
---|---|---|
66a7748d | 1 | import chalk from 'chalk' |
8f801a93 | 2 | import { satisfies } from 'semver' |
66a7748d | 3 | import { version, exit } from 'node:process' |
8fa6f565 JB |
4 | import { readFileSync } from 'node:fs' |
5 | ||
6 | const packageJson = JSON.parse(readFileSync('./package.json', 'utf8')) | |
1f7fa4de | 7 | |
67623aa6 | 8 | /** |
fc040c43 | 9 | * Check if the current node version match the required engines version. |
67623aa6 | 10 | */ |
1cee0015 | 11 | export const checkNodeVersion = () => { |
66a7748d | 12 | const enginesNodeVersion = packageJson.engines.node |
8f801a93 | 13 | if (satisfies(version, enginesNodeVersion) === false) { |
67623aa6 JB |
14 | console.error( |
15 | chalk.red( | |
412cece8 | 16 | `Required node version ${enginesNodeVersion} not satisfied with current version ${version}` |
66a7748d JB |
17 | ) |
18 | ) | |
ef85c95a | 19 | // eslint-disable-next-line n/no-process-exit |
66a7748d | 20 | exit(1) |
67623aa6 | 21 | } |
66a7748d | 22 | } |
67623aa6 | 23 | |
66a7748d | 24 | checkNodeVersion() |