UNPKG

chicago

Version:

A front-end JavaScript library for user-interface developers.

166 lines (142 loc) 3.89 kB
module.exports = function( grunt ) { var newVersion; grunt.registerTask('update-version', 'Publishes the package to npm', function() { var pkg = grunt.config('pkg'), version = pkg.version, array = version.split('.'); for( var i = 0; i < array.length; i++ ) { array[i] = parseInt( array[i] ); } if( array[2] < 9 ) { array[2]++; } else { array[2] = 0; if( array[1] < 9 ) { array[1]++; } else { array[1] = 0; array[0]++; } } newVersion = array.join('.'); // replace in package.json var pkgContent = grunt.file.read( 'package.json' ).replace( '"version": "' + version + '"', '"version": "' + newVersion + '"' ); grunt.file.write( 'package.json', pkgContent ); // replace in bower.json var bowerContent = grunt.file.read( 'bower.json' ).replace( '"version" : "' + version + '"', '"version" : "' + newVersion + '"' ); grunt.file.write( 'bower.json', bowerContent ); // replace in dist files grunt.file.recurse('dist', function(abspath, rootdir, subdir, filename) { var content = grunt.file.read( abspath ), rgx = new RegExp( 'Version: ' + version, 'g' ); content = content.replace( rgx, 'Version: ' + newVersion ); grunt.file.write( abspath, content ); }); var done = this.async(); // git add // grunt.util.spawn({ // cmd: 'git', // args: ['add', 'bower.json', 'package.json'] // }, function (error, data) { // if (error) { // grunt.log.error(error); // return done(false); // } // git commit grunt.util.spawn({ cmd: 'git', args: ['commit', '-am', 'Pushing latest bower.json and package.json files ahead of version ' + newVersion + ' publication.'] }, function (error, data) { if (error) { grunt.log.error(error); return done(false); } // git tag grunt.util.spawn({ cmd: 'git', args: ['tag', '-f', '-a', newVersion, '-m', 'Version ' + newVersion] }, function (error, data) { if (error) { grunt.log.error(error); return done(false); } // git push grunt.util.spawn({ cmd: 'git', args: ['push', 'origin', 'master', '--tags'] }, function (error, data) { if (error) { grunt.log.error(error); return done(false); } done(); }); }); }); // }); }); grunt.registerTask('npm-publish', 'Publishes the package to npm', function() { var done = this.async(); grunt.util.spawn({ cmd: 'npm', args: ['version', newVersion] }, function (error, data) { if (error) { // grunt.log.warn(error); grunt.log.error(error); return done(false); } grunt.util.spawn({ cmd: 'npm', args: ['publish'] }, function (error, data) { if (error) { // grunt.log.warn(error); grunt.log.error(error); return done(false); } grunt.log.writeln( data ); done(); }); }); }); grunt.registerTask('bower-publish', 'publishes the package to bower', function() { var done = this.async(); grunt.util.spawn({ cmd: 'bower', args: ['version', newVersion] }, function (error, data) { if (error) { grunt.log.error(error); return done(false); } done(); // grunt.util.spawn({ // cmd: 'bower', // args: ['register', 'Chicago', 'git://github.com/nielse63/Chicago.git'] // }, function (error, data) { // if (error) { // grunt.log.error(error); // return done(false); // } // grunt.log.writeln( data ); // done(); // }); }); }); grunt.registerTask('changelog', 'Auto-generates a changelog.', function() { var done = this.async(); grunt.util.spawn({ cmd: 'changelog', args: ['chicago', 'all', '-m'] }, function (error, data) { if (error) { grunt.log.error(error); return done(false); } grunt.file.write( 'CHANGELOG.md', data ); grunt.log.ok('Changelog created'); done(); }); }); };