Created
April 4, 2014 15:47
-
-
Save Agnostic/9977399 to your computer and use it in GitHub Desktop.
Titanium Alloy + Jade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you don't already have alloy.jmk generated do this inside your app/project folder | |
// $ alloy generate jmk | |
task("pre:compile", function(event,logger) { | |
var wrench = require("wrench"), | |
fs = require("fs"), | |
jade = require("jade"), | |
view_root = event.dir.project, | |
path = require("path"); | |
event.alloyConfig.xml = []; | |
wrench.readdirSyncRecursive(view_root).forEach(function(view) { | |
if (view.match(/.jade$/) | |
&& view.indexOf('templates') === -1 | |
&& view.indexOf('includes') === -1) { | |
event.alloyConfig.xml.push(view.replace(/\.jade$/, ".xml")); | |
try { | |
fs.writeFileSync( | |
path.join(view_root,view.replace(/\.jade$/, ".xml")), | |
jade.compile(fs.readFileSync(path.join(view_root,view)).toString(), | |
{filename: path.join(view_root, view), | |
pretty: true})(event)); | |
} catch(e) { | |
logger.error("ERROR: " + view + "\n" + JSON.stringify(e)); | |
process.exit(1); | |
} | |
} | |
}); | |
}); | |
// Remove generated xml files except index.xml | |
// (Titanium build checks for this file to compile) | |
task("post:compile",function(event,logger){ | |
var fs = require("fs"), | |
view_root = event.dir.project, | |
path = require("path"); | |
event.alloyConfig.xml.forEach(function(view){ | |
if (!view.match(/index.xml/g)) { | |
fs.unlinkSync(path.join(view_root, view)); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment