forked from jquery/jquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
172 lines (148 loc) · 4.88 KB
/
release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
module.exports = function( Release ) {
var
fs = require( "fs" ),
shell = require( "shelljs" ),
// Windows needs the .cmd version but will find the non-.cmd
// On Windows, ensure the HOME environment variable is set
gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt",
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 //,
// Disable these until 2.0 defeats 1.9 as the ONE TRUE JQUERY
// "jquery.js": devFile,
// "jquery.min.js": minFile,
// "jquery.min.map": mapFile,
// "jquery-latest.js": devFile,
// "jquery-latest.min.js": minFile,
// "jquery-latest.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;
// Beta releases don't update the jquery-latest etc. copies
if ( !Release.preRelease || key.indexOf( "VER" ) >= 0 ) {
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;
}
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();
});
}
Release.define({
npmPublish: true,
issueTracker: "trac",
contributorReportId: 508,
/**
* 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 ) {
if ( Release.exec( gruntCmd ).code !== 0 ) {
Release.abort("Grunt command failed");
}
makeReleaseCopies();
callback([ "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" ]);
},
/**
* Release completion
*/
complete: function() {
// Build CDN archives async
buildGoogleCDN();
buildMicrosoftCDN();
_complete();
},
/**
* 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
*/
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;
}
otherVersion = "1." + ( minor + 10 ) + patch;
return otherVersion + "/" + version;
}
});
};