From 6c034a568facb240fb18938d6465f247c4792898 Mon Sep 17 00:00:00 2001 From: Evo <85353424+EvolutionX-10@users.noreply.github.com> Date: Fri, 22 Jul 2022 19:22:54 +0530 Subject: [PATCH] refactor(init): improve node version check (#63) --- src/commands/init.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/commands/init.js b/src/commands/init.js index fd2f09c..3dd2ebe 100644 --- a/src/commands/init.js +++ b/src/commands/init.js @@ -24,11 +24,15 @@ const { prompt } = prompts; */ export async function init(flags) { // * Check if node version is valid - const node = await execa('node', ['--version']); - if (/v1(([0-6]\.[2-9])|([0-5]\.[0-9]))/gm.test(node.stdout)) { + const { version } = process; + const [major, minor] = version.split('.'); + const majorNum = parseInt(major.slice(1)); + const minorNum = parseInt(minor); + + if (majorNum < 16 || (majorNum === 16 && minorNum < 10)) { console.log( yellowBright( - `\nYou are using Node ${node.stdout}\nPlease upgrade to Node 16.10.x or higher!\n` + `\nYou are using Node ${version}\nPlease upgrade to Node 16.10.x or higher!\n` ) );