Repository navigation
Expand file tree
/
Copy pathGruntfile.js
More file actions
207 lines (174 loc) · 6.03 KB
/
Copy pathGruntfile.js
File metadata and controls
207 lines (174 loc) · 6.03 KB
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
require("coffee-script");
var fs = require('fs');
var open = require("open");
module.exports = function (grunt) {
var pkg = grunt.file.readJSON('package.json');
var version = pkg.version;
var banner = '/**\n' +
' * <%= pkg.name %> <%= pkg.version %>\n' +
' * <%= pkg.author.url %>\n *\n' +
' * Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %>\n' +
' * Dual licensed under the MIT or GPL licenses.\n' +
' */\n\n';
var docGen = function() {
var outputFile = "./build/api.json";
var sourceParser = require("./build/parseSourceDocs");
var apiGenerator = require("./build/parseNodes");
var sourceFiles = grunt.file.expand('src/**/*.js');
var blocks = sourceParser.parse(sourceFiles);
var jsonObject = apiGenerator.structureBlocks(blocks);
var apiJSON = JSON.stringify(jsonObject, null, 4);
grunt.file.write(outputFile, apiJSON);
grunt.log.writeln("Wrote api data to " + outputFile);
};
var apiServer = require("./build/api-gen/dynamic-server.js");
function runApiServer() {
var done = this.async();
apiServer(grunt, "./build/api.json");
setTimeout(function(){
open("http://localhost:8080");
}, 100);
}
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
usebanner: {
dist: {
options: {
position: 'top',
banner: banner
},
files: {
src: ['crafty.js']
}
}
},
browserify: {
dist: {
files: {
'crafty.js': ['src/crafty.js']
},
options: {
transform: ['brfs']
}
},
debug: {
files: {
'crafty.js': ['src/crafty.js']
},
options: {
debug: true,
transform: ['brfs']
}
}
},
watch: {
files: ['src/*.js'],
tasks: ['build:dev']
},
uglify: {
options: {
banner: banner
},
build: {
src: 'crafty.js',
dest: 'crafty-min.js'
}
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'tests/**/*.js'],
options: {
trailing: true,
ignores: ['tests/lib/*.js'],
globals: {
}
}
},
qunit: {
all: ['tests/index.html']
},
'node-qunit': {
all: {
deps: 'tests/lib/helperFunctions.js',
code: 'tests/index_headless.js',
tests: [
'tests/common.js',
'tests/core.js',
'tests/2d.js',
'tests/logging.js',
'tests/controls.js',
'tests/events.js',
//TODO add these once isometric adapted:
//'tests/isometric.js',
'tests/math.js',
'tests/model.js',
'tests/storage.js',
'tests/systems.js',
'tests/time.js',
'tests/tween.js',
'tests/issue746/mbr.js',
'tests/issue746/pos.js',
'tests/2D/collision/collision.js',
'tests/2D/collision/sat.js'
],
setup: {
log: {
errors: true,
//tests: true,
globalSummary: true
}
},
done: function(err, res) {
if (!err)
grunt.log.ok("NODE TESTS SUCCESSFUL");
else
grunt.log.error("NODE TESTS FAILED");
}
}
},
jsvalidate: {
files: ['crafty.js', 'tests/**/*.js']
},
connect: {
server: {
options: {
keepalive: true
}
}
},
open: {
api : {
path: 'http://localhost:8080/',
},
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-jsvalidate');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-banner');
grunt.loadNpmTasks('grunt-node-qunit');
grunt.registerTask('version', 'Takes the version into src/version.js', function() {
fs.writeFileSync('src/version.js', 'module.exports = "' + version + '";');
});
// Build development
grunt.registerTask('build:dev', ['browserify:debug', 'usebanner']);
// Build release
grunt.registerTask('build:release', ['browserify:dist', 'usebanner']);
// Building the documentation
grunt.registerTask('api', "Generate api documentation", docGen);
// Default task.
grunt.registerTask('default', ['build:dev', 'jsvalidate']);
// Run the test suite
grunt.registerTask('check', ['build:dev', 'jsvalidate', 'qunit', 'node-qunit', 'jshint']);
// Make crafty.js ready for release - minified version
grunt.registerTask('release', ['version', 'build:release', 'uglify', 'api']);
// Run only tests
grunt.registerTask('validate', ['qunit', 'node-qunit']);
grunt.registerTask('api-server', "View dynamically generated docs", runApiServer);
grunt.registerTask('view-api', ['api', 'api-server'] );
};