Skip to content

Commit 26eca14

Browse files
committed
Release: Distribute files to distribution repo
Fixes jquerygh-1869 Fixes jquerygh-1673 Fixes jquerygh-2045
1 parent 087d280 commit 26eca14

File tree

7 files changed

+251
-159
lines changed

7 files changed

+251
-159
lines changed

bower.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

build/release.js

Lines changed: 30 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,21 @@
1+
12
module.exports = function( Release ) {
23

34
var
4-
fs = require( "fs" ),
5-
shell = require( "shelljs" ),
6-
ensureSizzle = require( "./ensure-sizzle" ),
7-
8-
devFile = "dist/jquery.js",
9-
minFile = "dist/jquery.min.js",
10-
mapFile = "dist/jquery.min.map",
11-
12-
cdnFolder = "dist/cdn",
13-
14-
releaseFiles = {
15-
"jquery-VER.js": devFile,
16-
"jquery-VER.min.js": minFile,
17-
"jquery-VER.min.map": mapFile
18-
},
19-
20-
googleFilesCDN = [
21-
"jquery.js", "jquery.min.js", "jquery.min.map"
22-
],
23-
24-
msFilesCDN = [
25-
"jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map"
26-
],
5+
files = [ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ],
6+
cdn = require( "./release/cdn" ),
7+
dist = require( "./release/dist" ),
8+
ensureSizzle = require( "./release/ensure-sizzle" ),
279

28-
_complete = Release.complete;
10+
npmTags = Release.npmTags;
2911

30-
/**
31-
* Generates copies for the CDNs
32-
*/
33-
function makeReleaseCopies() {
34-
shell.mkdir( "-p", cdnFolder );
35-
36-
Object.keys( releaseFiles ).forEach(function( key ) {
37-
var text,
38-
builtFile = releaseFiles[ key ],
39-
unpathedFile = key.replace( /VER/g, Release.newVersion ),
40-
releaseFile = cdnFolder + "/" + unpathedFile;
41-
42-
if ( /\.map$/.test( releaseFile ) ) {
43-
// Map files need to reference the new uncompressed name;
44-
// assume that all files reside in the same directory.
45-
// "file":"jquery.min.js","sources":["jquery.js"]
46-
text = fs.readFileSync( builtFile, "utf8" )
47-
.replace( /"file":"([^"]+)","sources":\["([^"]+)"\]/,
48-
"\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js" ) +
49-
"\",\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" );
50-
fs.writeFileSync( releaseFile, text );
51-
} else if ( /\.min\.js$/.test( releaseFile ) ) {
52-
// Remove the source map comment; it causes way too many problems.
53-
// Keep the map file in case DevTools allow manual association.
54-
text = fs.readFileSync( builtFile, "utf8" )
55-
.replace( /\/\/# sourceMappingURL=\S+/, "" );
56-
fs.writeFileSync( releaseFile, text );
57-
} else if ( builtFile !== releaseFile ) {
58-
shell.cp( "-f", builtFile, releaseFile );
59-
}
60-
});
61-
}
62-
63-
function buildGoogleCDN() {
64-
makeArchive( "googlecdn", googleFilesCDN );
65-
}
66-
67-
function buildMicrosoftCDN() {
68-
makeArchive( "mscdn", msFilesCDN );
69-
}
70-
71-
function makeArchive( cdn, files ) {
72-
if ( Release.preRelease ) {
73-
console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
74-
return;
75-
}
76-
77-
console.log( "Creating production archive for " + cdn );
78-
79-
var archiver = require( "archiver" )( "zip" ),
80-
md5file = cdnFolder + "/" + cdn + "-md5.txt",
81-
output = fs.createWriteStream(
82-
cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip"
83-
);
84-
85-
output.on( "error", function( err ) {
86-
throw err;
87-
});
88-
89-
archiver.pipe( output );
90-
91-
files = files.map(function( item ) {
92-
return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion );
93-
});
94-
95-
shell.exec( "md5sum", files, function( code, stdout ) {
96-
fs.writeFileSync( md5file, stdout );
97-
files.push( md5file );
98-
99-
files.forEach(function( file ) {
100-
archiver.append( fs.createReadStream( file ), { name: file } );
101-
});
102-
103-
archiver.finalize();
104-
});
105-
}
12+
// Have jquery-release update the version
13+
// in our bower.json template
14+
Release._jsonFiles.push( "build/release/_bower.json" );
10615

10716
Release.define({
10817
npmPublish: true,
109-
issueTracker: "trac",
110-
contributorReportId: 508,
18+
issueTracker: "github",
11119
/**
11220
* Ensure the repo is in a proper state before release
11321
* @param {Function} callback
@@ -123,48 +31,37 @@ module.exports = function( Release ) {
12331
*/
12432
generateArtifacts: function( callback ) {
12533
Release.exec( "grunt", "Grunt command failed" );
126-
makeReleaseCopies();
127-
callback([ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ]);
34+
cdn.makeReleaseCopies( Release );
35+
callback( files );
12836
},
12937
/**
130-
* Release completion
38+
* Acts as insertion point for restoring Release.dir.repo
39+
* It was changed to reuse npm publish code in jquery-release
40+
* for publishing the distribution repo instead
13141
*/
132-
complete: function() {
133-
// Build CDN archives async
134-
buildGoogleCDN();
135-
buildMicrosoftCDN();
136-
_complete();
42+
npmTags: function() {
43+
// origRepo is not defined if dist was skipped
44+
Release.dir.repo = Release.dir.origRepo || Release.dir.repo;
45+
return npmTags();
13746
},
13847
/**
139-
* Our trac milestones are different than the new version
140-
* @example
141-
*
142-
* // For Release.newVersion equal to 2.1.0 or 1.11.0
143-
* Release._tracMilestone();
144-
* // => 1.11/2.1
145-
*
146-
* // For Release.newVersion equal to 2.1.1 or 1.11.1
147-
* Release._tracMilestone();
148-
* // => 1.11.1/2.1.1
48+
* Publish to distribution repo and npm
49+
* @param {Function} callback
14950
*/
150-
tracMilestone: function() {
151-
var otherVersion,
152-
m = Release.newVersion.split( "." ),
153-
major = m[0] | 0,
154-
minor = m[1] | 0,
155-
patch = m[2] | 0 ? "." + m[2] : "",
156-
version = major + "." + minor + patch;
157-
if ( major === 1) {
158-
otherVersion = "2." + ( minor - 10 ) + patch;
159-
return version + "/" + otherVersion;
51+
dist: function( callback ) {
52+
53+
if ( Release.isTest ) {
54+
callback();
55+
return;
16056
}
161-
otherVersion = "1." + ( minor + 10 ) + patch;
162-
return otherVersion + "/" + version;
57+
58+
dist( Release, callback );
16359
}
16460
});
16561
};
16662

16763
module.exports.dependencies = [
16864
"archiver@0.5.2",
169-
"shelljs@0.2.6"
65+
"shelljs@0.2.6",
66+
"npm@2.3.0"
17067
];

build/release/cdn.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
var
2+
fs = require( "fs" ),
3+
shell = require( "shelljs" ),
4+
5+
cdnFolder = "dist/cdn",
6+
7+
devFile = "dist/jquery.js",
8+
minFile = "dist/jquery.min.js",
9+
mapFile = "dist/jquery.min.map",
10+
11+
releaseFiles = {
12+
"jquery-VER.js": devFile,
13+
"jquery-VER.min.js": minFile,
14+
"jquery-VER.min.map": mapFile
15+
},
16+
17+
googleFilesCDN = [
18+
"jquery.js", "jquery.min.js", "jquery.min.map"
19+
],
20+
21+
msFilesCDN = [
22+
"jquery-VER.js", "jquery-VER.min.js", "jquery-VER.min.map"
23+
];
24+
25+
/**
26+
* Generates copies for the CDNs
27+
*/
28+
function makeReleaseCopies( Release ) {
29+
shell.mkdir( "-p", cdnFolder );
30+
31+
Object.keys( releaseFiles ).forEach(function( key ) {
32+
var text,
33+
builtFile = releaseFiles[ key ],
34+
unpathedFile = key.replace( /VER/g, Release.newVersion ),
35+
releaseFile = cdnFolder + "/" + unpathedFile;
36+
37+
if ( /\.map$/.test( releaseFile ) ) {
38+
// Map files need to reference the new uncompressed name;
39+
// assume that all files reside in the same directory.
40+
// "file":"jquery.min.js","sources":["jquery.js"]
41+
text = fs.readFileSync( builtFile, "utf8" )
42+
.replace( /"file":"([^"]+)","sources":\["([^"]+)"\]/,
43+
"\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js" ) +
44+
"\",\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]" );
45+
fs.writeFileSync( releaseFile, text );
46+
} else if ( /\.min\.js$/.test( releaseFile ) ) {
47+
// Remove the source map comment; it causes way too many problems.
48+
// Keep the map file in case DevTools allow manual association.
49+
text = fs.readFileSync( builtFile, "utf8" )
50+
.replace( /\/\/# sourceMappingURL=\S+/, "" );
51+
fs.writeFileSync( releaseFile, text );
52+
} else if ( builtFile !== releaseFile ) {
53+
shell.cp( "-f", builtFile, releaseFile );
54+
}
55+
});
56+
}
57+
58+
function makeArchive( Release, cdn, files ) {
59+
if ( Release.preRelease ) {
60+
console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
61+
return;
62+
}
63+
64+
console.log( "Creating production archive for " + cdn );
65+
66+
var archiver = require( "archiver" )( "zip" ),
67+
md5file = cdnFolder + "/" + cdn + "-md5.txt",
68+
output = fs.createWriteStream(
69+
cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip"
70+
);
71+
72+
output.on( "error", function( err ) {
73+
throw err;
74+
});
75+
76+
archiver.pipe( output );
77+
78+
files = files.map(function( item ) {
79+
return cdnFolder + "/" + item.replace( /VER/g, Release.newVersion );
80+
});
81+
82+
shell.exec( "md5sum", files, function( code, stdout ) {
83+
fs.writeFileSync( md5file, stdout );
84+
files.push( md5file );
85+
86+
files.forEach(function( file ) {
87+
archiver.append( fs.createReadStream( file ), { name: file } );
88+
});
89+
90+
archiver.finalize();
91+
});
92+
}
93+
94+
function buildGoogleCDN( Release ) {
95+
makeArchive( Release, "googlecdn", googleFilesCDN );
96+
}
97+
98+
function buildMicrosoftCDN( Release ) {
99+
makeArchive( Release, "mscdn", msFilesCDN );
100+
}
101+
102+
module.exports = {
103+
makeReleaseCopies: makeReleaseCopies,
104+
buildGoogleCDN: buildGoogleCDN,
105+
buildMicrosoftCDN: buildMicrosoftCDN
106+
};

0 commit comments

Comments
 (0)