forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
345 lines (325 loc) · 8.75 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
// these requires allow us to use es6 features such as
// `import`/`export` and `async`/`await` in the Grunt tasks
// we load from other files (`tasks/`)
require('regenerator-runtime/runtime');
require('@babel/register');
module.exports = grunt => {
const connectConfig = open => {
return {
options: {
directory: {
path: './',
options: {
icons: true
}
},
port: 9001,
open,
middleware: function(connect, options, middlewares) {
middlewares.unshift(
require('connect-modrewrite')([
'^/assets/js/p5(\\.min)?\\.js(.*) /lib/p5$1.js$2 [L]',
'^/assets/js/p5\\.(sound)(\\.min)?\\.js(.*) /lib/addons/p5.$1$2.js$3 [L]'
]),
function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
return next();
}
);
return middlewares;
}
}
};
};
const gruntConfig = {
// 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.
eslint: {
options: {
format: 'unix'
},
build: {
src: [
'Gruntfile.js',
'docs/preprocessor.js',
'utils/**/*.js',
'tasks/**/*.js'
]
},
source: {
src: ['src/**/*.js']
},
test: {
src: ['test/**/*.js', '!test/js/*.js']
},
fix: {
// src: is calculated below...
options: {
rules: {
'no-undef': 0,
'no-unused-vars': 0
},
fix: true
}
}
},
'eslint-samples': {
options: {
parserOptions: {
ecmaVersion: 8
},
format: 'unix'
},
source: {
src: ['src/**/*.js']
},
fix: {
options: {
fix: true
}
}
},
// 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',
'src/**/*.glsl'
],
tasks: ['browserify:dev'],
options: {
livereload: true
}
},
// Watch the codebase for changes
main: {
files: ['src/**/*.js'],
tasks: ['newer:eslint: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 codebase for doc updates
// launch with 'grunt yui connect:yui watch:yui'
yui: {
files: [
'src/**/*.js',
'lib/addons/*.js',
'src/**/*.frag',
'src/**/*.vert',
'src/**/*.glsl'
],
tasks: [
'browserify',
'browserify:min',
'yuidoc:prod',
'clean:reference',
'minjson',
'uglify'
],
options: {
livereload: true
}
}
},
// Set up node-side (non-browser) mocha tests.
mochaTest: {
test: {
src: ['test/node/**/*.js'],
options: {
reporter: 'spec',
require: '@babel/register',
ui: 'tdd'
}
}
},
// Set up the mocha task, used for running the automated tests.
mochaChrome: {
yui: {
options: {
urls: ['http://localhost:9001/test/test-reference.html']
}
},
test: {
options: {
urls: [
'http://localhost:9001/test/test.html',
'http://localhost:9001/test/test-minified.html'
]
}
}
},
nyc: {
report: {
options: {
reporter: ['text-summary', 'html', 'json']
}
}
},
babel: {
options: {
presets: ['@babel/preset-env']
},
dist: {
files: {
'lib/p5.pre-min.js': 'lib/p5.js'
}
}
},
// 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.pre-min.js'],
'lib/modules/p5Custom.min.js': ['lib/modules/p5Custom.pre-min.js']
}
}
},
// this builds the documentation for the codebase.
yuidoc: {
prod: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
paths: ['src/', 'lib/addons/'],
themedir: 'docs/yuidoc-p5-theme/',
helpers: ['docs/yuidoc-p5-theme/helpers/helpers_prod.js'],
preprocessor: './docs/preprocessor.js',
outdir: 'docs/reference/'
}
}
},
clean: {
// Clean up unused files generated by yuidoc
reference: {
src: [
'docs/reference/classes/',
'docs/reference/elements/',
'docs/reference/files/',
'docs/reference/modules/',
'docs/reference/api.js'
]
}
},
// 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: connectConfig(),
yui: connectConfig('http://127.0.0.1:9001/docs/reference/')
},
// This minifies the data.json file created from the inline reference
minjson: {
compile: {
files: {
'./docs/reference/data.min.json': './docs/reference/data.json'
}
}
}
};
// eslint fixes everything it checks:
gruntConfig.eslint.fix.src = Object.keys(gruntConfig.eslint).reduce(
(acc, key) => {
if (gruntConfig.eslint[key].src) {
acc.push(...gruntConfig.eslint[key].src);
}
return acc;
},
[]
);
/* not yet
gruntConfig['eslint-samples'].fix.src = Object.keys(
gruntConfig['eslint-samples']
)
.map(s => gruntConfig['eslint-samples'][s].src)
.reduce((a, b) => a.concat(b), [])
.filter(a => a);
*/
grunt.initConfig(gruntConfig);
// 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 tasks for testing
grunt.loadTasks('tasks/test');
// Load the external libraries used.
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-minjson');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-simple-nyc');
// Create the multitasks.
grunt.registerTask('build', [
'yui',
'browserify',
'browserify:min',
'uglify',
'browserify:test'
]);
grunt.registerTask('lint', ['lint:source', 'lint:samples']);
grunt.registerTask('lint:source', [
'eslint:build',
'eslint:source',
'eslint:test'
]);
grunt.registerTask('lint:samples', [
'yui', // required for eslint-samples
'eslint-samples:source'
]);
grunt.registerTask('lint-fix', ['eslint:fix']);
grunt.registerTask('test', [
'build',
'connect:server',
'mochaChrome',
'mochaTest',
'nyc:report'
]);
grunt.registerTask('test:nobuild', [
'eslint:test',
'connect:server',
'mochaChrome',
'mochaTest',
'nyc:report'
]);
grunt.registerTask('yui', ['yuidoc:prod', 'clean:reference', 'minjson']);
grunt.registerTask('yui:test', ['yui', 'connect:yui', 'mochaChrome:yui']);
grunt.registerTask('yui:dev', ['yui', 'build', 'connect:yui', 'watch:yui']);
grunt.registerTask('default', ['lint', 'test']);
};