Skip to content

Instantly share code, notes, and snippets.

@jeremija
Created April 27, 2017 19:19
Show Gist options
  • Save jeremija/c1a284ab42ac80c5aaf62af7b8cd7525 to your computer and use it in GitHub Desktop.
Save jeremija/c1a284ab42ac80c5aaf62af7b8cd7525 to your computer and use it in GitHub Desktop.
update node deps
'use strict';
const pkg = require('./package.json');
const _ = require('underscore');
const fs = require('fs');
const deps = {};
fs.readFileSync('./deps').toString().split('\n').forEach(row => {
row = row.split('@');
deps[row[0]] = row[1];
});
const dependencies = _.mapObject(pkg.dependencies, (value, dep) => {
if (value.startsWith('git+')) return value;
return deps[dep];
});
const devDependencies = _.mapObject(pkg.devDependencies, (value, dep) => {
if (dep.startsWith('git+')) return value;
return deps[dep];
});
pkg.dependencies = dependencies;
pkg.devDependencies = devDependencies;
const json = JSON.stringify(pkg, null, ' ');
fs.writeFileSync('package2.json', json);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment