Skip to content

Instantly share code, notes, and snippets.

@ryugoo ryugoo/stylus.jmk.js
Last active Dec 11, 2015

Embed
What would you like to do?
Stylus to Alloy JMK
var fs = require("fs");
var path = require("path");
var util = require("util");
var styl = require("stylus");
var wrench = require("wrench");
function compileTSS(root, view) {
var data = fs.readFileSync(path.join(root, view), "utf8"),
tss;
styl.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("pre:compile", function (event, logger) {
var root = event.dir.styles;
wrench.readdirSyncRecursive(root).forEach(function (view) {
if (view.match("styl$")) {
var tss = compileTSS(root, view);
fs.writeFileSync(path.join(root, view.replace("styl", "tss")), tss);
}
});
});
task("post:compile", function (event, logger) {});
@shinriyo

This comment has been minimized.

Copy link

shinriyo commented Mar 30, 2014

[ERROR] : : Cannot call method 'replace' of undefined
[ERROR] : Alloy compiler failed
になりませんか?

@ninjaYang

This comment has been minimized.

Copy link

ninjaYang commented Sep 24, 2014

stylusにエラーがある場合cssが空になる。
var Log = require("log");
var log = new Log(Log.INFO);
styl.render(data, function(err, css) {
if (err)
log.error(err);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.