EvanLovely
12/29/2015 - 8:55 PM

Check if an installed node dependency is up to date; if not: update it.

Check if an installed node dependency is up to date; if not: update it.

Dependency Version Checker

Run this before your start script to update crucial dependencies. To use:

  1. Update your package.json with stuff
  2. Replace uses of p2-theme-core in JS file with your crucial deps.
  3. Ensure devs enter into your app/site with 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'}));
}