Skip to content

Commit 70f7a2f

Browse files
committed
move concat config into config.js, remove old helpers
1 parent 53fdfed commit 70f7a2f

File tree

4 files changed

+143
-149
lines changed

4 files changed

+143
-149
lines changed

build/config.js

Lines changed: 140 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,107 +4,172 @@ var fs = require( 'fs' ),
44
glob = require( 'glob-whatev' );
55

66
module.exports = function( grunt ) {
7-
var global = {
8-
dirs : {
9-
output: 'compiled',
10-
temp: 'tmp'
11-
},
7+
var dirs, names;
128

13-
files: {
14-
license: 'LICENSE-INFO.txt'
15-
},
9+
dirs = {
10+
output: 'compiled',
11+
temp: 'tmp'
12+
};
1613

17-
names: {
18-
base: 'jquery.mobile',
19-
// this will change for the deploy target to include version information
20-
root: 'jquery.mobile',
21-
structure: 'jquery.mobile.structure',
22-
theme: 'jquery.mobile.theme'
23-
},
14+
names= {
15+
base: 'jquery.mobile',
16+
// this will change for the deploy target to include version information
17+
root: 'jquery.mobile',
18+
structure: 'jquery.mobile.structure',
19+
theme: 'jquery.mobile.theme'
20+
};
2421

25-
// other version information is added via the asyncConfig helper that
26-
// depends on git commands (eg ver.min, ver.header)
27-
ver: {
28-
official: grunt.file.read( 'version.txt' ).replace(/\n/, ''),
29-
min: "/*! jQuery Mobile v<%= build_sha %> jquerymobile.com | jquery.org/license !*/"
22+
function outputPath( name ){
23+
return path.join( dirs.output, name );
24+
}
25+
26+
// Project configuration.
27+
grunt.config.init({
28+
jshint: {
29+
options: {
30+
curly: true,
31+
eqeqeq: true,
32+
33+
// (function(){})() seems acceptable
34+
immed: false,
35+
latedef: true,
36+
newcap: true,
37+
noarg: true,
38+
sub: true,
39+
undef: true,
40+
boss: true,
41+
eqnull: true,
42+
browser: true
43+
},
44+
globals: {
45+
jQuery: true,
46+
"$": true,
47+
48+
// qunit globals
49+
// TODO would be nice to confine these to test files
50+
module: true,
51+
ok: true,
52+
test: true,
53+
asyncTest: true,
54+
same: true,
55+
start: true,
56+
stop: true,
57+
expect: true,
58+
59+
// require js global
60+
define: true
61+
}
3062
},
3163

32-
shas: {},
64+
lint: {
65+
files: ['grunt.js', 'js/*.js', 'tests/**/*.js']
66+
},
3367

34-
helpers: {
35-
// in place
36-
sed: function( file, filter ) {
37-
var id, inputString = fs.readFileSync(file).toString();
68+
// NOTE these configuration settings are used _after_ compilation has taken place
69+
// using requirejs. Thus the .compiled extensions. The exception being the theme concat
70+
concat: {
71+
js: {
72+
src: [ '<banner:global.ver.header>', outputPath( names.root ) + '.compiled.js' ],
73+
dest: outputPath( names.root ) + '.js'
74+
},
3875

39-
inputString = filter ? filter(inputString) : inputString;
76+
structure: {
77+
src: [ '<banner:global.ver.header>', outputPath( names.structure ) + '.compiled.css' ],
78+
dest: outputPath( names.structure ) + '.css'
79+
},
4080

41-
grunt.file.write( file, inputString );
81+
regular: {
82+
src: [ '<banner:global.ver.header>', outputPath( names.root ) + '.compiled.css' ],
83+
dest: outputPath( names.root ) + '.css'
4284
},
4385

44-
configExtend: function( prop, extension ) {
45-
var config = grunt.config.get( prop ) || {};
86+
theme: {
87+
src: [
88+
'<banner:global.ver.header>',
89+
'css/themes/default/jquery.mobile.theme.css'
90+
],
91+
dest: outputPath( names.theme ) + '.css'
92+
}
93+
},
94+
95+
global: {
96+
dirs: dirs,
4697

47-
for( p in extension ){
48-
config[p] = extension[p];
49-
}
98+
names: names,
5099

51-
grunt.config.set( prop, config );
100+
files: {
101+
license: 'LICENSE-INFO.txt'
52102
},
53103

54-
// NOTE cargo culting my way to the top :(
55-
rmdirRecursive: function(dir) {
56-
if( !path.existsSync(dir) ) {
57-
return;
58-
}
59-
60-
var list = fs.readdirSync(dir);
61-
for(var i = 0; i < list.length; i++) {
62-
var filename = path.join(dir, list[i]);
63-
var stat = fs.statSync(filename);
64-
65-
if(filename == "." || filename == "..") {
66-
// pass these files
67-
} else if(stat.isDirectory()) {
68-
// rmdir recursively
69-
this.rmdirRecursive(filename);
70-
} else {
71-
// rm fiilename
72-
fs.unlinkSync(filename);
73-
}
74-
}
75-
fs.rmdirSync(dir);
104+
// other version information is added via the asyncConfig helper that
105+
// depends on git commands (eg ver.min, ver.header)
106+
ver: {
107+
official: grunt.file.read( 'version.txt' ).replace(/\n/, ''),
108+
min: "/*! jQuery Mobile v<%= build_sha %> jquerymobile.com | jquery.org/license !*/"
76109
},
77110

78-
asyncConfig: function( callback ) {
79-
child_process.exec( 'git log -1 --format=format:"Git Build: SHA1: %H <> Date: %cd"', function( err, stdout, stderr ){
80-
global.shas.build_sha = stdout;
81-
global.ver.min = grunt.template.process( global.ver.min, global.shas );
111+
shas: {},
82112

83-
child_process.exec( 'git log -1 --format=format:"%H"', function( err, stdout, stderr ) {
84-
global.shas.head_sha = stdout;
113+
helpers: {
114+
// in place file alteration
115+
sed: function( file, filter ) {
116+
var id, inputString = fs.readFileSync(file).toString();
85117

86-
// NOTE not using a template here because the Makefile depends on the v@VERSION
87-
global.ver.header = grunt.file.read( global.files.license )
88-
.replace(/v@VERSION/, global.shas.build_sha );
89-
callback( global );
90-
});
91-
});
118+
inputString = filter ? filter(inputString) : inputString;
119+
120+
grunt.file.write( file, inputString );
121+
},
122+
123+
// NOTE cargo culting my way to the top :(
124+
rmdirRecursive: function(dir) {
125+
if( !path.existsSync(dir) ) {
126+
return;
127+
}
128+
129+
var list = fs.readdirSync(dir);
130+
for(var i = 0; i < list.length; i++) {
131+
var filename = path.join(dir, list[i]);
132+
var stat = fs.statSync(filename);
133+
134+
if(filename == "." || filename == "..") {
135+
// pass these files
136+
} else if(stat.isDirectory()) {
137+
// rmdir recursively
138+
this.rmdirRecursive(filename);
139+
} else {
140+
// rm fiilename
141+
fs.unlinkSync(filename);
142+
}
143+
}
144+
fs.rmdirSync(dir);
145+
}
92146
}
93147
}
94-
};
95-
96-
grunt.config.set( 'global', global );
148+
});
97149

98150
grunt.registerTask( 'config:async', 'git hashes for output headers', function() {
99-
var done = this.async();
151+
var done = this.async(), global = grunt.config.get( 'global' );
100152

101-
grunt.config.get( 'global' ).helpers.asyncConfig(function(config) {
102-
grunt.config.set( 'global', config );
103-
done();
153+
child_process.exec( 'git log -1 --format=format:"Git Build: SHA1: %H <> Date: %cd"', function( err, stdout, stderr ){
154+
global.shas.build_sha = stdout;
155+
global.ver.min = grunt.template.process( global.ver.min, global.shas );
156+
157+
child_process.exec( 'git log -1 --format=format:"%H"', function( err, stdout, stderr ) {
158+
global.shas.head_sha = stdout;
159+
160+
// NOTE not using a template here because the Makefile depends on the v@VERSION
161+
global.ver.header = grunt.file.read( global.files.license )
162+
.replace(/v@VERSION/, global.shas.build_sha );
163+
164+
grunt.config.set( 'global', global );
165+
done();
166+
});
104167
});
105168
});
106169

107-
grunt.registerTask( 'test:config', 'glob all the test files', function() {
170+
// TODO could use some cleanup. Eg, can we use grunt's parameter passing functionality
171+
// in place of environment variables
172+
grunt.registerTask( 'config:test', 'glob all the test files', function() {
108173
var done = this.async(), test_paths, server_paths = [], env = process.env;
109174

110175

build/tasks/css.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ module.exports = function( grunt ) {
2929
}
3030
});
3131

32-
helpers.configExtend( 'concat', {
33-
structure: {
34-
src: [ '<banner:global.ver.header>', structureFile + '.compiled.css' ],
35-
dest: structureFile + '.css'
36-
},
37-
38-
regular: {
39-
src: [ '<banner:global.ver.header>', regularFile + '.compiled.css' ],
40-
dest: regularFile + '.css'
41-
},
42-
43-
theme: {
44-
src: [
45-
'<banner:global.ver.header>',
46-
'css/themes/default/jquery.mobile.theme.css'
47-
],
48-
dest: themeFile + '.css'
49-
}
50-
});
51-
5232
// setup css min configuration
5333
cssmin[ regularFile + '.min.css' ] = [ "<banner:global.ver.min>", regularFile + '.css' ];
5434
cssmin[ structureFile + '.min.css' ] = [ "<banner:global.ver.min>", structureFile + '.css' ];

build/tasks/js.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ module.exports = function( grunt ) {
2727
}
2828
});
2929

30-
helpers.configExtend( 'concat', {
31-
js: {
32-
src: [ '<banner:global.ver.header>', outputFile + '.compiled.js' ],
33-
dest: outputFile + '.js'
34-
}
35-
});
36-
3730
// setup minification
3831
min[ outputFile + '.min.js' ] = [ "<banner:global.ver.min>", outputFile + '.js' ];
3932
grunt.config.set( 'min', min );

grunt.js

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,8 @@
11
var path = require( 'path' );
22

33
module.exports = function( grunt ) {
4-
5-
// Project configuration.
6-
grunt.config.init({
7-
jshint: {
8-
options: {
9-
curly: true,
10-
eqeqeq: true,
11-
12-
// (function(){})() seems acceptable
13-
immed: false,
14-
latedef: true,
15-
newcap: true,
16-
noarg: true,
17-
sub: true,
18-
undef: true,
19-
boss: true,
20-
eqnull: true,
21-
browser: true
22-
},
23-
globals: {
24-
jQuery: true,
25-
"$": true,
26-
27-
// qunit globals
28-
// TODO would be nice to confine these to test files
29-
module: true,
30-
ok: true,
31-
test: true,
32-
asyncTest: true,
33-
same: true,
34-
start: true,
35-
stop: true,
36-
expect: true,
37-
38-
// require js global
39-
define: true
40-
}
41-
},
42-
43-
lint: {
44-
files: ['grunt.js', 'js/*.js', 'tests/**/*.js']
45-
}
46-
});
4+
// load the project wide config before loading the tasks
5+
require( path.resolve('build/config') )( grunt );
476

487
// set the default task.
498
grunt.registerTask('default', 'lint');
@@ -52,10 +11,7 @@ module.exports = function( grunt ) {
5211
grunt.loadNpmTasks( "grunt-css" );
5312

5413
// A convenient task alias.
55-
grunt.registerTask('test', 'test:config qunit');
56-
57-
// load the project wide config before loading the tasks
58-
require( path.resolve(path.join('build', 'config')) )( grunt );
14+
grunt.registerTask('test', 'config:test qunit');
5915

6016
// load the project's default tasks
6117
grunt.loadTasks( path.join('build', 'tasks') );

0 commit comments

Comments
 (0)