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
|
var
fs = require( "fs" ),
shell = require( "shelljs" ),
path = require( "path" ),
cdnFolder = "dist/cdn",
devFile = "dist/jquery.js",
minFile = "dist/jquery.min.js",
mapFile = "dist/jquery.min.map",
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"
];
/**
* 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 ( builtFile !== releaseFile ) {
shell.cp( "-f", builtFile, releaseFile );
}
} );
}
function makeArchives( Release, callback ) {
Release.chdir( Release.dir.repo );
function makeArchive( cdn, files, callback ) {
if ( Release.preRelease ) {
console.log( "Skipping archive creation for " + cdn + "; this is a beta release." );
callback();
return;
}
console.log( "Creating production archive for " + cdn );
var sum,
archiver = require( "archiver" )( "zip" ),
md5file = cdnFolder + "/" + cdn + "-md5.txt",
output = fs.createWriteStream(
cdnFolder + "/" + cdn + "-jquery-" + Release.newVersion + ".zip"
),
rver = /VER/;
output.on( "close", callback );
output.on( "error", function( err ) {
throw err;
} );
archiver.pipe( output );
files = files.map( function( item ) {
return "dist" + ( rver.test( item ) ? "/cdn" : "" ) + "/" +
item.replace( rver, Release.newVersion );
} );
sum = Release.exec( "md5sum " + files.join( " " ), "Error retrieving md5sum" );
fs.writeFileSync( md5file, sum );
files.push( md5file );
files.forEach( function( file ) {
archiver.append( fs.createReadStream( file ),
{ name: path.basename( file ) } );
} );
archiver.finalize();
}
function buildGoogleCDN( callback ) {
makeArchive( "googlecdn", googleFilesCDN, callback );
}
function buildMicrosoftCDN( callback ) {
makeArchive( "mscdn", msFilesCDN, callback );
}
buildGoogleCDN( function() {
buildMicrosoftCDN( callback );
} );
}
module.exports = {
makeReleaseCopies: makeReleaseCopies,
makeArchives: makeArchives
};
|