diff --git a/javascript/packages/cli/src/cli.ts b/javascript/packages/cli/src/cli.ts index b3c573cb7..75c8e38cb 100644 --- a/javascript/packages/cli/src/cli.ts +++ b/javascript/packages/cli/src/cli.ts @@ -6,6 +6,7 @@ import { convert } from "./actions/convert"; import { setup } from "./actions/setup"; import { spawn } from "./actions/spawn"; import { test } from "./actions/test"; +import { checkNodeVersion } from "./versionCheck"; const debug = require("debug")("zombie-cli"); @@ -18,6 +19,8 @@ const setGlobalNetwork = (globalNetwork: Network) => { network = globalNetwork; }; +checkNodeVersion(); + async function handleTermination(userInterrupted = false) { process.env.terminating = "1"; if (network && !alreadyTryToStop) { diff --git a/javascript/packages/cli/src/versionCheck.ts b/javascript/packages/cli/src/versionCheck.ts new file mode 100644 index 000000000..966d629fe --- /dev/null +++ b/javascript/packages/cli/src/versionCheck.ts @@ -0,0 +1,24 @@ +import { decorators } from "@zombienet/utils"; + +export const checkNodeVersion = () => { + const nodeVersion = process.versions.node; + const requiredNodeVersion = getPackageNodeVersion(); + if ( + parseInt(nodeVersion.split(".")[0]) < + parseInt(requiredNodeVersion.split(".")[0]) + ) { + console.error( + `\n${decorators.red("Error: ")} \t ${decorators.bright( + `Node version ${nodeVersion} is not supported. Please update to Node ${requiredNodeVersion} or above.`, + )}\n`, + ); + process.exit(1); + } +}; + +const getPackageNodeVersion = () => { + const { + engines: { node }, + } = require("../package.json"); + return node.replace(/>=\s*/, ""); +};