Skip to content

Commit a8897d4

Browse files
committed
Release: Use downloadBuilder to build pre/cdn packages instead of our grunt tasks
1 parent e591a7a commit a8897d4

File tree

3 files changed

+178
-216
lines changed

3 files changed

+178
-216
lines changed

Gruntfile.js

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ function createBanner( files ) {
153153
grunt.initConfig({
154154
pkg: grunt.file.readJSON("package.json"),
155155
files: {
156-
dist: "<%= pkg.name %>-<%= pkg.version %>",
157-
cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
158-
themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
156+
dist: "<%= pkg.name %>-<%= pkg.version %>"
159157
},
160158
compare_size: compareFiles,
161159
concat: {
@@ -196,122 +194,10 @@ grunt.initConfig({
196194
})
197195
},
198196
copy: {
199-
dist: {
200-
src: [
201-
"AUTHORS.txt",
202-
"jquery-*.js",
203-
"MIT-LICENSE.txt",
204-
"README.md",
205-
"Gruntfile.js",
206-
"package.json",
207-
"*.jquery.json",
208-
"ui/**/*",
209-
"ui/.jshintrc",
210-
"demos/**/*",
211-
"themes/**/*",
212-
"external/**/*",
213-
"tests/**/*"
214-
],
215-
renames: {
216-
"dist/jquery-ui.js": "ui/jquery-ui.js",
217-
"dist/jquery-ui.min.js": "ui/minified/jquery-ui.min.js",
218-
"dist/i18n/jquery-ui-i18n.js": "ui/i18n/jquery-ui-i18n.js",
219-
"dist/i18n/jquery-ui-i18n.min.js": "ui/minified/i18n/jquery-ui-i18n.min.js",
220-
"dist/jquery-ui.css": "themes/base/jquery-ui.css",
221-
"dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
222-
},
223-
dest: "dist/<%= files.dist %>"
224-
},
225-
dist_min: {
226-
src: "dist/minified/**/*",
227-
strip: /^dist/,
228-
dest: "dist/<%= files.dist %>/ui"
229-
},
230-
dist_css_min: {
231-
src: "dist/themes/base/minified/*.css",
232-
strip: /^dist/,
233-
dest: "dist/<%= files.dist %>"
234-
},
235197
dist_units_images: {
236198
src: "themes/base/images/*",
237199
strip: /^themes\/base\//,
238200
dest: "dist/"
239-
},
240-
dist_min_images: {
241-
src: "themes/base/images/*",
242-
strip: /^themes\/base\//,
243-
dest: "dist/<%= files.dist %>/themes/base/minified"
244-
},
245-
cdn: {
246-
src: [
247-
"AUTHORS.txt",
248-
"MIT-LICENSE.txt",
249-
"ui/*.js",
250-
"package.json"
251-
],
252-
renames: {
253-
"dist/jquery-ui.js": "jquery-ui.js",
254-
"dist/jquery-ui.min.js": "jquery-ui.min.js",
255-
"dist/i18n/jquery-ui-i18n.js": "i18n/jquery-ui-i18n.js",
256-
"dist/i18n/jquery-ui-i18n.min.js": "i18n/jquery-ui-i18n.min.js"
257-
},
258-
dest: "dist/<%= files.cdn %>"
259-
},
260-
cdn_i18n: {
261-
src: "ui/i18n/jquery.ui.datepicker-*.js",
262-
strip: "ui/",
263-
dest: "dist/<%= files.cdn %>"
264-
},
265-
cdn_i18n_min: {
266-
src: "dist/minified/i18n/jquery.ui.datepicker-*.js",
267-
strip: "dist/minified",
268-
dest: "dist/<%= files.cdn %>"
269-
},
270-
cdn_min: {
271-
src: "dist/minified/*.js",
272-
strip: /^dist\/minified/,
273-
dest: "dist/<%= files.cdn %>/ui"
274-
},
275-
cdn_themes: {
276-
src: "dist/<%= files.themes %>/themes/**/*",
277-
strip: "dist/<%= files.themes %>",
278-
dest: "dist/<%= files.cdn %>"
279-
},
280-
themes: {
281-
src: [
282-
"AUTHORS.txt",
283-
"MIT-LICENSE.txt",
284-
"package.json"
285-
],
286-
dest: "dist/<%= files.themes %>"
287-
}
288-
},
289-
zip: {
290-
dist: {
291-
src: "<%= files.dist %>",
292-
dest: "<%= files.dist %>.zip"
293-
},
294-
cdn: {
295-
src: "<%= files.cdn %>",
296-
dest: "<%= files.cdn %>.zip"
297-
},
298-
themes: {
299-
src: "<%= files.themes %>",
300-
dest: "<%= files.themes %>.zip"
301-
}
302-
},
303-
md5: {
304-
dist: {
305-
src: "dist/<%= files.dist %>",
306-
dest: "dist/<%= files.dist %>/MANIFEST"
307-
},
308-
cdn: {
309-
src: "dist/<%= files.cdn %>",
310-
dest: "dist/<%= files.cdn %>/MANIFEST"
311-
},
312-
themes: {
313-
src: "dist/<%= files.themes %>",
314-
dest: "dist/<%= files.themes %>/MANIFEST"
315201
}
316202
},
317203
qunit: {
@@ -363,8 +249,5 @@ grunt.registerTask( "test", [ "qunit" ] );
363249
grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] );
364250
grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] );
365251
grunt.registerTask( "build", [ "concat", "uglify", "cssmin", "copy:dist_units_images" ] );
366-
grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist".split( " " ) );
367-
grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes".split( " " ) );
368-
grunt.registerTask( "release_cdn", "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_themes md5:cdn zip:cdn".split( " " ) );
369252

370253
};

build/release/release.js

Lines changed: 177 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
"use strict";
1010

11-
var baseDir, repoDir, prevVersion, newVersion, nextVersion, tagTime, preRelease, repo,
11+
var baseDir, downloadBuilder, repoDir, prevVersion, newVersion, nextVersion, tagTime, preRelease, repo,
1212
fs = require( "fs" ),
13+
path = require( "path" ),
1314
rnewline = /\r?\n/,
1415
branch = "master";
1516

@@ -25,7 +26,8 @@ walk([
2526
confirm,
2627

2728
section( "building release" ),
28-
buildRelease,
29+
buildReleaseBranch,
30+
buildPackage,
2931

3032
section( "pushing tag" ),
3133
confirmReview,
@@ -66,13 +68,6 @@ function cloneRepo() {
6668
if ( exec( "npm install" ).code !== 0 ) {
6769
abort( "Error installing dependencies." );
6870
}
69-
// We need download.jqueryui.com in order to generate themes.
70-
// We only generate themes for stable releases.
71-
if ( !preRelease ) {
72-
if ( exec( "npm install download.jqueryui.com" ).code !== 0 ) {
73-
abort( "Error installing dependencies." );
74-
}
75-
}
7671
echo();
7772
}
7873

@@ -135,9 +130,8 @@ function getVersions() {
135130
echo( "After the release, the version will be " + nextVersion.cyan + "." );
136131
}
137132

138-
function buildRelease() {
139-
var pkg,
140-
releaseTask = preRelease ? "release" : "release_cdn";
133+
function buildReleaseBranch() {
134+
var pkg;
141135

142136
echo( "Creating " + "release".cyan + " branch..." );
143137
git( "checkout -b release", "Error creating release branch." );
@@ -158,12 +152,6 @@ function buildRelease() {
158152
}
159153
echo();
160154

161-
echo( "Building release..." );
162-
if ( exec( "grunt " + releaseTask ).code !== 0 ) {
163-
abort( "Error building release." );
164-
}
165-
echo();
166-
167155
echo( "Committing release artifacts..." );
168156
git( "add *.jquery.json", "Error adding manifest files to git." );
169157
git( "commit -am 'Tagging the " + newVersion + " release.'",
@@ -175,6 +163,175 @@ function buildRelease() {
175163
tagTime = git( "log -1 --format='%ad'", "Error getting tag timestamp." ).trim();
176164
}
177165

166+
function buildPackage( callback ) {
167+
if( preRelease ) {
168+
return buildPreReleasePackage( callback );
169+
} else {
170+
return buildCDNPackage( callback );
171+
}
172+
}
173+
174+
function buildPreReleasePackage( callback ) {
175+
var build, files, jqueryUi, packer, target, targetZip;
176+
177+
echo( "Build pre-release Package" );
178+
179+
jqueryUi = new downloadBuilder.JqueryUi( path.resolve( "." ) );
180+
build = new downloadBuilder.Builder( jqueryUi, ":all:" );
181+
packer = new downloadBuilder.Packer( build, null, {
182+
addTests: true,
183+
bundleSuffix: "",
184+
skipDocs: true,
185+
skipTheme: true
186+
});
187+
target = "../" + jqueryUi.pkg.name + "-" + jqueryUi.pkg.version;
188+
targetZip = target + ".zip";
189+
190+
return walk([
191+
function( callback ) {
192+
echo( "Building release files" );
193+
packer.pack(function( error, _files ) {
194+
if( error ) {
195+
abort( error.stack );
196+
}
197+
files = _files.map(function( file ) {
198+
199+
// Strip first path
200+
file.path = file.path.replace( /^[^\/]*\//, "" );
201+
return file;
202+
203+
}).filter(function( file ) {
204+
205+
// Filter development-bundle content only
206+
return (/^development-bundle/).test( file.path );
207+
}).map(function( file ) {
208+
209+
// Strip development-bundle
210+
file.path = file.path.replace( /^development-bundle\//, "" );
211+
return file;
212+
213+
});
214+
return callback();
215+
});
216+
},
217+
function() {
218+
downloadBuilder.util.createZip( files, targetZip, function( error ) {
219+
if ( error ) {
220+
abort( error.stack );
221+
}
222+
echo( "Built zip package at " + path.relative( "../..", targetZip ).cyan );
223+
return callback();
224+
});
225+
}
226+
]);
227+
}
228+
229+
function buildCDNPackage( callback ) {
230+
var build, output, target, targetZip,
231+
add = function( file ) {
232+
output.push( file );
233+
},
234+
bundleFiles = [],
235+
jqueryUi = new downloadBuilder.JqueryUi( path.resolve( "." ) ),
236+
themeGallery = downloadBuilder.themeGallery( jqueryUi );
237+
238+
echo( "Build CDN Package" );
239+
240+
build = new downloadBuilder.Builder( jqueryUi, ":all:" );
241+
output = [];
242+
target = "../" + jqueryUi.pkg.name + "-" + jqueryUi.pkg.version + "-cdn";
243+
targetZip = target + ".zip";
244+
245+
[ "AUTHORS.txt", "MIT-LICENSE.txt", "package.json" ].map(function( name ) {
246+
return build.get( name );
247+
}).forEach( add );
248+
249+
// "ui/*.js"
250+
build.componentFiles.filter(function( file ) {
251+
return (/^ui\//).test( file.path );
252+
}).forEach( add );
253+
254+
// "ui/*.min.js"
255+
build.componentMinFiles.filter(function( file ) {
256+
return (/^ui\//).test( file.path );
257+
}).forEach( add );
258+
259+
// "i18n/*.js"
260+
build.i18nFiles.rename( /^ui\//, "" ).forEach( add );
261+
build.i18nMinFiles.rename( /^ui\//, "" ).forEach( add );
262+
build.bundleI18n.into( "i18n/" ).forEach( add );
263+
build.bundleI18nMin.into( "i18n/" ).forEach( add );
264+
265+
build.bundleJs.forEach( add );
266+
build.bundleJsMin.forEach( add );
267+
268+
walk( themeGallery.map(function( theme ) {
269+
return function( callback ) {
270+
var themeCssOnlyRe, themeDirRe,
271+
folderName = theme.folderName(),
272+
packer = new downloadBuilder.Packer( build, theme, {
273+
skipDocs: true
274+
});
275+
// TODO improve code by using custom packer instead of download packer (Packer)
276+
themeCssOnlyRe = new RegExp( "development-bundle/themes/" + folderName + "/jquery.ui.theme.css" );
277+
themeDirRe = new RegExp( "css/" + folderName );
278+
packer.pack(function( error, files ) {
279+
if ( error ) {
280+
abort( error.stack );
281+
}
282+
// Add theme files.
283+
files
284+
// Pick only theme files we need on the bundle.
285+
.filter(function( file ) {
286+
if ( themeCssOnlyRe.test( file.path ) || themeDirRe.test( file.path ) ) {
287+
return true;
288+
}
289+
return false;
290+
})
291+
// Convert paths the way bundle needs
292+
.map(function( file ) {
293+
file.path = file.path
294+
295+
// Remove initial package name eg. "jquery-ui-1.10.0.custom"
296+
.split( "/" ).slice( 1 ).join( "/" )
297+
298+
.replace( /development-bundle\/themes/, "css" )
299+
.replace( /css/, "themes" )
300+
301+
// Make jquery-ui-1.10.0.custom.css into jquery-ui.css, or jquery-ui-1.10.0.custom.min.css into jquery-ui.min.css
302+
.replace( /jquery-ui-.*?(\.min)*\.css/, "jquery-ui$1.css" );
303+
304+
return file;
305+
}).forEach( add );
306+
return callback();
307+
});
308+
309+
}
310+
}).concat([function() {
311+
var crypto = require( "crypto" );
312+
313+
// Create MD5 manifest
314+
output.push({
315+
path: "MANIFEST",
316+
data: output.sort(function( a, b ) {
317+
return a.path.localeCompare( b.path );
318+
}).map(function( file ) {
319+
var md5 = crypto.createHash( "md5" );
320+
md5.update( file.data );
321+
return file.path + " " + md5.digest( "hex" );
322+
}).join( "\n" )
323+
});
324+
325+
downloadBuilder.util.createZip( output, targetZip, function( error ) {
326+
if ( error ) {
327+
abort( error.stack );
328+
}
329+
echo( "Built zip CDN package at " + path.relative( "../..", targetZip ).cyan );
330+
return callback();
331+
});
332+
}]));
333+
}
334+
178335
function pushRelease() {
179336
echo( "Pushing release to GitHub..." );
180337
git( "push --tags", "Error pushing tags to GitHub." );
@@ -419,14 +576,15 @@ function _bootstrap( fn ) {
419576
fs.mkdirSync( baseDir );
420577

421578
console.log( "Installing dependencies..." );
422-
require( "child_process" ).exec( "npm install shelljs colors", function( error ) {
579+
require( "child_process" ).exec( "npm install shelljs colors download.jqueryui.com", function( error ) {
423580
if ( error ) {
424581
console.log( error );
425582
return process.exit( 1 );
426583
}
427584

428585
require( "shelljs/global" );
429586
require( "colors" );
587+
downloadBuilder = require( "download.jqueryui.com" );
430588

431589
fn();
432590
});

0 commit comments

Comments
 (0)