[install.js][s]: add function to check package version

This commit is contained in:
steveoni 2020-11-25 12:43:58 +01:00
parent f3d4a9bb4c
commit 8f0cf2eab6

View File

@ -1,5 +1,7 @@
const spawn = require("cross-spawn");
const path = require("path");
const execSync = require('child_process').execSync;
const semver = require('semver');
/**
*
@ -36,4 +38,15 @@ async function initGit() {
spawn(`git`, [`init`, `-q`]);
}
module.exports = { install, initGit };
/**
* Check the version for npm and Yarn
* @param {*} pname
* @returns Boolean
*/
function checkPackageVersion(pname){
let userVersion = execSync(`${pname} --version`).toString();
let expectedVersion = pname === 'yarn' ? '1.22.10' : '6.14.5';
return !semver.lt(userVersion,expectedVersion)
}
module.exports = { install, initGit, checkPackageVersion };