Skip to content
Permalink
Browse files

Build: Migrate to grunt 0.4. Rename to Gruntfile, upgrade to newer gr…

…unt-css and grunt-html, update custom tasks. Drop qunit-junit plugin, not worth the trouble. Update release script to run grunt-prepare after npm-install.
  • Loading branch information
jzaefferer committed Dec 21, 2012
1 parent 4d67f4f commit f87b4e0f4ac2342dff260c32aa8d08148e76f7a4
Showing with 153 additions and 111 deletions.
  1. +116 −76 grunt.js → Gruntfile.js
  2. +3 −0 build/release/release.js
  3. +24 −28 build/tasks/build.js
  4. +10 −7 package.json
@@ -18,11 +18,11 @@ var

uiFiles = coreFiles.map(function( file ) {
return "ui/" + file;
}).concat( grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
}).concat( expandFiles( "ui/*.js" ).filter(function( file ) {
return coreFiles.indexOf( file.substring(3) ) === -1;
})),

allI18nFiles = grunt.file.expandFiles( "ui/i18n/*.js" ),
allI18nFiles = expandFiles( "ui/i18n/*.js" ),

cssFiles = [
"core",
@@ -46,16 +46,42 @@ var

// minified files
minify = {
"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" ]
options: {
preserveComments: false
},
main: {
options: {
banner: createBanner( uiFiles )
},
files: {
"dist/jquery-ui.min.js": "dist/jquery-ui.js"
}
},
i18n: {
options: {
banner: createBanner( allI18nFiles )
},
files: {
"dist/i18n/jquery-ui-i18n.min.js": "dist/i18n/jquery-ui-i18n.js"
}
}
},

minifyCSS = {
"dist/jquery-ui.min.css": "dist/jquery-ui.css"
options: {
keepSpecialComments: 0
},
main: {
options: {
keepSpecialComments: '*'
},
src: "dist/jquery-ui.css",
dest: "dist/jquery-ui.min.css"
}
},

compareFiles = {
all: [
files: [
"dist/jquery-ui.js",
"dist/jquery-ui.min.js"
]
@@ -65,85 +91,102 @@ function mapMinFile( file ) {
return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
}

function expandFiles( files ) {
return grunt.util._.pluck( grunt.file.expandMapping( files ), "src" ).map(function( values ) {
return values[ 0 ];
});
}

uiFiles.concat( allI18nFiles ).forEach(function( file ) {
minify[ mapMinFile( file ) ] = [ "<banner>", file ];
minify[ file ] = {
options: {
banner: createBanner()
},
files: {}
};
minify[ file ].files[ mapMinFile( file ) ] = file;
});

cssFiles.forEach(function( file ) {
minifyCSS[ "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" ) ] = [ "<banner>", "<strip_all_banners:" + file + ">" ];
minifyCSS[ file ] = {
options: {
banner: createBanner()
},
src: file,
dest: "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" )
};
});

uiFiles.forEach(function( file ) {
// TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
compareFiles[ file ] = [ file, mapMinFile( file ) ];
});

// grunt plugins
grunt.loadNpmTasks( "grunt-contrib-jshint" );
grunt.loadNpmTasks( "grunt-contrib-uglify" );
grunt.loadNpmTasks( "grunt-contrib-concat" );
grunt.loadNpmTasks( "grunt-contrib-qunit" );
grunt.loadNpmTasks( "grunt-css" );
grunt.loadNpmTasks( "grunt-html" );
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-junit" );
grunt.loadNpmTasks( "grunt-git-authors" );
// local testswarm and build tasks
grunt.loadTasks( "build/tasks" );

grunt.registerHelper( "strip_all_banners", function( filepath ) {
return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" );
});

function stripBanner( files ) {
return files.map(function( file ) {
return "<strip_all_banners:" + file + ">";
});
}

function stripDirectory( file ) {
// TODO: we're receiving the directive, so we need to strip the trailing >
// we should be receving a clean path without the directive
return file.replace( /.+\/(.+?)>?$/, "$1" );
}
// allow access from banner template
global.stripDirectory = stripDirectory;

function createBanner( files ) {
// strip folders
var fileNames = files && files.map( stripDirectory );
return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
"<%= grunt.template.today('isoDate') %>\n" +
"<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" +
"* Includes: " + (files ? fileNames.join(", ") : "<%= stripDirectory(grunt.task.current.file.src[1]) %>") + "\n" +
"<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
(files ? "* Includes: " + fileNames.join(", ") + "\n" : "")+
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */";
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
}

grunt.initConfig({
pkg: "<json:package.json>",
pkg: grunt.file.readJSON("package.json"),
files: {
dist: "<%= pkg.name %>-<%= pkg.version %>",
cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
},
meta: {
banner: createBanner(),
bannerAll: createBanner( uiFiles ),
bannerI18n: createBanner( allI18nFiles ),
bannerCSS: createBanner( cssFiles )
},
compare_size: compareFiles,
concat: {
ui: {
src: [ "<banner:meta.bannerAll>", stripBanner( uiFiles ) ],
options: {
banner: createBanner( uiFiles ),
stripBanners: {
block: true
}
},
src: uiFiles,
dest: "dist/jquery-ui.js"
},
i18n: {
src: [ "<banner:meta.bannerI18n>", allI18nFiles ],
options: {
banner: createBanner( allI18nFiles )
},
src: allI18nFiles,
dest: "dist/i18n/jquery-ui-i18n.js"
},
css: {
src: [ "<banner:meta.bannerCSS>", stripBanner( cssFiles ) ],
options: {
banner: createBanner( cssFiles ),
stripBanners: {
block: true
}
},
src: cssFiles,
dest: "dist/jquery-ui.css"
}
},
min: minify,
uglify: minify,
cssmin: minifyCSS,
htmllint: {
// ignore files that contain invalid html, used only for ajax content testing
@@ -158,7 +201,7 @@ grunt.initConfig({
"jquery-*.js",
"MIT-LICENSE.txt",
"README.md",
"grunt.js",
"Gruntfile.js",
"package.json",
"*.jquery.json",
"ui/**/*",
@@ -278,22 +321,43 @@ grunt.initConfig({
}
},
qunit: {
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go
return !( /(all|index|test|dialog|dialog_deprecated|tabs|tooltip)\.html$/ ).test( file );
})
},
lint: {
ui: "ui/*.js",
grunt: [ "grunt.js", "build/**/*.js" ],
tests: "tests/unit/**/*.js"
jshint: {
ui: {
options: {
jshintrc: "ui/.jshintrc"
},
files: {
src: "ui/*.js"
}
},
grunt: {
options: {
jshintrc: ".jshintrc"
},
files: {
src: [ "Gruntfile.js", "build/**/*.js" ]
}
},
tests: {
options: {
jshintrc: "tests/.jshintrc"
},
files: {
src: "tests/unit/**/*.js"
}
}
},
csslint: {
// nothing: []
// TODO figure out what to check for, then fix and enable
base_theme: {
src: grunt.file.expandFiles( "themes/base/*.css" ).filter(function( file ) {
src: expandFiles( "themes/base/*.css" ).filter(function( file ) {
// TODO remove items from this list once rewritten
return !( /(button|datepicker|core|dialog|theme)\.css$/ ).test( file );
}),
@@ -307,39 +371,15 @@ grunt.initConfig({
"compatible-vendor-prefixes": false
}
}
},
jshint: (function() {
function parserc( path ) {
var rc = grunt.file.readJSON( (path || "") + ".jshintrc" ),
settings = {
options: rc,
globals: {}
};

(rc.predef || []).forEach(function( prop ) {
settings.globals[ prop ] = true;
});
delete rc.predef;

return settings;
}

return {
grunt: parserc(),
ui: parserc( "ui/" ),
// TODO: `evil: true` is only for document.write() https://github.com/jshint/jshint/issues/519
// TODO: don't create so many globals in tests
tests: parserc( "tests/" )
};
})()
}
});

grunt.registerTask( "default", "lint csslint htmllint qunit" );
grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size:all" );
grunt.registerTask( "sizer_all", "concat:ui min compare_size" );
grunt.registerTask( "build", "concat min cssmin copy:dist_units_images" );
grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" );
grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes" );
grunt.registerTask( "release_cdn", "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_min_images copy:cdn_themes md5:cdn zip:cdn" );
grunt.registerTask( "default", [ "jshint", "csslint", "htmllint", "qunit" ] );
grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] );
grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] );
grunt.registerTask( "build", [ "concat", "uglify", "cssmin", "copy:dist_units_images" ] );
grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist".split( " " ) );
grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes".split( " " ) );
grunt.registerTask( "release_cdn", "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_min_images copy:cdn_themes md5:cdn zip:cdn".split( " " ) );

};
@@ -72,6 +72,9 @@ function cloneRepo() {
if ( exec( "npm install download.jqueryui.com" ).code !== 0 ) {
abort( "Error installing dependencies." );
}
if ( exec( "cd node_modules/download.jqueryui.com && grunt prepare" ).code !== 0 ) {
abort( "Error installing dependencies." );
}
}
echo();
}

0 comments on commit f87b4e0

Please sign in to comment.
You can’t perform that action at this time.