Last active
December 14, 2015 21:39
-
-
Save polidog/5153107 to your computer and use it in GitHub Desktop.
alloyでCoffessScriptとjadeとstylusを使う為のjmkファイルですよ^^
[追記] event.alloyConfig.deploytypeがdevelopmentの時は基本的にコンパイルしたjs,tss,xmlを消さないように修正
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"), | |
path = require("path"), | |
coffee = require("coffee-script"), | |
stylus = require("stylus"); | |
event.alloyConfig.coffee = []; | |
event.alloyConfig.jade = []; | |
event.alloyConfig.stylus = []; | |
// jade | |
wrench.readdirSyncRecursive(event.dir.views).forEach(function(view) { | |
if (view.match(/.jade$/)) { | |
event.alloyConfig.jade.push(view.replace(/\.jade$/, ".xml")); | |
fs.writeFileSync( | |
path.join(event.dir.views,view.replace(/\.jade$/, ".xml")), | |
jade.compile(fs.readFileSync(path.join(event.dir.views,view)).toString())(event)); | |
} | |
}); | |
// coffee-script | |
wrench.readdirSyncRecursive(event.dir.home).forEach(function(target){ | |
if (target.match(/\.coffee$/)) { | |
event.alloyConfig.coffee.push(target.replace(/\.coffee$/, ".js")); | |
fs.writeFileSync( | |
path.join(event.dir.home,target.replace(/\.coffee$/, ".js")), | |
coffee.compile(fs.readFileSync(path.join(event.dir.home + "/" + target)).toString(), { bare: true })); | |
} | |
}); | |
// stylus | |
wrench.readdirSyncRecursive(event.dir.styles).forEach(function(target){ | |
if (target.match(/\.styl$/)) { | |
event.alloyConfig.stylus.push(target.replace(/\.styl$/, ".tss")); | |
fs.writeFileSync(path.join(event.dir.styles, target.replace("styl", "tss")), compileTSS(event.dir.styles, target)); | |
} | |
}); | |
var compileTSS = function(root,target) { | |
var data = fs.readFileSync(path.join(root,target), 'utf-8'), | |
tss; | |
stylus.render(data,function(err,css){ | |
css = css.replace(/;/gi, ","); | |
css = css.replace(/\}/gi, "},"); | |
css = css.replace(/(.+?).?\{/gi, "\"$1\": {"); | |
css = css.replace(/,\n\},/gi, "\n\}"); | |
css = css.replace(/\}\n\"/gi, "\},\n\""); | |
css = css.replace(/['"]expr(.+?)['"]/gi, "expr$1"); | |
css = css.replace(/['"]Ti(.+?)['"]/gi, "Ti$1"); | |
css = css.replace(/['"]Titanium(.+?)['"]/gi, "Titanium$1"); | |
tss = css; | |
}); | |
return tss; | |
} | |
}); | |
task("post:compile",function(event,logger){ | |
var fs = require("fs"), | |
path = require("path"); | |
if (event.alloyConfig.deploytype != 'development') { | |
event.alloyConfig.jade.forEach(function(target){ | |
if (!target.match(/index.xml/g)) fs.unlinkSync(path.join(event.dir.views, target)); | |
}); | |
event.alloyConfig.coffee.forEach(function(target){ | |
fs.unlinkSync(event.dir.home + "/" + target); | |
}); | |
event.alloyConfig.stylus.forEach(function(target){ | |
fs.unlinkSync(event.dir.styles + "/" + target); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment