Created
May 23, 2013 13:49
-
-
Save killtw/5636206 to your computer and use it in GitHub Desktop.
Titanium Alloy with jade and coffeescript
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
task("pre:compile", function(event,logger) { | |
var wrench = require("wrench"), | |
fs = require("fs"), | |
jade = require("jade"), | |
view_root = event.dir.views, | |
controller_root = event.dir.controllers, | |
path = require("path"), | |
coffee = require("coffee-script"); | |
event.alloyConfig.xml = []; | |
event.alloyConfig.coffee = []; | |
wrench.readdirSyncRecursive(view_root).forEach(function(view) { | |
if (view.match(/.jade$/)) { | |
event.alloyConfig.xml.push(view.replace(/\.jade$/, ".xml")); | |
fs.writeFileSync( | |
path.join(view_root,view.replace(/\.jade$/, ".xml")), | |
jade.compile(fs.readFileSync(path.join(view_root,view)).toString())(event)); | |
} | |
}); | |
wrench.readdirSyncRecursive(controller_root).forEach(function(controller) { | |
if (controller.match(/.coffee$/)) { | |
event.alloyConfig.coffee.push(controller.replace(/\.coffee$/, ".js")); | |
fs.writeFileSync( | |
path.join(controller_root,controller.replace(/\.coffee$/, ".js")), | |
coffee.compile(fs.readFileSync(path.join(controller_root,controller)).toString(), { bare: true })); | |
} | |
}); | |
}); | |
task("post:compile",function(event,logger){ | |
var fs = require("fs"), | |
view_root = event.dir.views, | |
controller_root = event.dir.controllers, | |
path = require("path"); | |
event.alloyConfig.xml = []; | |
event.alloyConfig.coffee = []; | |
event.alloyConfig.xml.forEach(function(view){ | |
if (!view.match(/.xml$/)) { | |
fs.unlinkSync(path.join(view_root, view)); | |
} | |
}); | |
event.alloyConfig.coffee.forEach(function(controller){ | |
if (!controller.match(/.js$/)) { | |
fs.unlinkSync(path.join(controller_root, controller)); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment