public
Last active

A cordova-client hook to compile ./www/jade/index.jade to ./www/index.html as part of the build process.

  • Download Gist
compile_jade.js
JavaScript
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
#!/usr/bin/env node
/**
* Darryl Pogue, 2012
*
* A cordova-client hook to compile ./www/jade/index.jade to ./www/index.html as part of the build process.
* Requires node.js and jade to be installed.
*
* Copy this into the .cordova/hooks/before_build folder of your project, and make it executable.
*/
var fs = require('fs');
var path = require('path');
 
function compile_jade(src, dst) {
var jade = require('jade');
var options = {
filename: src,
pretty: true
};
 
try {
var stat = fs.lstatSync(src);
if (stat.isFile()) {
var str = fs.readFileSync(src, 'utf8');
var fn = jade.compile(str, options);
fs.writeFileSync(dst, fn(options));
}
} catch (e) {
throw e;
}
}
 
var assets = path.join('.', 'www');
 
// If ./www/jade/ exists, compile the jade files
var jade_index = path.join(assets, 'jade', 'index.jade');
if (fs.existsSync(jade_index)) {
compile_jade(jade_index, path.join(assets, 'index.html'));
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.