forked from senchalabs/jQTouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrunt.js
345 lines (312 loc) · 11.2 KB
/
grunt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*global module:false*/
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib');
grunt.loadNpmTasks('grunt-coverjs');
grunt.loadNpmTasks('grunt-text-replace');
grunt.registerTask('intro', 'Introduction to build', function() {
grunt.log.write('We are going to build a jQTouch release!');
});
grunt.registerMultiTask('compass', 'Compile sass with compass', function() {
/* roll our own, because I couldn't find -l options to the `contrib` version */
var cb = this.async(); // Tell grunt the task is async
var options = this.data['options'] || {};
var params = grunt.template.process(this.data['params']);
var exec = require('child_process').exec;
console.log('compass ' + params + '');
var child = exec('compass ' + params + '', options, function(error, stdout, stderr) {
if (!!stdout) {
console.log('stdout: ' + stdout);
}
if (error !== null) {
console.log('error: ' + error);
console.log('stderr: ' + stdout);
}
cb(); // Execute the callback when the async task is done
});
});
grunt.registerMultiTask('rake', 'Compile a Ruby Package with Rake', function() {
var cb = this.async(); // Tell grunt the task is async
var options = this.data['options'];
var params = grunt.template.process(this.data['params']);
var exec = require('child_process').exec;
var child = exec('rake ' + params + '', options, function(error, stdout, stderr) {
if (!!stdout) {
console.log('stdout: ' + stdout);
}
if (error !== null) {
console.log('error: ' + error);
console.log('stderr: ' + stdout);
}
cb(); // Execute the callback when the async task is done
});
});
grunt.registerMultiTask('gitmodule', 'Update git submodules', function() {
var cb = this.async(); // Tell grunt the task is async
var target = this.target || '';
var path = this.data['path'] || ('submodules/' + this.target);
var exec = require('child_process').exec;
var child = exec('git submodule update --init --recursive ' + path,
function(error, stdout, stderr) {
if (!!stdout) {
console.log('stdout: ' + stdout);
}
if (error !== null) {
console.log('error: ' + error);
console.log('stderr: ' + stdout);
}
cb(); // Execute the callback when the async task is done
}
);
});
grunt.registerMultiTask('minjs', 'Minify all JS in a directory', function() {
var target = this.target || '';
var options = this.data['options'];
var src = this.data['src'] || '*.js';
var dest = this.data['src'] || '*.min.js';
var banner = '';
if (options && options['banner']) {
banner = grunt.template.process(grunt.config.get('meta')['banner']);
}
grunt.file.expand({cwd: ''}, src).forEach(function(relpath) {
if (!/min.js$/g.test(relpath)) {
var dest = relpath.replace(/([\w-\.]*)\.js/g, '$1.min.js');
console.log('expanded: ' + relpath + ' dest: ' + dest);
var max = grunt.file.read(relpath);
var min = banner + grunt.helper('uglify', max, grunt.config('uglify'));
grunt.file.write(dest, min);
}
});
});
// Project configuration.
grunt
.initConfig({
pkg: '<json:package.json>',
meta: {
version: '<%= pkg.version %>-<%= pkg.versionId %>',
banner: '/*\n'
+ ' _/ _/_/ _/_/_/_/_/ _/ \n'
+ ' _/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/ \n'
+ ' _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/ \n'
+ ' _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n'
+ ' _/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/ \n'
+ ' _/ \n'
+ ' _/ \n'
+ ' Created by David Kaneda <http://www.davidkaneda.com> \n'
+ ' Maintained by Thomas Yip <http://beedesk.com/> \n'
+ ' Sponsored by Sencha Labs <http://www.sencha.com/> \n'
+ ' Special thanks to Jonathan Stark <http://www.jonathanstark.com/> \n'
+ ' \n'
+ ' Documentation and issue tracking on GitHub <http://github.com/senchalabs/jQTouch/> \n'
+ ' \n'
+ ' (c) 2009-<%= grunt.template.today("yyyy") %> Sencha Labs \n'
+ ' \n'
+ ' Version: <%= meta.version %> - <%= grunt.template.today("yyyy-mm-dd") %> \n'
+ ' \n'
+ ' jQTouch may be freely distributed under the MIT license. \n'
+ '*/\n'
},
dirs: {
src: 'src',
build: 'stage', /* change back to `build` when you port away from ant`. */
dist: 'jqtouch-<%= pkg.version %>-<%= pkg.versionId %>'
},
clean: {
zepto: ['zepto/lib'],
build: ['<%= dirs.build %>'],
css: ['<%= dirs.build %>/css'],
dist: ['<%= dirs.dist %>'],
excluded: [
'<%= dirs.dist %>/.gitignore',
'<%= dirs.dist %>/*.sublime-project',
'<%= dirs.dist %>/*.sublime-workspace',
'<%= dirs.dist %>/**/.DS_Store'
]
},
copy: {
prepare: {
files: {
'<%= dirs.build %>/': ['src/**', 'lib/**', 'themes/**',
'extensions/**', 'demos/**', 'versions/**', 'test/**', '*']
},
options: {
cwd: '',
excludeEmpty: false,
}
},
dist: {
files: {
'<%= dirs.dist %>/': ['<%= dirs.build %>/**']
},
options: {
cwd: '',
excludeEmpty: false,
}
},
zepto: {
files: {
'lib/zepto/': ['submodules/zepto/dist/**'],
'<%= dirs.build %>/src/jqtouch-jquery.js': ['submodules/zepto/src/touch.js'],
},
options: {
cwd: '',
excludeEmpty: false,
}
},
'jquery-bridge': {
files: {
'<%= dirs.build %>/src/jqtouch-jquery.js': ['submodules/zepto/src/touch.js']
},
options: {
cwd: '',
excludeEmpty: false,
}
},
checkin: { /* replace checkin version with updated css(es) */
files: {
'themes/css/': ['<%= dirs.dist %>/themes/css/**'],
'src/jqtouch-jquery.js': ['<%= dirs.dist %>/src/jqtouch-jquery.js']
},
options: {
cwd: '',
excludeEmpty: false,
}
},
htaccess: {
files: {
'<%= dirs.dist %>/.htaccess': ['<%= dirs.dist %>/sample.htaccess']
},
options: {
cwd: '',
excludeEmpty: false,
}
}
},
replace: {
'jquery-bridge': {
src: ['<%= dirs.build %>/src/jqtouch-jquery.js'],
overwrite: true,
replacements: [{
from: /e\.touches/g,
to: '(e.originalEvent || e).touches'
},{
from: /\(Zepto\)/g,
to: '(jQuery)'
}]
},
distpath: {
src: ['<%= dirs.dist %>/**/*.html'],
overwrite: true,
replacements: [{
from: /([\w-\.]*)\.js/g,
to: '$1.min.js'
}, {
from: /([\w-\.]*)\.min\.min\.js/g,
to: '$1.min.js'
}]
},
'strip-warnings': {
src: ['<%= dirs.dist %>/src/jqtouch.js', '<%= dirs.dist %>/src/jqtouch.min.js'],
overwrite: true,
replacements: [{
from: /\n\s*warn\(.*/g,
to: ''
}]
}
},
gitmodule: {
zepto: {
},
recipes: {
path: 'submodules/compass-recipes'
}
},
rake: {
zepto: {
params: 'concat[fx:ajax:data:detect:event:form:polyfill:touch] dist',
options: {
cwd: 'submodules/zepto'
}
}
},
compass: {
all: {
params: 'compile -l <%= dirs.build %>/themes/compass-recipes/ --sass-dir <%= dirs.build %>/themes/scss --css-dir <%= dirs.build %>/themes/css --output-style compressed --environment production -q'
}
},
lint: {
files: ['src/jqtouch.js']
},
qunit: {
files: ['<%= dirs.build %>/test/unit/*.html']
},
concat: {
dist: {
src: ['<banner>', '<file_strip_banner:src/jqtouch.js>'],
dest: '<%= dirs.dist %>/src/jqtouch.js'
}
},
minjs: {
extensions: {
src: ['<%= dirs.dist %>/extensions/*.js'],
dest: '<%= dirs.dist %>/extensions/*.min.js',
options: {
banner: true
}
}
},
min: {
jqtouch: {
src: ['<%= dirs.dist %>/src/jqtouch.js'],
dest: '<%= dirs.dist %>/src/jqtouch.min.js'
},
'jquery-bridge': {
src: ['<%= dirs.dist %>/src/jqtouch-jquery.js'],
dest: '<%= dirs.dist %>/src/jqtouch-jquery.min.js'
},
'jquery-bridge2': {
src: ['<%= dirs.dist %>/src/jqtouch-jquery2.js'],
dest: '<%= dirs.dist %>/src/jqtouch-jquery2.min.js'
}
},
cover: {
compile: {
files: {
'<%= dirs.build %>/test/instrumented/jqtouch.js': ['src/jqtouch.js']
}
}
},
watch: {
files: '<%= dirs.build %>/themes/css',
tasks: 'compass'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
},
uglify: {}
});
// Tasks
grunt.registerTask('nuke', 'clean:build clean:dist');
grunt.registerTask('css', 'clean:css gitmodule:recipes compass');
grunt.registerTask('zepto', 'clean:zepto gitmodule:zepto rake:zepto copy:zepto');
grunt.registerTask('jquery-bridge', 'zepto gitmodule:zepto copy:jquery-bridge replace:jquery-bridge');
grunt.registerTask('test', 'copy:prepare qunit');
grunt.registerTask('cq', 'lint light jshint csslint cover');
grunt.registerTask('light', 'intro nuke copy:prepare css concat');
grunt.registerTask('dist', 'intro nuke zepto jquery-bridge light test copy:dist replace:strip-warnings min minjs replace:distpath copy:htaccess clean:excluded copy:checkin');
grunt.registerTask('full', 'intro nuke light cq dist');
};