forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
362 lines (336 loc) · 11.1 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
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
/**
* This is the Gruntfile for p5.js. Grunt is a task runner/builder
* which is what p5.js uses to build the source code into the library
* and handle other housekeeping tasks.
*
* There are three main tasks:
*
* grunt - This is the default task, which builds the code, tests it
* using both jslint and mocha, and then minifies it.
*
* grunt yui - This will build the inline documentation for p5.js.
* The generated documentation is assumed to be
* served from the /reference/ folder of the p5js
* website (https://github.com/processing/p5.js-website).
*
* grunt test - This rebuilds the source and runs the automated tests on
* both the minified and unminified code. If you need to debug
* a test suite in a browser, `grunt test --keepalive` will
* start the connect server and leave it running; the tests
* can then be opened at localhost:9001/test/test.html
*
* Note: `grunt test:nobuild` will skip the build step when running the tests,
* and only runs the test files themselves through the linter: this can save
* a lot of time when authoring test specs without making any build changes.
*
* And there are several secondary tasks:
*
*
* grunt watch - This watches the source for changes and rebuilds on
* every file change, running the linter and tests.
*
* grunt watch:main - This watches the source for changes and rebuilds on
* every file change, but does not rebuild the docs.
* It's faster than the default watch.
*
* grunt watch:quick - This watches the source for changes and rebuilds
* p5.js on every file change, but does not rebuild
* docs, and does not perform linting, minification,
* or run tests. It's faster than watch:main.
*
* grunt update_json - This automates updating the bower file
* to match the package.json
*/
function getYuidocOptions() {
var BASE_YUIDOC_OPTIONS = {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
paths: ['src/', 'lib/addons/'],
themedir: 'docs/yuidoc-p5-theme/',
helpers: [],
preprocessor: './docs/preprocessor.js',
outdir: 'docs/reference/'
}
};
// note dev is no longer used, prod is used to build both testing and production ready docs
var o = {
prod: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS)),
dev: JSON.parse(JSON.stringify(BASE_YUIDOC_OPTIONS))
};
o.prod.options.helpers.push('docs/yuidoc-p5-theme/helpers/helpers_prod.js');
o.dev.options.helpers.push('docs/yuidoc-p5-theme/helpers/helpers_dev.js');
return o;
}
module.exports = function(grunt) {
// Specify what reporter we'd like to use for Mocha
var reporter = 'Nyan';
// For the static server used in running tests, configure the keepalive.
// (might not be useful at all.)
var keepalive = false;
if (grunt.option('keepalive')) {
keepalive = true;
}
grunt.initConfig({
// read in the package, used for knowing the current version, et al.
pkg: grunt.file.readJSON('package.json'),
// Configure style consistency checking for this file, the source, and the tests.
jscs: {
options: {
config: '.jscsrc',
reporter: require('jscs-stylish').path
},
build: {
src: [
'Gruntfile.js',
'tasks/**/*.js'
]
},
source: {
src: [
'src/**/*.js',
'!src/external/**/*.js'
]
},
test: {
src: ['test/unit/**/*.js']
}
},
// Configure hinting for this file, the source, and the tests.
jshint: {
build: {
options: {
jshintrc: '.jshintrc'
},
src: [
'Gruntfile.js',
'tasks/**/*.js'
]
},
source: {
options: {
jshintrc: 'src/.jshintrc',
ignores: [ 'src/external/**/*.js' ]
},
src: ['src/**/*.js']
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/unit/**/*.js']
}
},
// Set up the watch task, used for live-reloading during development.
// This watches both the codebase and the yuidoc theme. Changing the
// code touches files within the theme, so it will also recompile the
// documentation.
watch: {
quick: {
files: ['src/**/*.js','src/**/*.frag','src/**/*.vert'],
tasks: ['browserify'],
options: {
livereload: true
}
},
// Watch the codebase for changes
main: {
files: ['src/**/*.js'],
tasks: ['newer:jshint:source','test'],
options: {
livereload: true
}
},
// watch the theme for changes
reference_build: {
files: ['docs/yuidoc-p5-theme/**/*'],
tasks: ['yuidoc'],
options: {
livereload: true,
interrupt: true
}
},
// watch the yuidoc/reference theme scripts for changes
yuidoc_theme_build: {
files: ['docs/yuidoc-p5-theme-src/scripts/**/*'],
tasks: ['requirejs:yuidoc_theme']
},
// Watch the codebase for doc updates
yui:{
files:['src/**/*.js', 'lib/addons/*.js'],
task:['yuidoc']
}
},
// Set up node-side (non-browser) mocha tests.
mochaTest: {
test: {
src: ['test/node/**/*.js']
}
},
// Set up the mocha task, used for running the automated tests.
mocha: {
yui: {
options: {
urls: [
'http://localhost:9001/test/test-reference.html'
],
reporter: reporter,
run: false,
log: true,
logErrors: true
}
},
test: {
options: {
urls: [
'http://localhost:9001/test/test.html',
'http://localhost:9001/test/test-minified.html'
],
reporter: reporter,
run: true,
log: true,
logErrors: true,
timeout: 100000
}
}
},
// This is a standalone task, used to automatically update the bower.json
// file to match the values in package.json. It is (likely) used as part
// of the manual release strategy.
update_json: {
// set some task-level options
options: {
src: 'package.json',
indent: '\t'
},
// update bower.json with data from package.json
bower: {
src: 'package.json', // where to read from
dest: 'bower.json', // where to write to
// the fields to update, as a String Grouping
fields: 'name version description repository'
}
},
// This generates the theme for the documentation from the theme source
// files.
requirejs: {
yuidoc_theme: {
options: {
baseUrl: './docs/yuidoc-p5-theme-src/scripts/',
mainConfigFile: './docs/yuidoc-p5-theme-src/scripts/config.js',
name: 'main',
out: './docs/yuidoc-p5-theme/assets/js/reference.js',
optimize: 'none',
generateSourceMaps: true,
findNestedDependencies: true,
wrap: true,
paths: {
'jquery': 'empty:'
}
}
}
},
// This minifies the javascript into a single file and adds a banner to the
// front of the file.
uglify: {
options: {
compress: {
global_defs: {
'IS_MINIFIED': true
}
},
banner: '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */ '
},
dist: {
files: {
'lib/p5.min.js': 'lib/p5.js',
'lib/addons/p5.dom.min.js': 'lib/addons/p5.dom.js'
}
}
},
// this builds the documentation for the codebase.
yuidoc: getYuidocOptions(),
// This is a static server which is used when testing connectivity for the
// p5 library. This avoids needing an internet connection to run the tests.
// It serves all the files in the test directory at http://localhost:9001/
connect: {
server: {
options: {
base: './',
port: 9001,
keepalive: keepalive,
middleware: function(connect, options, middlewares) {
middlewares.unshift(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
return next();
});
return middlewares;
}
}
}
},
'saucelabs-mocha': {
all: {
options: {
urls: ['http://127.0.0.1:9001/test/test.html'],
tunnelTimeout: 5,
build: process.env.TRAVIS_JOB_ID,
concurrency: 3,
browsers: [
{browserName: 'chrome'},
{browserName: 'firefox', platform: 'Linux', version: '42.0'},
{browserName: 'safari'},
],
testname: 'p5.js mocha tests',
tags: ['master']
}
}
},
minjson: {
compile: {
files: {
'./docs/reference/data.min.json': './docs/reference/data.json'
}
}
}
});
// Load build tasks.
// This contains the complete build task ("browserify")
// and the task to generate user select modules of p5
// ("combineModules") which can be invoked directly by
// `grunt combineModules:module_1:module_2` where core
// is included by default in all combinations always.
// NOTE: "module_x" is the name of it's folder in /src.
grunt.loadTasks('tasks/build');
// Load release task
grunt.loadTasks('tasks/release');
// Load the external libraries used.
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-http');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-minjson');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-release-it');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.loadNpmTasks('grunt-update-json');
// Create the multitasks.
grunt.registerTask('build', ['browserify', 'uglify', 'requirejs']);
grunt.registerTask('test', ['jshint', 'jscs', 'yuidoc:prod', 'build', 'connect', 'mocha', 'mochaTest']);
grunt.registerTask('test:nobuild', ['jshint:test', 'jscs:test', 'connect', 'mocha']);
grunt.registerTask('yui', ['yuidoc:prod', 'minjson']);
grunt.registerTask('yui:test', ['yuidoc:prod', 'connect', 'mocha:yui']);
grunt.registerTask('default', ['test']);
grunt.registerTask('saucetest', ['connect', 'saucelabs-mocha']);
};