forked from senchalabs/jQTouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
487 lines (420 loc) · 13.9 KB
/
Gruntfile.coffee
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
module.exports = (grunt) ->
extend = require('util')._extend
path = require('path')
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON('package.json')
meta:
version: "<%= pkg.version %>-<%= pkg.versionId %>"
tag: "v<%= pkg.version %><%= pkg.versionId %>"
build: "jqt-<%= meta.tag %>"
dist: "<%= meta.build %>"
demo: "jqt-demo-<%= meta.tag %>"
banner: """
/*
_/ _/_/ _/_/_/_/_/ _/
_/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/
_/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/
_/
_/
Created by David Kaneda <http://www.davidkaneda.com>
Maintained by Thomas Yip <http://beedesk.com/>
Sponsored by Sencha Labs <http://www.sencha.com/>
Special thanks to Jonathan Stark <http://www.jonathanstark.com/>
Documentation and issue tracking on GitHub <http://github.com/senchalabs/jQTouch/>
(c) 2009-<%= grunt.template.today("yyyy") %> Sencha Labs
Version: <%= meta.version %> - <%= grunt.template.today("yyyy-mm-dd") %>
jQTouch may be freely distributed under the MIT license.
*/\n
"""
dirs:
src: "src"
etc: "etc"
build: "build"
dist: "dist"
archive: "archive"
package: "<%= dirs.archive %>/package"
css: "<%= dirs.build %>/themes/css"
clean:
build: ["<%= dirs.build %>"]
dist: ["<%= dirs.dist %>"]
package: ["<%= dirs.package%>"]
zepto: ["submodules/zepto/dist"]
coffee:
script:
expand: yes
cwd: 'src'
src: ['**.coffee']
dest: '<%= dirs.build %>/src/'
ext: '.js'
extension:
expand: yes
cwd: 'extensions'
src: ['**.coffee']
dest: '<%= dirs.build %>/extensions/'
rename: (dest, filepath) ->
path.join dest, filepath.replace /\.coffee$/, '.js'
demo:
expand: yes
cwd: 'demos'
src: ['**/*.coffee']
dest: '<%= dirs.build %>/demos/'
rename: (dest, filepath) ->
path.join dest, filepath.replace /\.coffee$/, '.js'
copy:
lib:
expand: yes
cwd: 'lib'
src: ["**/*", "!.*"]
dest: "<%= dirs.build %>/lib/"
script:
expand: yes
cwd: 'src'
src: ["**/*.js", "!reference/**"]
dest: "<%= dirs.build %>/src/"
demo:
expand: true
cwd: 'demos'
src: ["**/*", "!.*"]
dest: "<%= dirs.build %>/demos"
extension:
expand: true
cwd: 'extensions'
src: ["**/*", "!.*", "!*.coffee"]
dest: "<%= dirs.build %>/extensions"
theme:
expand: true
cwd: 'themes'
src: ["img/**/*", "!.*"]
dest: "<%= dirs.build %>/themes"
dist:
files: [
expand: yes
src: ["{src,extensions,themes}/**","lib/zepto/**"]
dest: '<%= dirs.dist %>'
cwd: '<%= dirs.package %>'
,
src: "<%= dirs.package %>/fingerprint"
dest: "<%= dirs.dist %>/fingerprint"
cwd: ''
]
package:
files: [
expand: yes
src: ["**/*"]
dest: '<%= dirs.package %>'
cwd: '<%= dirs.build %>'
,
expand: yes
src: ["README.md","VERSIONS.md","LICENSE.txt","package.json"]
dest: '<%= dirs.package %>'
cwd: ''
,
src: "<%= dirs.etc %>/sample.htaccess"
dest: "<%= dirs.package %>/.htaccess"
cwd: ''
,
src: "<%= dirs.etc %>/fingerprint"
dest: "<%= dirs.package %>/fingerprint"
cwd: ''
]
options:
processContentExclude: ['**/*.{png,gif,jpg,ico,psd}']
processContent: (content, path) ->
# Strip warnings from JavaScript
if path.match /\.js$/
content.replace /\n\s*warn\(.*/g, ''
# Update to minified JS/CSS paths in HTML
else if path.match /\.html$/
content
.replace(/([\w-\.]*)(\.min)?\.js/g, '$1.min.js')
.replace(/(themes\/css\/[\w-\.]*)(\.min)?\.css/g, '$1.min.css')
else if path.match /\/fingerprint$/
content
.replace(/\{build_id\}/, grunt.config('meta.build'))
.replace(/\{build_git_revision\}/, grunt.config('meta.revision'))
.replace(/\{build_date\}/, grunt.template.today('yyyy-mm-dd hh:mmZ'))
else
content
test:
expand: yes
cwd: '<%= dirs.build %>'
dest: 'test/build/'
src: '**/*'
zepto:
files: [
expand: yes
cwd: 'submodules/zepto/dist/'
src: ['zepto.js', 'zepto.min.js']
dest: '<%= dirs.build %>/lib/zepto'
,
src: 'submodules/zepto/src/touch.js'
dest: '<%= dirs.build %>/src/jqtouch-jquery.js'
]
"jquery-bridge":
options:
# Convert Zepto's touch class to work for jQuery
processContent: (content) ->
content
.replace(/e\.touches/g, '(e.originalEvent||e).touches')
.replace('(Zepto)', '(jQuery)')
files:
"<%= dirs.build %>/src/jqtouch-jquery.js": ["submodules/zepto/src/touch.js"]
compress:
archive:
options:
archive: "<%= dirs.archive %>/<%= meta.demo %>.tgz"
files: [
src: ["package/**/*"]
dest: ""
cwd: '<%= dirs.archive %>'
expand: true
]
dist:
options:
archive: "<%= dirs.archive %>/<%= meta.dist %>.tgz"
files: [
src: ["dist/**/*"]
dest: "package"
cwd: ''
expand: true
,
src: ["README.md","LICENSE.txt","VERSIONS.md","package.json"]
dest: "package/dist"
cwd: ''
expand: true
]
"npm-command":
zepto:
command: "run-script"
script: "dist"
params: ""
options:
cwd: "submodules/zepto"
env: extend(process.env, {'MODULES': 'zepto event ajax form ie detect fx data touch'})
compass:
theme:
files: [
src: 'themes/scss/**/*.scss'
]
options:
load: 'submodules/compass-recipes/'
sassDir: 'themes/scss'
cssDir: '<%= dirs.css %>'
demo:
files: [
src: 'demos/**/*.scss'
]
options:
load: 'submodules/compass-recipes/'
sassDir: 'demos/'
cssDir: "<%= dirs.build %>/demos/"
extension:
files: [
src: 'extensions/**/*.scss'
]
options:
load: 'submodules/compass-recipes/'
sassDir: 'extensions/'
cssDir: "<%= dirs.build %>/extensions/"
# Concat is only used to add our banner
concat:
script:
expand: yes
cwd: '<%= dirs.build %>/src/'
src: ['**/*.js', '!**/jqtouch-jquery.js']
dest: '<%= dirs.build %>/src/'
options:
banner: "<%= meta.banner %>"
theme:
expand: yes
cwd: '<%= dirs.build %>/themes/'
src: '**/*.css'
dest: '<%= dirs.build %>/themes/'
options:
banner: "<%= meta.banner %>"
qunit:
files: ['test/unit/**/*.html', '!**/disabled/**']
options:
timeout: 15000
uglify:
options:
globals:
jQTouch: yes
jqtouch:
expand: yes
cwd: '<%= dirs.package %>/src/'
src: ['**/*.js', '!**/jqtouch-jquery.js', '!**/*.min.js']
dest: '<%= dirs.package %>/src/'
ext: '.min.js'
options:
banner: '<%= meta.banner %>'
lib:
expand: yes
cwd: '<%= dirs.package %>'
src: ['lib/**/*.js', 'src/jqtouch-jquery.js', '!**/*.min.js']
dest: '<%= dirs.package %>'
rename: (dest, filepath) ->
path.join dest, filepath.replace /\.js$/, '.min.js'
options:
preserveComments: (comment) ->
# Preserve comments near the top of the file.
# Loosey-goosey, I know, but I want to make sure we keep any
# Zepto and jQuery lines about (c) and license
if comment.start.line < 6
yes
else
no
extension:
expand: yes
cwd: "<%= dirs.package %>/extensions/"
src: '**/*.js'
dest: "<%= dirs.package %>/extensions/"
rename: (dest, filepath) ->
path.join dest, filepath.replace /\.js$/, '.min.js'
options:
banner: "<%= meta.banner %>"
cssmin:
theme:
expand: yes
cwd: "<%= dirs.package %>/themes/css"
src: ['**/*.css', '!**/*.min.css']
dest: "<%= dirs.package %>/themes/css"
ext: '.min.css'
options:
banner: "<%= meta.banner %>"
extension:
expand: yes
cwd: "<%= dirs.package %>/extensions"
src: ['**/*.css', '!**/*.min.css']
dest: "<%= dirs.package %>/extensions"
rename: (dest, filepath) ->
path.join dest, filepath.replace /\.css$/, '.min.css'
options:
banner: "<%= meta.banner %>"
cover:
compile:
files:
"<%= dirs.build %>/test/instrumented/jqtouch.js": ["src/jqtouch.js"]
watch_files:
live:
files: ['build/**', '!.*', '!.**/*']
options:
livereload: true # default port: 35729, add <script src="http://localhost:35729/livereload.js"></script>
theme:
files: ['themes/scss/**/*.scss', '!.*', '!.**/*']
tasks: ['compass']
dot: false
coffee:
files: ['src/**/*.coffee', '!.*', '!.**/*']
tasks: ['coffee:script']
dot: false
script:
files: ['src/**/*.js', '!.*', '!.**/*']
tasks: ['copy:script']
dot: false
demo:
files: ['demos/**/*', '!.*', '!.**/*']
tasks: ['demo']
dot: false
extension:
files: ['extensions/**/*', '!.*', '!.**/*']
tasks: ['extension']
dot: false
jshint:
src: "<%= dirs.src %>/**/*.js"
options:
camelcase: true
curly: false
eqeqeq: true
immed: true
latedef: true
newcap: true
noarg: true
sub: true
undef: true
boss: true
eqnull: true
browser: true
globals:
$: true
console: true
# Task definitions
require('load-grunt-tasks')(grunt);
grunt.registerMultiTask "npm-command", "Run an NPM command in a specific module", ->
cb = @async() # Tell grunt the task is async
command = @data["command"]
params = grunt.template.process(@data["params"])
script = grunt.template.process(@data["script"])
options = @data["options"]
exec = require("child_process").exec
child = exec("npm install", options, (error, stdout, stderr) ->
grunt.log.write stdout if stdout
grunt.log.error stdout if stderr
if error isnt null
cb(error) # Execute the callback when the async task is done
else
child = exec(["npm", command, script, params].join(' '), options, (error, stdout, stderr) ->
grunt.log.write stdout if stdout
grunt.log.error stdout if stderr
cb(error) # Execute the callback when the async task is done
)
)
grunt.registerTask "git-describe", "Describes current git commit", ->
# prefer to use our own task for better control over cmd line args
done = this.async();
args = ["describe", "--tags", "--always", "--long", "--dirty=*", "--abbrev=12"]
grunt.util.spawn cmd: "git", args: args, (err, result) ->
if err
grunt.log.error err
return done(false)
grunt.config("meta.revision", result)
grunt.config("meta.dist", 'jqt-' + result)
grunt.config("meta.demo", 'jqt-demo-' + result)
return done(result)
grunt.registerTask "git-tag", "Tag the current git commit", ->
done = this.async();
args = ["tag", grunt.config("meta.tag")]
console.log('$ git ' + args.join(' '))
grunt.util.spawn cmd: "git", args: args, (err, result) ->
if err
grunt.log.error err
return done(false)
return done(result)
grunt.renameTask 'watch', 'watch_files'
# Build Zepto
grunt.registerTask 'zepto', ['npm-command:zepto', 'copy:zepto', 'copy:jquery-bridge']
# Build Lib
grunt.registerTask 'lib', ['zepto', 'copy:lib']
# Build Scripts
grunt.registerTask 'script', ['copy:script', 'coffee:script', 'concat:script']
# jQT Theme
grunt.registerTask 'theme', ['script', 'copy:theme', 'compass:theme', 'concat:theme']
# Main jQT bits
grunt.registerTask 'main', ['script', 'theme']
# Build Extensions
grunt.registerTask 'extension', ['copy:extension', 'coffee:extension', 'compass:extension']
# Build Demos
grunt.registerTask 'demo', ['copy:demo', 'coffee:demo', 'compass:demo']
# Build
grunt.registerTask 'build', ['lib', 'main', 'extension', 'demo']
# Watch
grunt.registerTask 'watch', ['build', 'watch_files']
# Full (Clean and Build)
grunt.registerTask 'full', ['clean', 'update_submodules', 'build']
# Default (Same as full)
grunt.registerTask 'default', ['full']
# Test
grunt.registerTask 'test', ['copy:test', 'qunit']
# Minify Assets
grunt.registerTask 'minify', ['uglify', 'cssmin']
# Build full, and and minifies all artifacts
grunt.registerTask 'pack', ['git-describe', 'copy:package', 'minify']
# Pack and compress into a versioned archive
grunt.registerTask 'archive', ['pack', 'compress:archive']
# Select the core from package to make a `dist` structure
grunt.registerTask 'dist', ['full', 'test', 'archive', 'copy:dist', 'compress:dist']
# Npm Prepublish
grunt.registerTask 'release', ['git-tag', 'dist']