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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
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);
});
}
});
|