forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
282 lines (265 loc) · 8.76 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
/**
* 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.
*
* 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 update_json - This automates updating the bower file
* to match the package.json
*/
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']
},
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']
},
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: {
// 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'],
task:['yuidoc']
}
},
// Set up the mocha task, used for running the automated tests.
mocha: {
test: {
options: {
urls: [
'http://localhost:9001/test/test.html',
'http://localhost:9001/test/test-minified.html'
],
reporter: reporter,
run: true,
log: true,
logErrors: true
}
},
},
// 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'
}
},
// Build p5 into a single, UMD-wrapped file
browserify: {
p5: {
options: {
transform: ['brfs'],
browserifyOptions: {
standalone: 'p5'
},
banner: '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */'
},
src: 'src/app.js',
dest: 'lib/p5.js'
}
},
// The actual compile step: This should collect all the dependencies
// and compile them into a single file.
requirejs: {
// This generates the theme for the documentation from the theme source
// files.
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: {
banner: '/*! p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */ ',
footer: 'p5.prototype._validateParameters = function() {};'+
'p5.prototype._friendlyFileLoadError = function() {};'
},
build: {
src: 'lib/p5.js',
dest: 'lib/p5.min.js'
}
},
// this builds the documentation for the codebase.
yuidoc: {
compile: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
paths: ['src/', 'lib/addons/'],
themedir: 'docs/yuidoc-p5-theme/',
outdir: 'docs/reference/'
}
}
},
release: {
options: {
github: {
repo: 'processing/p5.js', //put your user/repo here
usernameVar: process.env.GITHUB_USERNAME, //ENVIRONMENT VARIABLE that contains Github username
passwordVar: process.env.GITHUB_PASSWORD //ENVIRONMENT VARIABLE that contains Github password
}
}
},
// 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;
}
}
}
}
});
// Load the external libraries used.
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-update-json');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-newer');
// Create the multitasks.
// TODO: "requirejs" is in here to run the "yuidoc_themes" subtask. Is this needed?
grunt.registerTask('build', ['browserify', 'uglify', 'requirejs']);
grunt.registerTask('test', ['jshint', 'jscs', 'build', 'connect', 'mocha']);
grunt.registerTask('test:nobuild', ['jshint:test', 'jscs:test', 'connect', 'mocha']);
grunt.registerTask('yui', ['yuidoc']);
grunt.registerTask('default', ['test']);
};