Check if an installed node dependency is up to date; if not: update it.
Run this before your start script to update crucial dependencies. To use:
package.json
with stuffp2-theme-core
in JS file with your crucial deps.npm start
.I realize this could be expanded to check all deps or multiple ones, but just wanted to put this out for others.
{
"scripts": {
"prestart": "npm run checkDeps",
"start": "echo 'Start your stuff here' ",
"checkDeps": "node scripts/dependency-version-checker.js"
},
"devDependencies": {
"semver": "^5.1.0"
}
}
#!/usr/bin/env node
var semver = require('semver');
var requiredVer = require('../package.json').devDependencies['p2-theme-core'];
var installedVer = require('p2-theme-core/package.json').version;
//console.log('requiredVer', requiredVer);
//console.log('installedVer', installedVer);
if (! semver.satisfies(installedVer, requiredVer)) {
console.log('Installed version of "p2-theme-core" is old; updating...');
var exec = require('child_process').execSync;
console.log(exec('npm install', {encoding: 'utf8'}));
}