forked from timmywil/panzoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
162 lines (151 loc) · 3.19 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
/**
* Gruntfile.js
*/
module.exports = function( grunt ) {
'use strict';
// Load all grunt tasks
require('load-grunt-tasks')( grunt );
var gzip = require('gzip-js');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bowercopy: {
options: {
clean: true
},
dev: {
options: {
destPrefix: 'test/libs'
},
files: {
'test/libs/jquery.js': 'jquery/dist/jquery.js',
'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'
}
}
},
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: true
}
},
uglify: {
'dist/jquery.panzoom.min.js': [
'dist/jquery.panzoom.js'
],
options: {
banner: '/* jquery.panzoom.min.js <%= pkg.version %> (c) Timmy Willison - MIT License */\n'
}
},
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',
'test/index.html'
],
tasks: 'dev',
options: {
livereload: 35711,
atBegin: true
}
},
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() );
}
// 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');
};