Last active
August 29, 2015 14:05
-
-
Save Elzair/bd68c460304eafe5fd12 to your computer and use it in GitHub Desktop.
Update Angular Modules
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/local/bin/node --harmony | |
var co = require('co') | |
, fs = require('co-fs') | |
, request = require('request') | |
, spawn = require('co-child-process') | |
, thunkify = require('thunkify') | |
, util = require('util') | |
; | |
var base_dir = process.env['HOME'] + '/Development/Nodejs/'; | |
var files = [ | |
['angular-module-animate', 'angular-animate'] | |
, ['angular-module-aria', 'angular-aria'] | |
, ['angular-module-cookies', 'angular-cookies'] | |
, ['angular-module-core', 'angular'] | |
, ['angular-module-loader', 'angular-loader'] | |
, ['angular-module-messages', 'angular-messages'] | |
, ['angular-module-resource', 'angular-resource'] | |
, ['angular-module-route', 'angular-route'] | |
, ['angular-module-sanitize', 'angular-sanitize'] | |
, ['angular-module-touch', 'angular-touch'] | |
]; | |
co(function *() { | |
// Get new version number and make sure it is a valid semver | |
var version = process.argv[2]; | |
if (!/^\d+\.\d+\.\d+$/.exec(version)) { | |
console.error('Version number must have the form x.y.z!'); | |
} | |
try { | |
for (var i=0; i<files.length; i++) { | |
var cwd = base_dir + files[i][0]; | |
// Update repo to latest version | |
yield spawn('git', ['pull'], {cwd: cwd}); | |
console.log(util.format('Got remote changes for %s', files[i][0])); | |
// Fetch latest version of file | |
var url = util.format('https://ajax.googleapis.com/ajax/libs/angularjs/%s/%s.min.js', version, files[i][1]); | |
console.log(util.format('Fetching %s', url)); | |
var file = yield thunkify(request.get)(url); | |
yield fs.writeFile(util.format('%s/%s.js', cwd, files[i][1]), file[1]); | |
// Update package.json to latest version | |
var pkg_json = JSON.parse(yield fs.readFile(util.format('%s/package.json', cwd), {encoding: 'utf8'})); | |
pkg_json.version = version; | |
yield fs.writeFile(util.format('%s/package.json', cwd), JSON.stringify(pkg_json, null, 2)); | |
console.log('package.json for %s updated to %s', files[i][0], version); | |
// Commit changes | |
yield spawn('git', ['add', 'package.json', util.format('%s.js', files[i][1])], {cwd: cwd}); | |
yield spawn('git', ["commit", "-m", util.format("Updated to version v%s", version)], {cwd: cwd}); | |
// Create new tag | |
yield spawn('git', ['tag', util.format('v%s', version)], {cwd: cwd}); | |
yield spawn('git', ['push'], {cwd: cwd}); | |
yield spawn('git', ['push', 'origin', util.format('v%s', version)], {cwd: cwd}); | |
// Publish module | |
yield spawn('npm', ['publish'], {cwd: cwd}); | |
console.log(util.format('%s updated!', files[i][0])); | |
} | |
} | |
catch (e) { | |
console.error(JSON.stringify(e, null, 2)); | |
process.exit(1); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment