forked from FirstLegoLeague/fllscoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
314 lines (283 loc) · 10.3 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
function getPhonegapConfig() {
var configPath = './pgbuildconfig.json';
var fs = require('fs');
if (fs.existsSync(configPath)) {
var pgbuildconfig = require(configPath);
return {
username: pgbuildconfig.username,
password: pgbuildconfig.password,
platforms: ['ios', 'android','wp8']
};
} else {
return {};
}
}
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
nwjs: { // nw.js, formerly known as "node-webkit"
options: {
buildDir: './nw-builds', // output folder for nwjs apps
cacheDir: './nw-cache',
platforms: ['win', 'osx64', 'linux'],
version: 'v0.12.0' // nwjs version to use
},
src: ['./src/**/*'] // Your node-wekit app
},
compress: {
main: {
options: {
archive: 'temp/app.zip'
},
files: [{
expand: true,
src: ['**'],
cwd: 'src/',
dest: '/'
}]
}
},
"phonegap": {
config: {
root: "src",
config: "src/config.xml",
html: "fgindex.html",
name: function(){
var pkg = grunt.file.readJSON('package.json');
return pkg.name;
},
debuggable: true,
releases: 'releases',
platforms: ['ios', 'android','wp8'],
plugins: [
'org.apache.cordova.file'
],
verbose: true,
releaseName: function(){
var pkg = grunt.file.readJSON('package.json');
return(pkg.name + '-' + pkg.version);
},
remote: getPhonegapConfig()
}
},
karma: {
options: {
configFile: 'karma.conf.js',
},
unit: {
runnerPort: 9999,
singleRun: true,
browsers: ['Chrome']
}
},
saxon: {
options: {
saxonPath: 'tools/saxon9he.jar',
xslPath: 'challenges/xsl/challenge.xsl'
},
files: {
src: 'challenges/xml/*.xml',
dest: 'challenges/html/'
}
},
'http-server': {
'dev': {
root: "challenges/html/",
port: 8282,
host: "127.0.0.1",
// cache: < sec > ,
// showDir: true,
// autoIndex: true,
// server default file extension
ext: "html",
// run in parallel with other tasks
runInBackground: true
}
},
phantomJSScreenShot: {
options: {
phantomPath: 'node_modules/.bin/phantomjs',
address: "http://127.0.0.1:8282/"
},
files: {
src: 'challenges/html/*.html',
dest: 'challenges/pdf/'
}
},
jsChallenge: {
options: {
},
files: {
src: 'challenges/xml/*.xml',
dest: 'challenges/js/'
}
}
});
grunt.loadNpmTasks('grunt-nw-builder');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-http-server');
grunt.loadNpmTasks('grunt-phonegap');
grunt.registerTask('phonegap', ['phonegap:login', 'phonegap:build', 'phonegap:logout']);
grunt.registerTask('phonegap:ios', ['phonegap:login', 'phonegap:build:ios', 'phonegap:logout']);
grunt.registerTask('phonegap:android', ['phonegap:login', 'phonegap:build:android', 'phonegap:logout']);
grunt.registerTask('phonegap:wp8', ['phonegap:login', 'phonegap:build:wp8', 'phonegap:logout']);
grunt.registerTask('html', ['saxon']);
grunt.registerTask('js', ['jsChallenge']);
grunt.registerTask('pdf', ['saxon','http-server', 'phantomJSScreenShot']);
grunt.registerTask('challenge', ['js', 'pdf']); //html is generated with pdf
grunt.registerMultiTask('jsChallenge', function() {
var options = this.options();
var npath = require('path');
var nfs = require('fs');
var Q = require('q');
var done = this.async();
var exec = require('child_process').exec;
function process(filepath,dest) {
return Q.promise(function(resolve,reject) {
var base = npath.basename(filepath, '.html');
var cmd = [
'node',
'"tools/buildchallenge.js"',
'"' + filepath + '"',
'>',
'"' + dest + '"'
].join(' ');
// console.log(cmd);
// resolve()
exec(cmd, function(error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
reject(error);
}
resolve();
});
});
}
this.files.forEach(function(f) {
f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
return function() {
var base = npath.basename(filepath, '.xml');
var dest = npath.resolve(f.dest, base) + '.js';
// console.log(filepath);
// console.log(dest);
return process(filepath,dest);
};
}).reduce(function(pending,promise) {
return pending.then(promise);
},Q()).then(done,done);
});
});
grunt.registerMultiTask('saxon', function() {
var options = this.options();
var saxonPath = options.saxonPath;
var xslPath = options.xslPath;
var npath = require('path');
var nfs = require('fs');
var Q = require('q');
var saxon = require('saxon-stream2');
var done = this.async();
function process(filepath,dest) {
return Q.promise(function(resolve,reject) {
var xslt = saxon(saxonPath, xslPath, {
timeout: 5000
});
nfs.createReadStream(filepath, {
encoding: 'utf-8'
})
.pipe(xslt)
.on('error', function(err) {
console.log('xslt error:',err);
reject(err);
})
.pipe(nfs.createWriteStream(dest))
.on('error', function(err) {
console.log('write error:',err);
reject(err);
})
.on('finish', function() {
console.log('done');
resolve();
});
});
}
this.files.forEach(function(f) {
f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
return function() {
var base = npath.basename(filepath, '.xml');
var dest = npath.resolve(f.dest, base) + '.html';
// console.log(filepath);
// console.log(dest);
return process(filepath,dest);
};
}).reduce(function(pending,promise) {
return pending.then(promise);
},Q()).then(done,done);
});
});
grunt.registerMultiTask('phantomJSScreenShot', function() {
var options = this.options();
var phantomPath = options.phantomPath;
var address = options.address;
var npath = require('path');
var nfs = require('fs');
var Q = require('q');
var done = this.async();
var exec = require('child_process').exec;
function process(filepath,dest) {
return Q.promise(function(resolve,reject) {
var base = npath.basename(filepath, '.html');
dest = npath.resolve(dest, base) + '.pdf';
var cmd = [
'"' + phantomPath + '"',
'"tools/rasterize.js"',
'"' + address + base + '.html"',
'"' + dest + '"',
'a4'
].join(' ');
exec(cmd, function(error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
reject(error);
}
resolve();
});
});
}
this.files.forEach(function(f) {
f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
return function() {
return process(filepath,f.dest);
};
}).reduce(function(pending,promise) {
return pending.then(promise);
},Q()).then(done,done);
});
});
// Default task(s).
// grunt.registerTask('default', ['uglify']);
};