Skip to content

Commit

Permalink
Added build/release automation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
asciidisco committed Aug 20, 2013
1 parent 8492829 commit 92e2b6c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
94 changes: 94 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ module.exports = function(grunt) {
}
},

// up version, tag & commit
bump: {
options: {
files: ['package.json'],
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json'],
createTag: true,
tagName: '%VERSION%',
tagMessage: '%VERSION%',
push: true
}
},

// compress artifacts
compress: {
main: {
Expand Down Expand Up @@ -204,6 +218,85 @@ module.exports = function(grunt) {
}
});

// releases a new canary build
grunt.registerTask('release-canary', function () {
var done = this.async();
var pkg = grunt.config.get('pkg');
var canaryPkg = grunt.util._.clone(pkg);

Object.keys(canaryPkg.dependencies).forEach(function (pack) {
if (pack.search('dalek') !== -1) {
delete canaryPkg.dependencies[pack];
canaryPkg.dependencies[pack + '-canary'] = 'latest';
}
});

canaryPkg.name = canaryPkg.name + '-canary';
canaryPkg.version = canaryPkg.version + '-' + grunt.template.today('yyyy-mm-dd-HH-MM-ss');

grunt.file.write('package.json', JSON.stringify(canaryPkg, true, 2));

var npm = require('npm');
npm.load({}, function() {
npm.registry.adduser(process.env.npmuser, process.env.npmpass, process.env.npmmail, function(err) {
if (err) {
grunt.log.error(err);
grunt.file.write('package.json', JSON.stringify(pkg, true, 2));
done(false);
} else {
npm.config.set('email', process.env.npmmail, 'user');
npm.commands.publish([], function(err) {
grunt.file.write('package.json', JSON.stringify(pkg, true, 2));
grunt.log.ok('Published canary build to registry');
done(!err);
});
}
});
});
});

// release a new version
grunt.registerTask('release-package', function () {
var done = this.async();
var http = require('http');
var pkg = grunt.config.get('pkg');
var body = '';

http.get('http://registry.npmjs.org/' + pkg.name, function(res) {
res.on('data', function (data) {
body += data;
});

res.on('end', function () {
var versions = grunt.util._.pluck(JSON.parse(body).versions, 'version');
var currVersion = parseInt(pkg.version.replace(/\./gi, ''), 10);
var availableVersions = versions.map(function (version) {
return parseInt(version.replace(/\./gi, ''), 10);
});

if (!grunt.util._.contains(availableVersions, currVersion)) {
var npm = require('npm');
npm.load({}, function() {
npm.registry.adduser(process.env.npmuser, process.env.npmpass, process.env.npmmail, function(err) {
if (err) {
grunt.log.error(err);
done(false);
} else {
npm.config.set('email', process.env.npmmail, 'user');
npm.commands.publish([], function(err) {
grunt.log.ok('Released new version: ', pkg.version);
done(!err);
});
}
});
});
} else {
done();
}
});
});
});

// load 3rd party tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
Expand All @@ -212,6 +305,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-complexity');
grunt.loadNpmTasks('grunt-plato');
grunt.loadNpmTasks('grunt-bump');

// define runner tasks
grunt.registerTask('lint', 'jshint');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"grunt-complexity": "~0.1.3",
"grunt-plato": "~0.2.1",
"grunt-include-replace": "~1.1.0",
"grunt-bump": "~0.0.11",
"blanket": "~1.1.5",
"chai": "~1.7.2"
},
Expand Down

0 comments on commit 92e2b6c

Please sign in to comment.