diff options
-rw-r--r-- | grunt.js | 211 | ||||
-rw-r--r-- | version.txt | 1 |
2 files changed, 172 insertions, 40 deletions
@@ -23,39 +23,35 @@ var uiFiles = coreFiles.map(function(file) { })); var minify = { - 'dist/ui/minified/jquery-ui.min.js': ['<banner:meta.bannerAll>', 'dist/ui/jquery-ui.js'], - 'dist/ui/minified/i18n/jquery-ui-i18n.min.js': ['<banner:meta.bannerI18n>', 'dist/ui/i18n/jquery-ui-i18n.js'] + 'dist/jquery-ui.min.js': ['<banner:meta.bannerAll>', 'dist/jquery-ui.js'], + 'dist/i18n/jquery-ui-i18n.min.js': ['<banner:meta.bannerI18n>', 'dist/i18n/jquery-ui-i18n.js'] }; function minFile(file) { - minify['dist/' + file.replace(/\.js$/, '.min.js').replace(/ui\//, 'ui/minified/')] = ['<banner>', file]; + minify['dist/' + file.replace(/\.js$/, '.min.js').replace(/ui\//, 'minified/')] = ['<banner>', file]; } uiFiles.forEach(minFile); var allI18nFiles = file.expand('ui/i18n/*.js'); allI18nFiles.forEach(minFile); -// TODO move core to the front, theme to the end, exclude all and base -var cssFiles = file.expand('themes/base/*.css'); - -var cdnFiles = [ - 'AUTHORS.txt', - 'GPL-LICENSE.txt', - 'MIT-LICENSE.txt', - 'dist/i18n/jquery-ui-i18n.js', - 'dist/i18n/jquery-ui-i18n.min.js', - 'ui/i18n/jquery.ui.datepicker-*.js', - 'dist/ui/i18n/jquery.ui.datepicker-*.min.js', - 'dist/ui/jquery-ui.js', - 'dist/ui/minified/jquery-ui.min.js', - 'themes/base/images/*.png', - 'dist/themes/base/jquery-ui.css', - 'themes/base/jquery.ui.*.css', - 'dist/themes/base/minified/*.css', - 'version.txt' -]; +var cssFiles = 'core accordion autocomplete button datepicker dialog menu progressbar resizable selectable slider spinner tabs tooltip theme'.split(' ').map(function(component) { + return 'themes/base/jquery.ui.' + component + '.css'; +}); +var minifyCSS = { + 'dist/jquery-ui.min.css': 'dist/jquery-ui.css' +}; +cssFiles.forEach(function(file) { + minifyCSS['dist/' + file.replace(/\.css$/, '.min.css').replace(/themes\/base\//, 'themes/base/minified/')] = ['<banner>', file]; +}); config.init({ pkg: '<json:package.json>', + files: { + distFolder: 'dist/<%= pkg.name %>-<%= pkg.version %>', + cdnDistFolder: 'dist/<%= pkg.name %>-<%= pkg.version %>-cdn', + zip: 'dist/<%= pkg.name %>-<%= pkg.version %>.zip', + cdnZip: 'dist/<%= pkg.name %>-<%= pkg.version %>-cdn.zip' + }, meta: { banner: createBanner(), bannerAll: createBanner(uiFiles), @@ -63,20 +59,32 @@ config.init({ bannerCSS: createBanner(cssFiles) }, concat: { - 'dist/ui/jquery-ui.js': uiFiles, - 'dist/ui/i18n/jquery-ui-i18n.js': 'ui/i18n/*.js' - }, - min: minify, - css_min: { - dist: { + // TODO replace banners, both for JS and CSS + ui: { + src: ['<banner:meta.bannerAll>'].concat(uiFiles.map(function(file) { + // TODO why doesn't this work? + return '<file_strip_banner:' + file + '>'; + })), + dest: 'dist/jquery-ui.js' + }, + i18n: { + src: ['<banner:meta.bannerI18n>', allI18nFiles], + dest: 'dist/i18n/jquery-ui-i18n.js' + }, + css: { src: ['<banner:meta.bannerCSS>'].concat(cssFiles), - dest: 'dist/themes/base/minified/jquery-ui.min.css' + dest: 'dist/jquery-ui.css' } }, - zip: { + min: minify, + css_min: minifyCSS, + copy: { dist: { src: [ - 'dist/**/*.js', + 'AUTHORS.txt', + 'GPL-LICENSE.txt', + 'jquery-1.7.1.js', + 'MIT-LICENSE.txt', 'README.md', 'grunt.js', 'package.json', @@ -86,15 +94,92 @@ config.init({ 'external/**/*', 'tests/**/*' ], - dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.zip' + renames: { + 'dist/jquery-ui.js': 'ui/jquery-ui.js', + 'dist/jquery-ui.min.js': 'ui/minified/jquery-ui.min.js', + 'dist/i18n/jquery-ui-i18n.js': 'ui/i18n/jquery-ui-i18n.js', + 'dist/i18n/jquery-ui-i18n.min.js': 'ui/minified/i18n/jquery-ui-i18n.min.js', + 'dist/jquery-ui.css': 'themes/base/jquery-ui.css', + 'dist/jquery-ui.min.css': 'themes/base/minified/jquery-ui.min.css' + }, + dest: '<%= files.distFolder %>' + }, + dist_min: { + src: 'dist/minified/**/*', + strip: /^dist/, + dest: '<%= files.distFolder %>/ui' + }, + dist_css_min: { + src: 'dist/themes/base/minified/*.css', + strip: /^dist/, + dest: '<%= files.distFolder %>' + }, + dist_min_images: { + src: 'themes/base/images/*', + strip: /^themes\/base\//, + dest: '<%= files.distFolder %>/themes/base/minified' }, cdn: { - src: cdnFiles, - dest: 'dist/<%= pkg.name %>-<%= pkg.version %>-cdn.zip' + src: [ + 'AUTHORS.txt', + 'GPL-LICENSE.txt', + 'MIT-LICENSE.txt', + 'ui/*.js', + 'themes/base/images/*.png', + 'themes/base/jquery.ui.*.css', + 'package.json' + ], + renames: { + 'dist/jquery-ui.js': 'jquery-ui.js', + 'dist/jquery-ui.min.js': 'jquery-ui.min.js', + 'dist/i18n/jquery-ui-i18n.js': 'i18n/jquery-ui-i18n.js', + 'dist/i18n/jquery-ui-i18n.min.js': 'i18n/jquery-ui-i18n.min.js', + 'dist/jquery-ui.css': 'themes/base/jquery-ui.css', + 'dist/jquery-ui.min.css': 'themes/base/minified/jquery-ui.min.css' + }, + dest: '<%= files.cdnDistFolder %>' + }, + cdn_i18n: { + src: 'ui/i18n/jquery.ui.datepicker-*.js', + strip: 'ui/', + dest: '<%= files.cdnDistFolder %>' + }, + cdn_i18n_min: { + src: 'dist/minified/i18n/jquery.ui.datepicker-*.js', + strip: 'dist/minified', + dest: '<%= files.cdnDistFolder %>' + }, + cdn_min: { + src: 'dist/minified/*.js', + strip: /^dist\/minified/, + dest: '<%= files.cdnDistFolder %>/ui' + }, + cdn_css_min: { + src: 'dist/themes/base/minified/*.css', + strip: /^dist/, + dest: '<%= files.cdnDistFolder %>' + }, + dist_min_images: { + src: 'themes/base/images/*', + strip: /^themes\/base\//, + dest: '<%= files.cdnDistFolder %>/themes/base/minified' + } + }, + zip: { + dist: { + src: '<%= files.distFolder %>/**/*', + dest: '<%= files.zip %>' + }, + cdn: { + src: '<%= files.cdnDistFolder %>/**/*', + dest: '<%= files.cdnZip %>' } }, md5: { - 'dist/MANIFEST': cdnFiles + cdn: { + dir: '<%= files.cdnDistFolder %>', + dest: '<%= files.cdnDistFolder %>/MANIFEST' + } }, qunit: { files: file.expand('tests/unit/**/*.html').filter(function(file) { @@ -126,6 +211,39 @@ config.init({ } }); +// grunt doesn't know about this files object, so need to process that manually once +// before any other variable is resolved, otherwise it would just include the templates +var files = config().files; +for (var key in files) { + files[key] = template.process(files[key], config()); +} +config('files', files); +// log.writeln(require('util').inspect(config().files)) + +task.registerTask('x', function() { + log.writeln(task.helper('concat', ['<file_strip_banner:ui/jquery.ui.core.js>'])); +}); + +task.registerBasicTask('copy', 'Copy files to destination folder and replace @VERSION with pkg.version', function(data) { + function replaceVersion(source) { + return source.replace("@VERSION", config("pkg").version); + } + var files = file.expand(data.src); + var target = data.dest + '/'; + files.forEach(function(fileName) { + var targetFile = data.strip ? fileName.replace(data.strip, '') : fileName; + file.copy(fileName, target + targetFile, replaceVersion); + }); + log.writeln('Copyied ' + files.length + ' files.'); + for (var fileName in data.renames) { + file.copy(fileName, target + template.process(data.renames[fileName], config())); + } + if (data.renames) { + log.writeln('Renamed ' + data.renames.length + ' files.'); + } +}); + + task.registerBasicTask('zip', 'Create a zip file for release', function(data) { var files = file.expand(data.src); log.writeln("Creating zip file " + data.dest); @@ -164,16 +282,31 @@ task.registerBasicTask( 'css_min', 'Minify CSS files with Sqwish.', function( da }); task.registerBasicTask('md5', 'Create list of md5 hashes for CDN uploads', function(data) { + // remove dest file before creating it, to make sure itself is not included + if (require('path').existsSync(data.dest)) { + require('fs').unlinkSync(data.dest); + } var crypto = require('crypto'); + var dir = template.process(data.dir, config()) + '/'; var hashes = []; - file.expand(data.src).forEach(function(fileName) { + file.expand(dir + '**/*').forEach(function(fileName) { var hash = crypto.createHash('md5'); hash.update(file.read(fileName)); - hashes.push(fileName + ' ' + hash.digest('hex')); + hashes.push(fileName.replace(dir, '') + ' ' + hash.digest('hex')); }); file.write(data.dest, hashes.join('\n') + '\n'); }); task.registerTask('default', 'lint qunit'); -task.registerTask('release', 'concat min zip:dist'); -task.registerTask('release_cdn', 'concat min md5 zip:cdn');
\ No newline at end of file +task.registerTask('build', 'concat min css_min'); +task.registerTask('release', 'build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min zip:dist'); +task.registerTask('release_themes', 'build download_themes zip:themes'); +// TODO includes other themes in cdn release +task.registerTask('release_cdn', 'build copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_css_min md5 zip:cdn'); + +task.registerTask('download_themes', function() { + // TODO use request.get to download the files specified in build/themes +}); + +// TODO add size task, see also build/sizer.js - copy from core grunt.js +// TODO add themes download task, part of release_cdn task diff --git a/version.txt b/version.txt deleted file mode 100644 index 13c1a7371..000000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -1.9pre |