This repository has been archived by the owner on Sep 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Gruntfile.js
292 lines (253 loc) · 7.5 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
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
var LibBuilder = require("./lib/build");
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// The config info
var cfg = {
pkg: grunt.file.readJSON('package.json'),
// Remove any compiled js files
clean: {
lib: [
'lib/**/*.js'
],
data: [
'client/walltime-data*.js'
],
individual: [
'client/individual/*.{js,zip}'
]
},
// Compile the coffeescript files to js
coffee: {
lib: {
files: [{
expand: true,
cwd: 'lib',
src: "**/*.coffee",
dest: 'lib',
ext: '.js'
}]
}
},
// Add the masthead information to each built file
concat: {
options: {
banner: grunt.file.read('masthead.tpl')
},
lib: {
expand: true,
src: ['client/walltime*.js', 'client/commonjs/**/*.js', '!client/walltime-data*.js']
},
data: {
expand: true,
src: ['client/walltime-data*.js']
},
individual: {
expand: true,
src: ['client/individual/walltime-data*.js']
}
},
// Build the walltime library with requirejs
requirejs: {
options: {
baseUrl: "lib",
name: "walltime",
optimize: "none"
},
lib: {
options: {
out: "client/walltime.js"
}
},
libmin: {
options: {
out: "client/walltime.min.js",
optimize: "uglify"
}
}
},
// Copy relevant files over for a commonjs build (i.e. Titanium)
copy: {
commonjs: {
files: [{
expand: true,
cwd: 'lib/',
src: ['walltime.js', 'olson/helpers.js', 'olson/rule.js', 'olson/zone.js', 'olson/timezonetime.js'],
dest: "client/commonjs"
}]
}
},
// Lint coffee files (indendation and style consistency)
coffeelint: {
options: {
max_line_length: {
level: "ignore"
},
indentation: {
value: 4
}
},
lib: ["lib/**/*.coffee"]
},
// Lint the javascript files
jshint2: {
options: {
jshintrc: ".jshintrc"
},
all: ["Gruntfile.js", "index.js"]
},
// Run mocha unit tests
simplemocha: {
options: {
compilers: ["coffee:coffee-script"],
ui: 'bdd',
reporter: 'spec'
},
all: ["test/*_spec.coffee"]
},
// Build the big walltime-data.js file
"walltime-data": {
all: {}
},
// Build the individual files; i.e. walltime-data[Africa-Cairo].js
"walltime-individual": {
all: {}
},
// Verify that a data file has rules or zones
"walltime-verify": {
data: {
options: {
allowEmptyRules: false,
allowEmptyZones: false
},
files: {
src: ["client/walltime-data.js"]
}
},
individual: ["client/individual/*.js"]
},
// Zip up all the individual data files.
compress: {
individual: {
options: {
archive: "client/individual/walltime-data.zip"
},
expand: true,
cwd: "client/individual",
src: ["*.js", "!*.min.js"]
},
"individual-min": {
options: {
archive: "client/individual/walltime-data-min.zip"
},
expand: true,
cwd: "client/individual",
src: ["*.min.js"]
}
},
// Start a connect server to serve client side mocha html tests for mocha_phantomjs
connect: {
server: {
options: {
port: 8000,
base: '.'
}
}
},
// Load the mocha client side test page with phantomjs to test that the library works
// in a browser.
mocha_phantomjs: {
requirejs: {
options: {
verbose: true,
urls: ["http://localhost:<%= connect.server.options.port %>/test/client/index-require.html"]
}
},
release: {
options: {
verbose: true,
urls: ["http://localhost:<%= connect.server.options.port %>/test/client/release.html"]
}
}
},
// Bump the version of the package.json for releases
bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: ['pkg'],
commitFiles: ["-a"],
push: true,
pushTo: "origin"
}
}
};
grunt.initConfig(cfg);
// Load the data building walltime- grunt tasks
LibBuilder.registerGruntTask(grunt);
// Build lib
grunt.registerTask("lib", [
"test",
"clean:lib",
"coffee:lib",
"requirejs:lib",
"requirejs:libmin",
"copy:commonjs",
"concat:lib",
"clean:lib"
]);
// Build entire data file
grunt.registerTask("data", [
"test",
"clean:data",
"walltime-data:all",
"walltime-verify:data",
"concat:data"
]);
// Build individual data files
grunt.registerTask("individual", [
"test",
"clean:individual",
"walltime-individual:all",
"walltime-verify:individual",
"concat:individual",
"compress:individual",
"compress:individual-min"
]);
// Lint and test code
grunt.registerTask("test", [
"coffeelint:lib",
"jshint2:all",
"simplemocha:all"
]);
// Test lib and data in phantomjs browser
grunt.registerTask("browsertest", [
"connect:server",
"mocha_phantomjs:release",
"mocha_phantomjs:requirejs"
]);
// Do build and test
grunt.registerTask("stage", [
"test",
"lib",
"data",
"individual",
"browsertest"
]);
// Bump version and do build
grunt.registerTask("release", [
"bump-only:minor",
"stage",
"bump-commit"
]);
grunt.registerTask("default", function () {
grunt.log.writeln("");
grunt.log.writeln("grunt lib");
grunt.log.writeln(" - build the client library");
grunt.log.writeln("grunt data");
grunt.log.writeln(" - build data files");
grunt.log.writeln("grunt individual");
grunt.log.writeln(" - build data files");
grunt.log.writeln("grunt test");
grunt.log.writeln(" - run unit tests and lint code");
});
};