From 301d6fdc5bd45696cc803cbb9e03d017efcbe874 Mon Sep 17 00:00:00 2001 From: Baris Aydinoglu Date: Thu, 3 Sep 2015 01:52:33 +0300 Subject: [PATCH] release tasks --- .bowerrc | 3 -- Gruntfile.js | 9 ++++ build/release.js | 56 -------------------- build/release/cdn.js | 115 ------------------------------------------ build/release/dist.js | 109 --------------------------------------- package.json | 1 + 6 files changed, 10 insertions(+), 283 deletions(-) delete mode 100644 .bowerrc delete mode 100644 build/release.js delete mode 100644 build/release/cdn.js delete mode 100644 build/release/dist.js diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 69fad35..0000000 --- a/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "bower_components" -} diff --git a/Gruntfile.js b/Gruntfile.js index 4df7f19..03889bf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -113,6 +113,15 @@ module.exports = function(grunt) { } } } + }, + "release-it": { + options: { + pkgFiles: ["package.json"], + commitMessage: "Release %s", + tagName: "%s", + tagAnnotation: "Release %s", + buildCommand: false + } } }); diff --git a/build/release.js b/build/release.js deleted file mode 100644 index 1402e55..0000000 --- a/build/release.js +++ /dev/null @@ -1,56 +0,0 @@ -module.exports = function( Release ) { - var - files = [ "dist/detectizr.js", "dist/detectizr.min.js", "dist/detectizr.min.map" ], - cdn = require( "./release/cdn" ), - dist = require( "./release/dist" ), - ensureSizzle = require( "./release/ensure-sizzle" ), - npmTags = Release.npmTags; - - Release.define({ - npmPublish: true, - issueTracker: "github", - /** - * Ensure the repo is in a proper state before release - * @param {Function} callback - */ - checkRepoState: function( callback ) { - ensureSizzle( Release, callback ); - }, - /** - * Generates any release artifacts that should be included in the release. - * The callback must be invoked with an array of files that should be - * committed before creating the tag. - * @param {Function} callback - */ - generateArtifacts: function( callback ) { - Release.exec( "grunt", "Grunt command failed" ); - cdn.makeReleaseCopies( Release ); - callback( files ); - }, - /** - * Acts as insertion point for restoring Release.dir.repo - * It was changed to reuse npm publish code in detectizr-release - * for publishing the distribution repo instead - */ - npmTags: function() { - // origRepo is not defined if dist was skipped - Release.dir.repo = Release.dir.origRepo || Release.dir.repo; - return npmTags(); - }, - /** - * Publish to distribution repo and npm - * @param {Function} callback - */ - dist: function( callback ) { - cdn.makeArchives( Release, function() { - dist( Release, callback ); - }); - } - }); -}; - -module.exports.dependencies = [ - "archiver@0.14.2", - "shelljs@0.2.6", - "npm@2.3.0" -]; diff --git a/build/release/cdn.js b/build/release/cdn.js deleted file mode 100644 index 583f0a8..0000000 --- a/build/release/cdn.js +++ /dev/null @@ -1,115 +0,0 @@ -var - fs = require( "fs" ), - shell = require( "shelljs" ), - path = require( "path" ), - - cdnFolder = "dist/cdn", - - devFile = "dist/detectizr.js", - minFile = "dist/detectizr.min.js", - mapFile = "dist/detectizr.min.map", - - releaseFiles = { - "detectizr-VER.js": devFile, - "detectizr-VER.min.js": minFile, - "detectizr-VER.min.map": mapFile - }, - - googleFilesCDN = [ - "detectizr.js", "detectizr.min.js", "detectizr.min.map" - ], - - msFilesCDN = [ - "detectizr-VER.js", "detectizr-VER.min.js", "detectizr-VER.min.map" - ]; - -/** - * Generates copies for the CDNs - */ -function makeReleaseCopies( Release ) { - shell.mkdir( "-p", cdnFolder ); - - Object.keys( releaseFiles ).forEach(function( key ) { - var text, - builtFile = releaseFiles[ key ], - unpathedFile = key.replace( /VER/g, Release.newVersion ), - releaseFile = cdnFolder + "/" + unpathedFile; - - if ( /\.map$/.test( releaseFile ) ) { - // Map files need to reference the new uncompressed name; - // assume that all files reside in the same directory. - // "file":"detectizr.min.js","sources":["detectizr.js"] - text = fs.readFileSync( builtFile, "utf8" ) - .replace( /"file":"([^"]+)","sources":\["([^"]+)"\]/, - "\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js" ) + - "\",\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" ); - fs.writeFileSync( releaseFile, text ); - } else if ( builtFile !== releaseFile ) { - shell.cp( "-f", builtFile, releaseFile ); - } - }); -} - -function makeArchives( Release, callback ) { - - Release.chdir( Release.dir.repo ); - - function makeArchive( cdn, files, callback ) { - if ( Release.preRelease ) { - console.log( "Skipping archive creation for " + cdn + "; this is a beta release." ); - callback(); - return; - } - - console.log( "Creating production archive for " + cdn ); - - var sum, - archiver = require( "archiver" )( "zip" ), - md5file = cdnFolder + "/" + cdn + "-md5.txt", - output = fs.createWriteStream( - cdnFolder + "/" + cdn + "-detectizr-" + Release.newVersion + ".zip" - ), - rver = /VER/; - - output.on( "close", callback ); - - output.on( "error", function( err ) { - throw err; - }); - - archiver.pipe( output ); - - files = files.map(function( item ) { - return "dist" + ( rver.test( item ) ? "/cdn" : "" ) + "/" + - item.replace( rver, Release.newVersion ); - }); - - sum = Release.exec( "md5sum " + files.join( " " ), "Error retrieving md5sum" ); - fs.writeFileSync( md5file, sum ); - files.push( md5file ); - - files.forEach(function( file ) { - archiver.append( fs.createReadStream( file ), - { name: path.basename( file ) } ); - }); - - archiver.finalize(); - } - - function buildGoogleCDN( callback ) { - makeArchive( "googlecdn", googleFilesCDN, callback ); - } - - function buildMicrosoftCDN( callback ) { - makeArchive( "mscdn", msFilesCDN, callback ); - } - - buildGoogleCDN(function() { - buildMicrosoftCDN( callback ); - }); -} - -module.exports = { - makeReleaseCopies: makeReleaseCopies, - makeArchives: makeArchives -}; diff --git a/build/release/dist.js b/build/release/dist.js deleted file mode 100644 index fee9e53..0000000 --- a/build/release/dist.js +++ /dev/null @@ -1,109 +0,0 @@ -module.exports = function( Release, complete ) { - var fs = require( "fs" ), - shell = require( "shelljs" ), - pkg = require( Release.dir.repo + "/package.json" ), - distRemote = Release.remote.replace("detectizr.git", "detectizr-dist.git"), - // These files are included with the distribution - files = [ - "src", - "LICENSE.txt", - "AUTHORS.txt", - "package.json" - ]; - - /** - * Clone the distribution repo - */ - function clone() { - Release.chdir( Release.dir.base ); - Release.dir.dist = Release.dir.base + "/dist"; - - console.log( "Using distribution repo: ", distRemote ); - Release.exec( "git clone " + distRemote + " " + Release.dir.dist, - "Error cloning repo." ); - - // Distribution always works on master - Release.chdir( Release.dir.dist ); - Release.exec( "git checkout master", "Error checking out branch." ); - console.log(); - } - - /** - * Generate bower file for detectizr-dist - */ - function generateBower() { - return JSON.stringify({ - name: pkg.name, - main: pkg.main, - license: "MIT", - ignore: [ - "package.json" - ], - keywords: pkg.keywords - }, null, 2); - } - - /** - * Copy necessary files over to the dist repo - */ - function copy() { - - // Copy dist files - var distFolder = Release.dir.dist + "/dist"; - shell.mkdir( "-p", distFolder ); - [ - "dist/detectizr.js", - "dist/detectizr.min.js", - "dist/detectizr.min.map" - ].forEach(function( file ) { - shell.cp( Release.dir.repo + "/" + file, distFolder ); - }); - - // Copy other files - files.forEach(function( file ) { - shell.cp( "-r", Release.dir.repo + "/" + file, Release.dir.dist ); - }); - - // Write generated bower file - fs.writeFileSync( Release.dir.dist + "/bower.json", generateBower() ); - - console.log( "Adding files to dist..." ); - Release.exec( "git add .", "Error adding files." ); - Release.exec( - "git commit -m 'Release " + Release.newVersion + "'", - "Error commiting files." - ); - console.log(); - - console.log( "Tagging release on dist..." ); - Release.exec( "git tag " + Release.newVersion, - "Error tagging " + Release.newVersion + " on dist repo." ); - Release.tagTime = Release.exec( "git log -1 --format='%ad'", - "Error getting tag timestamp." ).trim(); - } - - /** - * Push files to dist repo - */ - function push() { - Release.chdir( Release.dir.dist ); - - console.log( "Pushing release to dist repo..." ); - Release.exec( "git push " + distRemote + " master --tags", - "Error pushing master and tags to git repo." ); - - // Set repo for npm publish - Release.dir.origRepo = Release.dir.repo; - Release.dir.repo = Release.dir.dist; - } - - Release.walk( [ - Release._section( "Copy files to distribution repo" ), - clone, - copy, - Release.confirmReview, - - Release._section( "Pushing files to distribution repo" ), - push - ], complete ); -}; diff --git a/package.json b/package.json index d3997c5..3cb7f28 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "grunt-jscs": "2.1.0", "grunt-jsonlint": "1.0.4", "grunt-npmcopy": "0.1.0", + "grunt-release-it": "0.2.1", "gzip-js": "0.3.2", "load-grunt-tasks": "3.2.0", "qunitjs": "1.17.1",