jquery-ui/Gruntfile.js

256 lines
5.7 KiB
JavaScript
Raw Normal View History

2012-03-23 17:33:46 +00:00
module.exports = function( grunt ) {
"use strict";
var
// files
coreFiles = [
"jquery.ui.core.js",
"jquery.ui.widget.js",
"jquery.ui.mouse.js",
"jquery.ui.draggable.js",
"jquery.ui.droppable.js",
"jquery.ui.resizable.js",
"jquery.ui.selectable.js",
"jquery.ui.sortable.js",
2012-06-15 16:47:12 +00:00
"jquery.ui.effect.js"
],
uiFiles = coreFiles.map(function( file ) {
return "ui/" + file;
}).concat( expandFiles( "ui/*.js" ).filter(function( file ) {
return coreFiles.indexOf( file.substring(3) ) === -1;
})),
allI18nFiles = expandFiles( "ui/i18n/*.js" ),
cssFiles = [
"core",
"accordion",
"autocomplete",
"button",
"datepicker",
"dialog",
"menu",
"progressbar",
"resizable",
"selectable",
"slider",
"spinner",
"tabs",
"tooltip",
"theme"
].map(function( component ) {
return "themes/base/jquery.ui." + component + ".css";
}),
// minified files
minify = {
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 = {
options: {
keepSpecialComments: 0
},
main: {
options: {
keepSpecialComments: "*"
},
src: "dist/jquery-ui.css",
dest: "dist/jquery-ui.min.css"
}
},
compareFiles = {
all: [
"dist/jquery-ui.js",
"dist/jquery-ui.min.js"
]
};
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[ file ] = {
options: {
banner: createBanner()
},
files: {}
};
minify[ file ].files[ mapMinFile( file ) ] = file;
});
cssFiles.forEach(function( 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-contrib-csslint" );
grunt.loadNpmTasks( "grunt-contrib-cssmin" );
grunt.loadNpmTasks( "grunt-html" );
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-git-authors" );
// local testswarm and build tasks
2012-06-14 13:37:53 +00:00
grunt.loadTasks( "build/tasks" );
2012-03-19 21:12:21 +00:00
function stripDirectory( file ) {
return file.replace( /.+\/(.+?)>?$/, "$1" );
}
2012-03-19 21:12:21 +00:00
function createBanner( files ) {
// strip folders
var fileNames = files && files.map( stripDirectory );
return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
2012-03-23 17:33:46 +00:00
"<%= grunt.template.today('isoDate') %>\n" +
"<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
(files ? "* Includes: " + fileNames.join(", ") + "\n" : "")+
2012-08-09 14:13:24 +00:00
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
}
2012-03-19 21:12:21 +00:00
2012-03-23 17:33:46 +00:00
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
2012-03-19 21:12:21 +00:00
files: {
dist: "<%= pkg.name %>-<%= pkg.version %>"
2012-03-19 21:12:21 +00:00
},
compare_size: compareFiles,
2012-03-19 21:12:21 +00:00
concat: {
ui: {
options: {
banner: createBanner( uiFiles ),
stripBanners: {
block: true
}
},
src: uiFiles,
2012-03-19 21:12:21 +00:00
dest: "dist/jquery-ui.js"
},
i18n: {
options: {
banner: createBanner( allI18nFiles )
},
src: allI18nFiles,
2012-03-19 21:12:21 +00:00
dest: "dist/i18n/jquery-ui-i18n.js"
},
css: {
options: {
banner: createBanner( cssFiles ),
stripBanners: {
block: true
}
},
src: cssFiles,
2012-03-19 21:12:21 +00:00
dest: "dist/jquery-ui.css"
}
},
uglify: minify,
cssmin: minifyCSS,
htmllint: {
// ignore files that contain invalid html, used only for ajax content testing
all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core\.html)/.test( file );
})
},
2012-03-19 21:12:21 +00:00
copy: {
dist_units_images: {
src: "themes/base/images/*",
strip: /^themes\/base\//,
dest: "dist/"
2012-03-19 21:12:21 +00:00
}
},
qunit: {
files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
2012-03-19 21:12:21 +00:00
// 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|tooltip)\.html$/ ).test( file );
2012-03-19 21:12:21 +00:00
})
},
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"
}
}
2012-03-19 21:12:21 +00:00
},
csslint: {
base_theme: {
src: "themes/base/*.css",
options: {
csslintrc: ".csslintrc"
2012-03-19 21:12:21 +00:00
}
}
}
});
grunt.registerTask( "default", [ "lint", "test" ] );
grunt.registerTask( "lint", [ "asciilint", "jshint", "csslint", "htmllint" ] );
grunt.registerTask( "test", [ "qunit" ] );
grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] );
grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] );
// "copy:dist_units_images" is used by unit tests
grunt.registerTask( "build", [ "concat", "uglify", "cssmin", "copy:dist_units_images" ] );
2012-03-23 17:33:46 +00:00
};