-
Notifications
You must be signed in to change notification settings - Fork 3
/
Gruntfile.js
73 lines (63 loc) · 2.21 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
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jsChallenge: {
options: {
},
files: {
src: 'challenges/xml/*.xml',
dest: 'challenges/js/'
}
}
});
grunt.registerTask('js', ['jsChallenge']);
grunt.registerMultiTask('jsChallenge', function() {
var npath = require('path');
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 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);
});
});
// Default task(s).
grunt.registerTask('default', ['jsChallenge']);
};