Skip to content

Commit fc76a97

Browse files
committed
Release: Distribute files to distribution repo
Fixes gh-1869 Fixes gh-1673 Fixes gh-2045 Conflicts: bower.json build/release.js
1 parent 4e3c48f commit fc76a97

File tree

7 files changed

+264
-163
lines changed

7 files changed

+264
-163
lines changed

bower.json

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

build/release.js

Lines changed: 40 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,37 @@
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-
],
27-
28-
_complete = Release.complete;
29-
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-
}
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" ),
769

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-
}
10+
npmTags = Release.npmTags,
11+
createTag = Release._createTag;
10612

10713
Release.define({
10814
npmPublish: true,
109-
npmTags: function() {
110-
return [ "1.x" ];
111-
},
112-
issueTracker: "trac",
113-
contributorReportId: 508,
15+
issueTracker: "github",
11416
/**
11517
* Ensure the repo is in a proper state before release
11618
* @param {Function} callback
11719
*/
11820
checkRepoState: function( callback ) {
11921
ensureSizzle( Release, callback );
12022
},
23+
/**
24+
* The tag for compat is different
25+
* This sets a different new version for the source repo,
26+
* but after building with the correct tag
27+
* e.g. 3.0.0-compat
28+
*/
29+
_createTag: function( paths ) {
30+
Release.distVersion = Release.newVersion;
31+
Release.newVersion = Release.newVersion
32+
.replace( /(\d+\.\d+\.\d+)/, "$1-compat" );
33+
return createTag( paths );
34+
},
12135
/**
12236
* Generates any release artifacts that should be included in the release.
12337
* The callback must be invoked with an array of files that should be
@@ -126,48 +40,37 @@ module.exports = function( Release ) {
12640
*/
12741
generateArtifacts: function( callback ) {
12842
Release.exec( "grunt", "Grunt command failed" );
129-
makeReleaseCopies();
130-
callback([ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ]);
43+
cdn.makeReleaseCopies( Release );
44+
callback( files );
13145
},
13246
/**
133-
* Release completion
47+
* Acts as insertion point for restoring Release.dir.repo
48+
* It was changed to reuse npm publish code in jquery-release
49+
* for publishing the distribution repo instead
13450
*/
135-
complete: function() {
136-
// Build CDN archives async
137-
buildGoogleCDN();
138-
buildMicrosoftCDN();
139-
_complete();
51+
npmTags: function() {
52+
// origRepo is not defined if dist was skipped
53+
Release.dir.repo = Release.dir.origRepo || Release.dir.repo;
54+
return npmTags();
14055
},
14156
/**
142-
* Our trac milestones are different than the new version
143-
* @example
144-
*
145-
* // For Release.newVersion equal to 2.1.0 or 1.11.0
146-
* Release._tracMilestone();
147-
* // => 1.11/2.1
148-
*
149-
* // For Release.newVersion equal to 2.1.1 or 1.11.1
150-
* Release._tracMilestone();
151-
* // => 1.11.1/2.1.1
57+
* Publish to distribution repo and npm
58+
* @param {Function} callback
15259
*/
153-
tracMilestone: function() {
154-
var otherVersion,
155-
m = Release.newVersion.split( "." ),
156-
major = m[0] | 0,
157-
minor = m[1] | 0,
158-
patch = m[2] | 0 ? "." + m[2] : "",
159-
version = major + "." + minor + patch;
160-
if ( major === 1) {
161-
otherVersion = "2." + ( minor - 10 ) + patch;
162-
return version + "/" + otherVersion;
60+
dist: function( callback ) {
61+
62+
if ( Release.isTest ) {
63+
callback();
64+
return;
16365
}
164-
otherVersion = "1." + ( minor + 10 ) + patch;
165-
return otherVersion + "/" + version;
66+
67+
dist( Release, callback );
16668
}
16769
});
16870
};
16971

17072
module.exports.dependencies = [
17173
"archiver@0.5.2",
172-
"shelljs@0.2.6"
74+
"shelljs@0.2.6",
75+
"npm@2.3.0"
17376
];

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-compat-VER.js": devFile,
13+
"jquery-compat-VER.min.js": minFile,
14+
"jquery-compat-VER.min.map": mapFile
15+
},
16+
17+
googleFilesCDN = [
18+
"jquery-compat.js", "jquery-compat.min.js", "jquery-compat.min.map"
19+
],
20+
21+
msFilesCDN = [
22+
"jquery-compat-VER.js", "jquery-compat-VER.min.js", "jquery-compat-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)