Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
resolved node version checking bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Khalid committed Jan 24, 2019
1 parent d457f55 commit 743b8eb
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions check-version.js
@@ -1,20 +1,50 @@

const exec = require('child_process').exec;

exec("npm install semver",(error,stdout, stderr) => {
if(error){
console.log(error);
}else{
const package = require('./package.json')

const package = require('./package.json')
semver = require('semver');
const current_version = `${process.version.substr(1,process.version.length)}`,
expected_version = `${package.engines.node.substr(2,package.engines.node.length)}`;

const current_version = `${process.version.substr(1,process.version.length)}`,
expected_version = `${package.engines.node.substr(2,package.engines.node.length)}`;
if(!compare(current_version,expected_version)){
console.error(`Node 8.10.0 or later is required.`);
process.exit(1);
}

if(!semver.gte(current_version,expected_version)){
console.error(`Node 8.10.0 or later is required.`);
process.exit(1);
// comparing node version
function compare(a, b) {
if (a === b) {
return true;
}

var a_components = a.split(".");
var b_components = b.split(".");

var len = Math.min(a_components.length, b_components.length);

// loop while the components are equal
for (var i = 0; i < len; i++) {
// A bigger than B
if (parseInt(a_components[i]) > parseInt(b_components[i])) {
return true;
}

// B bigger than A
if (parseInt(a_components[i]) < parseInt(b_components[i])) {
return false;
}
}
});

// If one's a prefix of the other, the longer one is greater.
if (a_components.length >= b_components.length) {
return true;
}

if (a_components.length < b_components.length) {
return false;
}

// Otherwise they are the same.
return true;
}


0 comments on commit 743b8eb

Please sign in to comment.