Skip to content

Commit

Permalink
Release: Distribute files to distribution repo
Browse files Browse the repository at this point in the history
Fixes gh-1869
Fixes gh-1673
Fixes gh-2045

Conflicts:
	bower.json
	build/release.js
  • Loading branch information
timmywil committed Jan 29, 2015
1 parent 4e3c48f commit fc76a97
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 163 deletions.
21 changes: 0 additions & 21 deletions bower.json

This file was deleted.

177 changes: 40 additions & 137 deletions build/release.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,37 @@

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
*/
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
Expand All @@ -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 = [
"[email protected]",
"[email protected]"
"[email protected]",
"[email protected]"
];
106 changes: 106 additions & 0 deletions build/release/cdn.js
Original file line number Diff line number Diff line change
@@ -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
};
Loading

0 comments on commit fc76a97

Please sign in to comment.