Skip to content

Instantly share code, notes, and snippets.

@okunishinishi
Created August 8, 2015 06:47
Show Gist options
  • Save okunishinishi/47668dd147b5e3f1d63c to your computer and use it in GitHub Desktop.
Save okunishinishi/47668dd147b5e3f1d63c to your computer and use it in GitHub Desktop.
package.jsonのdependenciesを自動更新するスクリプトを書く ref: http://qiita.com/okunishinishi@github/items/7629b58d1c3d464738dc
"dependencies":{
"async":"*",
"glob":"latest"
}
var fs = require('fs'),
pkgPath = require.resolve('./package.json'),
pkg = require(pkgPath);
function _setAllProperty(obj, val) {
obj = obj || {};
Object.keys(obj).forEach(function (key) {
obj[key] = val;
});
return obj;
}
pkg['dependencies'] = _setAllProperty(pkg['dependencies'], '*');
pkg['devDependencies'] = _setAllProperty(pkg['devDependencies'], '*');
fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), function(err) {
/**...**/
});
var execcli = require('execcli'),
async = require('async');
async.series([
function (callback) {
var dependencyNames = Object.keys(pkg['dependencies']).sort();
var args = ['install'].concat(dependencyNames).concat(['--save']);
execcli('npm', args, {
cwd: path.dirname(pkgPath)
}, callback);
},
function (callback) {
var devDependencyNames = Object.keys(pkg['devDependencies']).sort();
var args = ['install'].concat(devDependencyNames).concat(['--save-dev']);
execcli('npm', args, {
cwd: path.dirname(pkgPath)
}, callback);
}
], function (err) {
callback(err);
});
$ npm install ape-updating --save-dev
#!/usr/bin/env node
var apeUpdating = require('ape-updating');
// Update all dependencies
apeUpdating(function (err) {
/*...*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment