forked from sarahghp/p5bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
194 lines (178 loc) · 5.52 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
/**
* This is the Gruntfile for p5bots.
* It is a modified version of the Gruntfile for p5.js. Grunt is a task
* runner/builder, used to build the source code into the library
* and handle other housekeeping tasks.
*
* There are five main tasks:
*
* grunt - This is the default task, which both tests and builds.
*
* grunt build - This task builds and minifies the client source code
* and the automated API documentation.
*
* grunt test - This only runs the automated tests, which is faster than
* rebuilding entirely from source because it skips minification
* and concatination. 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
*
*
* grunt watch:main - This watches the source for changes and rebuilds on
* every file change.
*/
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',
'build/**/*.js'
]
},
source: {
src: [
'src/client/**/*.js',
'src/p5bots-server/app.js',
'src/p5bots-server/lib/*.js',
]
},
test: {
src: ['test/unit/**/*.js']
}
},
// Configure hinting for this file, the source, and the tests.
jshint: {
build: {
options: {
jshintrc: '.jshintrc'
},
src: [
'Gruntfile.js',
'build/**/*.js'
]
},
source: {
options: {
jshintrc: 'src/.jshintrc',
ignores: [ 'src/external/**/*.js' ]
},
src: ['src/client/**/*.js',
'src/p5bots-server/app.js',
'src/p5bots-server/lib/*.js']
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/unit/**/*.js']
}
},
// Set up the watch task, used for live-reloading during development.
watch: {
// Watch the codebase for changes
main: {
files: ['src/**/*.js'],
tasks: ['newer:jshint:source','test', 'jsdoc'],
options: {
livereload: true
}
}
},
// Set up the mocha task, used for the automated browser-side 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
}
},
},
// Set up the mocha-chai-sinon task, used for the automated server-side tests.
'mocha-chai-sinon': {
build: {
src: ['test/unit/p5bots-server/app.js'],
options: {
ui: 'tdd',
reporter: reporter
}
}
},
// This minifies the javascript into a single file and adds a banner to the
// front of the file.
uglify: {
options: {
banner: '/*! p5bots.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> */ '
},
build: {
src: 'lib/p5bots.js',
dest: 'lib/p5bots.min.js'
}
},
release: {
options: {
github: {
repo: 'sarahgp/p5bots', //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.loadTasks('build/tasks');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-mocha-chai-sinon');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-newer');
// Create the multitasks.
grunt.registerTask('build', ['browserify', 'uglify']);
grunt.registerTask('test', ['jshint', 'jscs', 'build', 'connect', 'mocha', 'mocha-chai-sinon']);
grunt.registerTask('default', ['test']);
};