2012-06-08 15:35:11 +00:00
|
|
|
module.exports = function( grunt ) {
|
|
|
|
|
2012-10-22 21:41:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
2012-07-06 00:11:52 +00:00
|
|
|
grunt.registerTask( "manifest", "Generate jquery.json manifest files", function() {
|
2014-05-08 18:57:19 +00:00
|
|
|
var uiFiles,
|
|
|
|
totalManifests = 0,
|
|
|
|
pkg = grunt.config( "pkg" ),
|
2012-07-06 00:11:52 +00:00
|
|
|
base = {
|
|
|
|
core: {
|
|
|
|
name: "ui.{plugin}",
|
2012-07-16 12:50:00 +00:00
|
|
|
title: "jQuery UI {Plugin}"
|
2012-07-06 00:11:52 +00:00
|
|
|
},
|
2012-07-16 12:50:00 +00:00
|
|
|
widget: {
|
2012-07-06 00:11:52 +00:00
|
|
|
name: "ui.{plugin}",
|
|
|
|
title: "jQuery UI {Plugin}",
|
2012-07-16 12:50:00 +00:00
|
|
|
dependencies: [ "core", "widget" ]
|
2012-07-06 00:11:52 +00:00
|
|
|
},
|
2012-07-16 12:53:34 +00:00
|
|
|
interaction: {
|
|
|
|
name: "ui.{plugin}",
|
|
|
|
title: "jQuery UI {Plugin}",
|
|
|
|
dependencies: [ "core", "widget", "mouse" ]
|
|
|
|
},
|
2012-07-16 12:50:00 +00:00
|
|
|
effect: {
|
2012-07-06 00:11:52 +00:00
|
|
|
name: "ui.effect-{plugin}",
|
|
|
|
title: "jQuery UI {Plugin} Effect",
|
|
|
|
keywords: [ "effect", "show", "hide" ],
|
2013-04-26 16:09:00 +00:00
|
|
|
homepage: "http://jqueryui.com/effect/",
|
|
|
|
demo: "http://jqueryui.com/effect/",
|
2012-07-06 00:11:52 +00:00
|
|
|
docs: "http://api.jqueryui.com/{plugin}-effect/",
|
2012-07-16 12:50:00 +00:00
|
|
|
dependencies: [ "effect" ]
|
2012-07-06 00:11:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys( base ).forEach(function( type ) {
|
|
|
|
var baseManifest = base[ type ],
|
2014-02-04 14:16:26 +00:00
|
|
|
plugins = grunt.file.readJSON( "build/" + type + ".json" ),
|
|
|
|
bower = grunt.file.readJSON( "bower.json" );
|
2012-07-06 00:11:52 +00:00
|
|
|
|
|
|
|
Object.keys( plugins ).forEach(function( plugin ) {
|
2014-05-07 20:39:21 +00:00
|
|
|
var manifest, bowerKey,
|
2012-07-06 00:11:52 +00:00
|
|
|
data = plugins[ plugin ],
|
|
|
|
name = plugin.charAt( 0 ).toUpperCase() + plugin.substr( 1 );
|
|
|
|
|
|
|
|
function replace( str ) {
|
|
|
|
return str.replace( "{plugin}", plugin ).replace( "{Plugin}", name );
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest = {
|
2012-07-16 19:14:42 +00:00
|
|
|
name: data.name || replace( baseManifest.name ),
|
2012-07-06 16:39:17 +00:00
|
|
|
title: data.title || replace( baseManifest.title ),
|
2012-07-06 00:11:52 +00:00
|
|
|
description: data.description,
|
|
|
|
keywords: [ "ui", plugin ]
|
|
|
|
.concat( baseManifest.keywords || [] )
|
|
|
|
.concat( data.keywords || [] ),
|
|
|
|
version: pkg.version,
|
|
|
|
author: pkg.author,
|
|
|
|
maintainers: pkg.maintainers,
|
2012-07-06 16:47:44 +00:00
|
|
|
licenses: pkg.licenses,
|
2012-07-06 00:11:52 +00:00
|
|
|
bugs: pkg.bugs,
|
|
|
|
homepage: data.homepage || replace( baseManifest.homepage ||
|
|
|
|
"http://jqueryui.com/{plugin}/" ),
|
|
|
|
demo: data.demo || replace( baseManifest.demo ||
|
|
|
|
"http://jqueryui.com/{plugin}/" ),
|
|
|
|
docs: data.docs || replace( baseManifest.docs ||
|
|
|
|
"http://api.jqueryui.com/{plugin}/" ),
|
|
|
|
download: "http://jqueryui.com/download/",
|
2014-05-07 20:39:21 +00:00
|
|
|
dependencies: {},
|
2012-07-16 12:50:00 +00:00
|
|
|
// custom
|
|
|
|
category: data.category || type
|
2012-07-06 00:11:52 +00:00
|
|
|
};
|
|
|
|
|
2014-05-07 20:39:21 +00:00
|
|
|
for ( bowerKey in bower.dependencies ) {
|
|
|
|
manifest.dependencies[ bowerKey ] = bower.dependencies[ bowerKey ];
|
|
|
|
}
|
|
|
|
|
2012-07-06 00:11:52 +00:00
|
|
|
(baseManifest.dependencies || [])
|
|
|
|
.concat(data.dependencies || [])
|
|
|
|
.forEach(function( dependency ) {
|
|
|
|
manifest.dependencies[ "ui." + dependency ] = pkg.version;
|
|
|
|
});
|
|
|
|
|
2012-07-09 14:19:17 +00:00
|
|
|
grunt.file.write( manifest.name + ".jquery.json",
|
2012-07-19 21:14:47 +00:00
|
|
|
JSON.stringify( manifest, null, "\t" ) + "\n" );
|
2014-05-08 18:57:19 +00:00
|
|
|
totalManifests += 1;
|
2012-07-06 00:11:52 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-08 18:57:19 +00:00
|
|
|
|
|
|
|
uiFiles = grunt.file.expand( "ui/*.js" ).length;
|
|
|
|
if ( totalManifests !== uiFiles ) {
|
|
|
|
grunt.log.error( "Generated " + totalManifests + " manifest files, but there are " +
|
|
|
|
uiFiles + " ui/*.js files. Do all of them have entries?" );
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-06 00:11:52 +00:00
|
|
|
});
|
|
|
|
|
2012-06-16 12:36:57 +00:00
|
|
|
grunt.registerTask( "clean", function() {
|
|
|
|
require( "rimraf" ).sync( "dist" );
|
|
|
|
});
|
|
|
|
|
2013-06-14 07:01:02 +00:00
|
|
|
grunt.registerTask( "asciilint", function() {
|
|
|
|
var valid = true,
|
|
|
|
files = grunt.file.expand({ filter: "isFile" }, "ui/*.js" );
|
|
|
|
files.forEach(function( filename ) {
|
|
|
|
var i, c,
|
|
|
|
text = grunt.file.read( filename );
|
|
|
|
|
|
|
|
// Ensure files use only \n for line endings, not \r\n
|
|
|
|
if ( /\x0d\x0a/.test( text ) ) {
|
|
|
|
grunt.log.error( filename + ": Incorrect line endings (\\r\\n)" );
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure only ASCII chars so script tags don't need a charset attribute
|
|
|
|
if ( text.length !== Buffer.byteLength( text, "utf8" ) ) {
|
|
|
|
grunt.log.error( filename + ": Non-ASCII characters detected:" );
|
|
|
|
for ( i = 0; i < text.length; i++ ) {
|
|
|
|
c = text.charCodeAt( i );
|
|
|
|
if ( c > 127 ) {
|
|
|
|
grunt.log.error( "- position " + i + ": " + c );
|
|
|
|
grunt.log.error( "-- " + text.substring( i - 20, i + 20 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if ( valid ) {
|
|
|
|
grunt.log.ok( files.length + " files lint free." );
|
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
});
|
|
|
|
|
2012-09-13 13:50:43 +00:00
|
|
|
};
|