Created
January 2, 2014 16:16
-
-
Save polidog/8221640 to your computer and use it in GitHub Desktop.
coffee+jade+yamlのalloy.jmk
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"), | |
jade_root = event.dir.home + "/alt/views", | |
coffee_root = event.dir.home + "/alt", | |
yml_root = event.dir.home + "/alt/styles", | |
view_root = event.dir.views, | |
js_root = event.dir.models, | |
tss_root = event.dir.home + "/styles", | |
path = require("path"), | |
coffee = require("coffee-script"), | |
js_yaml = require("js-yaml"); | |
var yml = {}; | |
yml.compile = function(yaml,target) { | |
var replaceVal = function(target,value,object) { | |
for ( var key in object) { | |
if (object.hasOwnProperty(key)) { | |
if (typeof(object[key]) !== "object") { | |
if (object[key] === target) { | |
object[key] = value; | |
} | |
} else { | |
replaceVal(target,value,object[key]); | |
} | |
} | |
} | |
} | |
var object = js_yaml.load(yaml); | |
if (typeof(object.parameters) === "object") { | |
var param = object.parameters; | |
delete object.parameters; | |
for (var key in param) { | |
if (param.hasOwnProperty(key) && typeof(param[key]) !== "object") { | |
replaceVal('%'+key+'%',param[key],object); | |
} | |
} | |
} | |
var json = JSON.stringify(object,null, " "); | |
json = json.replace(/['"]expr(.+?)['"]/gi, "expr$1"); | |
json = json.replace(/['"]Ti(.+?)['"]/gi, "Ti$1"); | |
json = json.replace(/['"]Titanium(.+?)['"]/gi, "Titanium$1"); | |
return json; | |
} | |
event.alloyConfig.xml = []; | |
event.alloyConfig.coffee = []; | |
// jadeの変換 | |
wrench.readdirSyncRecursive(jade_root).forEach(function(view) { | |
if (view.match(/.jade$/)) { | |
fs.writeFileSync( | |
path.join(view_root,view.replace(/\.jade$/, ".xml")), | |
jade.compile(fs.readFileSync(path.join(jade_root,view)).toString())(event) | |
); | |
} | |
}); | |
// coffeeの変換 | |
wrench.readdirSyncRecursive(coffee_root).forEach(function(target){ | |
if (target.match(/\.coffee$/)) { | |
fs.writeFileSync( | |
path.join(event.dir.home,target.replace(/\.coffee$/, ".js")), | |
coffee.compile(fs.readFileSync(path.join(coffee_root + "/" + target)).toString(), { bare: true })); | |
} | |
}); | |
// ymlの変換 | |
wrench.readdirSyncRecursive(yml_root).forEach(function(target){ | |
if (target.match(/\.yml$/)) { | |
fs.writeFileSync( | |
path.join(tss_root,target.replace(/\.yml$/, ".tss")), | |
yml.compile(fs.readFileSync(path.join(yml_root + "/" + target)).toString(), { bare: true })); | |
} | |
}); | |
}); | |
task("post:compile",function(event,logger){ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment