From fc76a97b990508cc612c5cf805e62fc6e8bfae18 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Wed, 28 Jan 2015 11:37:29 -0800 Subject: [PATCH] Release: Distribute files to distribution repo Fixes gh-1869 Fixes gh-1673 Fixes gh-2045 Conflicts: bower.json build/release.js --- bower.json | 21 ---- build/release.js | 177 ++++++--------------------- build/release/cdn.js | 106 ++++++++++++++++ build/release/dist.js | 116 ++++++++++++++++++ build/{ => release}/ensure-sizzle.js | 5 +- build/{ => release}/release-notes.js | 0 package.json | 2 - 7 files changed, 264 insertions(+), 163 deletions(-) delete mode 100644 bower.json create mode 100644 build/release/cdn.js create mode 100644 build/release/dist.js rename build/{ => release}/ensure-sizzle.js (91%) rename build/{ => release}/release-notes.js (100%) diff --git a/bower.json b/bower.json deleted file mode 100644 index b08632b0a..000000000 --- a/bower.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "jquery-compat", - "version": "3.0.0-pre", - "main": "dist/jquery.js", - "license": "MIT", - "ignore": [ - "**/.*", - "build", - "speed", - "test", - "*.md", - "AUTHORS.txt", - "Gruntfile.js", - "package.json" - ], - "keywords": [ - "jquery", - "javascript", - "library" - ] -} diff --git a/build/release.js b/build/release.js index 56494a80e..d3206a956 100644 --- a/build/release.js +++ b/build/release.js @@ -1,116 +1,18 @@ + module.exports = function( Release ) { var - fs = require( "fs" ), - shell = require( "shelljs" ), - ensureSizzle = require( "./ensure-sizzle" ), - - devFile = "dist/jquery.js", - minFile = "dist/jquery.min.js", - mapFile = "dist/jquery.min.map", - - cdnFolder = "dist/cdn", - - releaseFiles = { - "jquery-VER.js": devFile, - "jquery-VER.min.js": minFile, - "jquery-VER.min.map": mapFile - }, - - googleFilesCDN = [ - "jquery.js", "jquery.min.js", "jquery.min.map" - ], - - msFilesCDN = [ - "jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map" - ], - - _complete = Release.complete; - - /** - * Generates copies for the CDNs - */ - function makeReleaseCopies() { - 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":"jquery.min.js","sources":["jquery.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 ( /\.min\.js$/.test( releaseFile ) ) { - // Remove the source map comment; it causes way too many problems. - // Keep the map file in case DevTools allow manual association. - text = fs.readFileSync( builtFile, "utf8" ) - .replace( /\/\/# sourceMappingURL=\S+/, "" ); - fs.writeFileSync( releaseFile, text ); - } else if ( builtFile !== releaseFile ) { - shell.cp( "-f", builtFile, releaseFile ); - } - }); - } - - function buildGoogleCDN() { - makeArchive( "googlecdn", googleFilesCDN ); - } - - function buildMicrosoftCDN() { - makeArchive( "mscdn", msFilesCDN ); - } - - function makeArchive( cdn, files ) { - if ( Release.preRelease ) { - console.log( "Skipping archive creation for " + cdn + "; this is a beta release." ); - return; - } + files = [ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ], + cdn = require( "./release/cdn" ), + dist = require( "./release/dist" ), + ensureSizzle = require( "./release/ensure-sizzle" ), - console.log( "Creating production archive for " + cdn ); - - var archiver = require( "archiver" )( "zip" ), - md5file = cdnFolder + "/" + cdn + "-md5.txt", - output = fs.createWriteStream( - cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip" - ); - - output.on( "error", function( err ) { - throw err; - }); - - archiver.pipe( output ); - - files = files.map(function( item ) { - return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion ); - }); - - shell.exec( "md5sum", files, function( code, stdout ) { - fs.writeFileSync( md5file, stdout ); - files.push( md5file ); - - files.forEach(function( file ) { - archiver.append( fs.createReadStream( file ), { name: file } ); - }); - - archiver.finalize(); - }); - } + npmTags = Release.npmTags, + createTag = Release._createTag; Release.define({ npmPublish: true, - npmTags: function() { - return [ "1.x" ]; - }, - issueTracker: "trac", - contributorReportId: 508, + issueTracker: "github", /** * Ensure the repo is in a proper state before release * @param {Function} callback @@ -118,6 +20,18 @@ module.exports = function( Release ) { checkRepoState: function( callback ) { ensureSizzle( Release, callback ); }, + /** + * The tag for compat is different + * This sets a different new version for the source repo, + * but after building with the correct tag + * e.g. 3.0.0-compat + */ + _createTag: function( paths ) { + Release.distVersion = Release.newVersion; + Release.newVersion = Release.newVersion + .replace( /(\d+\.\d+\.\d+)/, "$1-compat" ); + return createTag( paths ); + }, /** * Generates any release artifacts that should be included in the release. * The callback must be invoked with an array of files that should be @@ -126,48 +40,37 @@ module.exports = function( Release ) { */ generateArtifacts: function( callback ) { Release.exec( "grunt", "Grunt command failed" ); - makeReleaseCopies(); - callback([ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ]); + cdn.makeReleaseCopies( Release ); + callback( files ); }, /** - * Release completion + * Acts as insertion point for restoring Release.dir.repo + * It was changed to reuse npm publish code in jquery-release + * for publishing the distribution repo instead */ - complete: function() { - // Build CDN archives async - buildGoogleCDN(); - buildMicrosoftCDN(); - _complete(); + npmTags: function() { + // origRepo is not defined if dist was skipped + Release.dir.repo = Release.dir.origRepo || Release.dir.repo; + return npmTags(); }, /** - * Our trac milestones are different than the new version - * @example - * - * // For Release.newVersion equal to 2.1.0 or 1.11.0 - * Release._tracMilestone(); - * // => 1.11/2.1 - * - * // For Release.newVersion equal to 2.1.1 or 1.11.1 - * Release._tracMilestone(); - * // => 1.11.1/2.1.1 + * Publish to distribution repo and npm + * @param {Function} callback */ - tracMilestone: function() { - var otherVersion, - m = Release.newVersion.split( "." ), - major = m[0] | 0, - minor = m[1] | 0, - patch = m[2] | 0 ? "." + m[2] : "", - version = major + "." + minor + patch; - if ( major === 1) { - otherVersion = "2." + ( minor - 10 ) + patch; - return version + "/" + otherVersion; + dist: function( callback ) { + + if ( Release.isTest ) { + callback(); + return; } - otherVersion = "1." + ( minor + 10 ) + patch; - return otherVersion + "/" + version; + + dist( Release, callback ); } }); }; module.exports.dependencies = [ "archiver@0.5.2", - "shelljs@0.2.6" + "shelljs@0.2.6", + "npm@2.3.0" ]; diff --git a/build/release/cdn.js b/build/release/cdn.js new file mode 100644 index 000000000..81dac2bac --- /dev/null +++ b/build/release/cdn.js @@ -0,0 +1,106 @@ +var + fs = require( "fs" ), + shell = require( "shelljs" ), + + cdnFolder = "dist/cdn", + + devFile = "dist/jquery.js", + minFile = "dist/jquery.min.js", + mapFile = "dist/jquery.min.map", + + releaseFiles = { + "jquery-compat-VER.js": devFile, + "jquery-compat-VER.min.js": minFile, + "jquery-compat-VER.min.map": mapFile + }, + + googleFilesCDN = [ + "jquery-compat.js", "jquery-compat.min.js", "jquery-compat.min.map" + ], + + msFilesCDN = [ + "jquery-compat-VER.js", "jquery-compat-VER.min.js", "jquery-compat-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":"jquery.min.js","sources":["jquery.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 ( /\.min\.js$/.test( releaseFile ) ) { + // Remove the source map comment; it causes way too many problems. + // Keep the map file in case DevTools allow manual association. + text = fs.readFileSync( builtFile, "utf8" ) + .replace( /\/\/# sourceMappingURL=\S+/, "" ); + fs.writeFileSync( releaseFile, text ); + } else if ( builtFile !== releaseFile ) { + shell.cp( "-f", builtFile, releaseFile ); + } + }); +} + +function makeArchive( Release, cdn, files ) { + if ( Release.preRelease ) { + console.log( "Skipping archive creation for " + cdn + "; this is a beta release." ); + return; + } + + console.log( "Creating production archive for " + cdn ); + + var archiver = require( "archiver" )( "zip" ), + md5file = cdnFolder + "/" + cdn + "-md5.txt", + output = fs.createWriteStream( + cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip" + ); + + output.on( "error", function( err ) { + throw err; + }); + + archiver.pipe( output ); + + files = files.map(function( item ) { + return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion ); + }); + + shell.exec( "md5sum", files, function( code, stdout ) { + fs.writeFileSync( md5file, stdout ); + files.push( md5file ); + + files.forEach(function( file ) { + archiver.append( fs.createReadStream( file ), { name: file } ); + }); + + archiver.finalize(); + }); +} + +function buildGoogleCDN( Release ) { + makeArchive( Release, "googlecdn", googleFilesCDN ); +} + +function buildMicrosoftCDN( Release ) { + makeArchive( Release, "mscdn", msFilesCDN ); +} + +module.exports = { + makeReleaseCopies: makeReleaseCopies, + buildGoogleCDN: buildGoogleCDN, + buildMicrosoftCDN: buildMicrosoftCDN +}; diff --git a/build/release/dist.js b/build/release/dist.js new file mode 100644 index 000000000..2c6cfc645 --- /dev/null +++ b/build/release/dist.js @@ -0,0 +1,116 @@ +module.exports = function( Release, complete ) { + + var + fs = require( "fs" ), + shell = require( "shelljs" ), + pkg = require( Release.dir.repo + "/package.json" ), + // These files are included with the distrubtion + files = [ + "src", + "LICENSE.txt", + "AUTHORS.txt", + "package.json" + ]; + + /** + * Clone the distribution repo + */ + function clone() { + var distRemote = Release.remote.replace( "jquery", "jquery-compat-dist" ); + + 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 jquery-compat-dist + */ + function generateBower() { + return JSON.stringify({ + name: pkg.name, + version: pkg.version, + 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/jquery.js", + "dist/jquery.min.js", + "dist/jquery.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() ); + + // Restore newVersion + Release.newVersion = Release.distVersion; + + 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 origin 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/build/ensure-sizzle.js b/build/release/ensure-sizzle.js similarity index 91% rename from build/ensure-sizzle.js rename to build/release/ensure-sizzle.js index 66e5ee47c..c3e4ed159 100644 --- a/build/ensure-sizzle.js +++ b/build/release/ensure-sizzle.js @@ -1,10 +1,8 @@ var fs = require( "fs" ), npm = require( "npm" ), - sizzleLoc = __dirname + "/../external/sizzle/dist/sizzle.js", + sizzleLoc = __dirname + "/../../external/sizzle/dist/sizzle.js", rversion = /Engine v(\d+\.\d+\.\d+(?:-[-\.\d\w]+)?)/; -require( "colors" ); - /** * Retrieve the latest tag of Sizzle from npm * @param {Function(string)} callback @@ -36,6 +34,7 @@ function ensureSizzle( Release, callback ) { version = match ? match[ 1 ] : "Not Found"; if ( version !== latest ) { + // colors is inherited from jquery-release console.log( "The Sizzle version in the src folder (" + version.red + ") is not the latest tag (" + latest.green + ")." diff --git a/build/release-notes.js b/build/release/release-notes.js similarity index 100% rename from build/release-notes.js rename to build/release/release-notes.js diff --git a/package.json b/package.json index 75ec15047..d1234e901 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ ], "dependencies": {}, "devDependencies": { - "colors": "1.0.3", "commitplease": "2.0.0", "grunt": "0.4.5", "grunt-cli": "0.1.13", @@ -44,7 +43,6 @@ "grunt-npmcopy": "0.1.0", "gzip-js": "0.3.2", "load-grunt-tasks": "1.0.0", - "npm": "2.1.12", "qunitjs": "1.16.0", "requirejs": "2.1.15", "sinon": "1.12.2", -- 2.39.5