Created
August 8, 2015 06:47
-
-
Save okunishinishi/47668dd147b5e3f1d63c to your computer and use it in GitHub Desktop.
package.jsonのdependenciesを自動更新するスクリプトを書く ref: http://qiita.com/okunishinishi@github/items/7629b58d1c3d464738dc
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
"dependencies":{ | |
"async":"*", | |
"glob":"latest" | |
} |
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
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) { | |
/**...**/ | |
}); |
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
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); | |
}); |
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
$ npm install ape-updating --save-dev |
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 | |
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