Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Added a grunt task to build js files from xml
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkertkoppes committed Dec 25, 2014
1 parent 0b9c892 commit f02e7d7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
66 changes: 66 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ module.exports = function(grunt) {
src: 'challenges/html/*.html',
dest: 'challenges/pdf/'
}
},

jsChallenge: {
options: {

},
files: {
src: 'challenges/xml/*.xml',
dest: 'challenges/js/'
}
}
});

Expand All @@ -118,8 +128,64 @@ module.exports = function(grunt) {
grunt.registerTask('phonegap:ios', ['phonegap:login', 'phonegap:build:ios', 'phonegap:logout']);
grunt.registerTask('phonegap:android', ['phonegap:login', 'phonegap:build:android', 'phonegap:logout']);
grunt.registerTask('html', ['saxon']);
grunt.registerTask('js', ['jsChallenge']);
grunt.registerTask('pdf', ['saxon','http-server', 'phantomJSScreenShot']);

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;
Expand Down
19 changes: 9 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ For the phonegap build, copy `pgbuildconfig.example.json` to `pgbuildconfig.json

For iOS, see [Building for iOS](https://github.com/FirstLegoLeague/fllscoring/wiki/Building-for-iOS)

To build js challenge files from the xml description files, use
(Only) when XML definition files have changed:
-----------------------------

- run `grunt html`
- run `grunt pdf`
- run `grunt js`

This will rebuild html, pdf and js versions of the challenge.

node tools\buildchallenge.js challenges\xml\2014.xml > challenges\js\2014.js
These files are also included in the repo: `challenges/html`, `challenges/pdf`, `challenges/js`

Documentation
-------------
Expand All @@ -79,14 +86,6 @@ Documentation
- [interface](docs/user_interface/readme.md)
- [internationalization](docs/i18n/readme.md)

Generating HTML and PDF scoresheets
-----------------------------

- run `grunt html`
- run `grunt pdf`

These files are also included in the repo: `challenges/html` and `challenges/pdf`

TODO's
--------

Expand Down

0 comments on commit f02e7d7

Please sign in to comment.