Created
April 29, 2022 19:33
-
-
Save andygup/65eb8624195ffcc3527624f373f2ef4d to your computer and use it in GitHub Desktop.
Compare installed library version with the latest version on npm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const exec = require("util").promisify(require("child_process").exec); | |
/** | |
* Compare the installed version against the latest @next version | |
* @returns {{validate: boolean, nextRelease: string}} | |
*/ | |
const checkVersion = async (currentVersion) => { | |
let installedVersion, nextRelease, validate = false; | |
try { | |
installedVersion = ( | |
await exec( | |
"npm --prefix ../../esm-samples/jsapi-vue/ --json list @arcgis/core" | |
) | |
).stdout; | |
console.log(installedVersion); | |
const coreVersion = JSON.parse(installedVersion); | |
// HEADS-UP: This can return a false negative. For example, if node modules | |
// haven't been installed this will code block will never run. | |
if ("dependencies" in coreVersion) { | |
nextRelease = (await exec("npm view @arcgis/core@next version")).stdout; | |
const parsedInstalledVersion = | |
coreVersion["dependencies"]["@arcgis/core"]["version"]; | |
validate = | |
parsedInstalledVersion.trim() === nextRelease.trim() ? true : false; | |
console.log( | |
"Comparing installed version against @next: ", | |
parsedInstalledVersion + ", " + nextRelease + ", " + validate | |
); | |
} else { | |
console.log("There was a problem in finding @arcgis/core."); | |
} | |
} catch (err) { | |
console.error(err); | |
} | |
console.log("validate", validate); | |
return {validate,nextRelease}; | |
}; | |
module.exports = checkVersion; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment