Skip to content

Commit 4121fc0

Browse files
committed
abstracted filename alteration, config options
1 parent d6f21b6 commit 4121fc0

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

build/tasks/plugin.json.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"docs": "http://jquerymobile.com/demos/",
2626
"download": "http://jquerymobile.com/download/",
2727
"dependencies": {
28-
"jquery": ">=1.6.4"
29-
<%= dependencies %>
28+
"jquery": ">=1.6.4",
29+
"mobile.core", "<%= version %>"
3030
},
3131
"category": "widget"
3232
}

build/tasks/plugins.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,56 @@ var requirejs = require( 'requirejs' ),
55

66
module.exports = function( grunt ) {
77
grunt.registerTask( "plugins", function() {
8-
var global_config = grunt.config.get( 'global' ),
9-
done = this.async(),
10-
output = global_config.plugins.output;
8+
var globalConfig = pluginConfig = grunt.config.get( 'global' ),
9+
pluginConfig = globalConfig.plugins,
10+
done = this.async(), filenameToPlugin;
11+
12+
filenameToPlugin = function( filename ) {
13+
var pathless = filename.replace( /js\//, "" ),
14+
newFilename, template;
15+
16+
// if the file is one of the old convention top level
17+
// just strip the js dir, otherwise use the directory
18+
// names for namespaces
19+
if( /jquery\.mobile/.test( filename )){
20+
newFilename = pathless;
21+
} else {
22+
newFilename = pathless.split("/").join(".");
23+
}
24+
25+
return "mobile." + newFilename
26+
.replace( "jquery.mobile.", "" )
27+
.replace( ".js", ".jquery.json" );
28+
};
1129

1230
requirejs.tools.useLib( function ( require ) {
1331
require( [ 'parse' ], function ( parse ) {
1432
// grab all the files that still use the original convention
1533
var files = [], distFiles;
1634

17-
global_config.plugins.globs.forEach(function( globstr ) {
35+
pluginConfig.globs.forEach(function( globstr ) {
1836
// glob glob glob ... namespace fail
1937
files = files.concat( glob.glob( globstr ) );
2038
});
2139

2240
files.forEach( function( filename, i ) {
41+
if( pluginConfig.exclude.test(filename) ) {
42+
return;
43+
}
44+
2345
var data = fs.readFileSync( filename, 'utf8' ),
2446
tree = parse.findDependencies( filename, data ),
25-
pathless = filename.replace( /js\//, "" ),
26-
newFilename, manifest, template;
27-
28-
// TODO splitting this out using the above globs would be faster/better
29-
if( /jquery\.mobile/.test( filename )){
30-
newFilename = pathless;
31-
grunt.file.copy( filename, output + newFilename );
32-
} else {
33-
newFilename = "jquery.mobile." + pathless.split("/").join(".");
34-
grunt.file.copy( filename, output + newFilename );
35-
}
47+
manifest, template;
48+
49+
template = grunt.file.read( pluginConfig.template );
50+
51+
manifest = filenameToPlugin( filename );
3652

37-
manifest = "dist." + newFilename.replace( ".js", ".json" );
38-
template = grunt.file.read( global_config.plugins.template );
3953
grunt.file.write( manifest, grunt.template.process( template, {
40-
name: "foo",
41-
title: "bar",
42-
desc: "baz",
43-
version: global_config.ver.official,
44-
dependencies: ""
54+
name: filename.replace(".json", ""),
55+
title: "TODO",
56+
desc: "TODO",
57+
version: globalConfig.ver.official
4558
}));
4659
});
4760
});

grunt.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ module.exports = function( grunt ) {
168168

169169
plugins: {
170170
template: "build/tasks/plugin.json.ejs",
171-
output: "dist/",
171+
172172
globs: [
173-
"./js/jquery.mobile.*.js",
174-
"./js/*/**/*.js"
175-
]
173+
"./js/widgets/**/*.js",
174+
"./js/events/**/*.js",
175+
"./js/*.buttonMarkup.js",
176+
"./js/*.vmouse.js"
177+
],
178+
179+
exclude: /docs|define|autodividers|listview\.filter/
176180
}
177181
}
178182
});

0 commit comments

Comments
 (0)