Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
package.json node version update (#263)
Browse files Browse the repository at this point in the history
* updated version check script to use regex, updated package.json to require node version 16+

Co-authored-by: Daniel Cheng <[email protected]>
  • Loading branch information
MrDSGC and Daniel Cheng authored Jul 12, 2022
1 parent e2a5c91 commit 74b0b58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
16 changes: 12 additions & 4 deletions .ki-scripts/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,20 @@ pm2.connect(false, async function (err) {
// ------------------------------------------------------------
// ------------- CHECK FOR CORRECT NODE VERSION ---------------

if (
!process.version.split(".")[0].includes(pjson.engines.node.split(".")[0])
) {
const parseVersion = (nodeVersionString) => {
const majorVersion = nodeVersionString.split(".")[0];
const majorVersionIntOnly = majorVersion.replace(/[^0-9]/g,"");

return parseInt(majorVersionIntOnly);
}

const processNodeVersion = parseVersion(process.version)
const engineNodeRequirement = parseVersion(pjson.engines.node);

if (processNodeVersion < engineNodeRequirement) {
spinner.warn(
`This project requires Node version ${chalk.yellow(
"16.x"
pjson.engines.node
)} or higher. Please install Node.js and try again.${"\n"}`
);
pm2.disconnect();
Expand Down
15 changes: 13 additions & 2 deletions .ki-scripts/version-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ import jetpack from "fs-jetpack";
import chalk from "chalk";

const pjson = jetpack.read("./package.json", "json");
const parseVersion = (nodeVersionString) => {
const majorVersion = nodeVersionString.split(".")[0];

if (!process.version.split(".")[0].includes(pjson.engines.node.split(".")[0])) {
// use regex to remove leading chars such as "v", "^", "<", ">", ""="
const majorVersionIntOnly = majorVersion.replace(/[^0-9]/g,"");

return parseInt(majorVersionIntOnly);
}

const processNodeVersion = parseVersion(process.version)
const engineNodeRequirement = parseVersion(pjson.engines.node);

if (processNodeVersion < engineNodeRequirement) {
console.log(
`This project requires Node version ${chalk.yellow(
pjson.engines.node
)} or higher. Please install Node.js and try again.${"\n"}`
);

process.exit(1);
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
},
"homepage": "https://github.com/onflow/kitty-items#readme",
"engines": {
"node": "16.x"
"node": ">=16.0.0"
}
}

0 comments on commit 74b0b58

Please sign in to comment.