-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log an error if node version is smaller than 17.0.0
- Loading branch information
1 parent
2daac55
commit 1396515
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
/** | ||
* Asserts that a certain node version is installed on the executing machine. | ||
* Exits the process if this prerequisite is not fulfilled. | ||
*/ | ||
export function assertNodeVersion() { | ||
const requiredNodeMajorVersion = 17; | ||
const currentNodeMajorVersion = getNodeMajorVersion(); | ||
|
||
if (currentNodeMajorVersion < requiredNodeMajorVersion) { | ||
console.error( | ||
`Jayvee requires node version ${requiredNodeMajorVersion}.0.0 or higher.`, | ||
); | ||
console.info( | ||
`Your current node version is ${currentNodeMajorVersion} - please upgrade!`, | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the node version of the executing machine. | ||
* Exits the process if no node process is running. | ||
*/ | ||
function getNodeMajorVersion(): number { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
const nodeVersion = process?.versions?.node; | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (nodeVersion === undefined) { | ||
console.error('Could not find a nodejs runtime.'); | ||
process.exit(1); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return +nodeVersion.split('.')[0]!; | ||
} |