forked from timmywil/panzoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
186 lines (174 loc) · 3.89 KB
/
Gruntfile.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
/**
* Gruntfile.js
*/
module.exports = function( grunt ) {
'use strict';
// Load all grunt tasks
require('load-grunt-tasks')( grunt );
var gzip = require('gzip-js');
var fs = require('graceful-fs');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bump: {
options: {
files: ['package.json', 'bower.json', 'panzoom.jquery.json'],
commitFiles: ['package.json', 'bower.json', 'panzoom.jquery.json'],
tagName: '%VERSION%',
push: false
}
},
bowercopy: {
options: {
clean: true
},
dev: {
options: {
destPrefix: 'test/libs'
},
files: {
'mocha/mocha.js': 'mocha/mocha.js',
'mocha/mocha.css': 'mocha/mocha.css',
'jquery.mousewheel.js': 'jquery-mousewheel/jquery.mousewheel.js',
'chai.js': 'chai/chai.js'
}
},
pointertouch: {
src: 'jquery.event.pointertouch/dist/jquery.event.pointertouch.js',
dest: 'src/pointertouch.js'
}
},
build: {
dist: {
dest: 'dist/jquery.panzoom.js',
src: 'src/panzoom.js'
},
manifest: {
src: 'panzoom.jquery.json'
},
bower: {
src: 'bower.json'
},
readme: {
src: 'README.md'
}
},
compare_size: {
files: [
'dist/jquery.panzoom.js',
'dist/jquery.panzoom.min.js'
],
options: {
cache: 'dist/.sizecache.json',
compress: {
gz: function( contents ) {
return gzip.zip( contents, {} ).length;
}
}
}
},
jsonlint: {
pkg: {
src: 'package.json'
},
bower: {
src: 'bower.json'
},
jquery: {
src: 'panzoom.jquery.json'
}
},
jshint: {
all: [
'Gruntfile.js',
'src/panzoom.js',
'test/bdd/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
uglify: {
'dist/jquery.panzoom.min.js': [
'dist/jquery.panzoom.js'
],
options: {
preserveComments: 'some'
}
},
mocha: {
// runs all html files in phantomjs
all: {
src: [ 'test/index.html' ],
options: {
mocha: {
ui: 'bdd',
ignoreLeaks: false
}
}
}
},
watch: {
dev: {
files: [
'<%= jshint.all %>',
'package.json',
'.jshintrc',
'test/index.html'
],
tasks: 'dev',
options: {
livereload: 35711
}
},
test: {
files: '<%= watch.dev.files %>',
tasks: 'test'
}
}
});
grunt.registerMultiTask(
'build',
'Build jquery.panzoom and package manifest',
function() {
var data = this.data;
var src = data.src;
var dest = data.dest || src;
var version = grunt.config('pkg.version');
var compiled = grunt.file.read( src );
// If this is the README, replace versions to download
if ( /README/.test(src) ) {
compiled = compiled
// Replace first instance of vx.x.x
.replace( /v\d\.\d+\.\d+/, 'v' + version )
// Replace the version in the URLs
.replace( /(panzoom\/)\b\d+\.\d+\.\d+\b(\/)/g, '$1' + version + '$2' );
} else {
// Replace version and date
compiled = compiled
// Replace version in JSON files
.replace( /("version":\s*")[^"]+/, '$1' + version )
// Replace version tag
.replace( /@VERSION/g, version )
.replace( '@DATE', (new Date).toDateString() );
}
if ( /panzoom/.test(src) ) {
var fixhook = fs.readFileSync(__dirname + '/src/pointertouch.js', 'utf8')
.replace(/\/\*\*[\w\W]*'use strict';\s*/, '')
.replace(/\s*return \w+;\s*\}\)\);\s*$/, '');
compiled = compiled
// Insert pointer/touch fixhook
.replace( /\/\/ INSERT FIXHOOK/, fixhook )
// Remove pointerhook dependency
.replace(', \'./pointertouch\'', '')
.replace(', require(\'./pointertouch\')', '');
}
// Write source to file
grunt.file.write( dest, compiled );
grunt.log.ok( 'File written to ' + dest );
}
);
grunt.registerTask( 'dev', [ 'jsonlint', 'jshint', 'build', 'uglify', 'compare_size' ] );
grunt.registerTask( 'test', [ 'dev', 'mocha' ]);
// Default grunt
grunt.registerTask( 'default', 'test');
};