hem
Version:
stitches CommonJS, and ties up other lose ends of web-app development.
233 lines (200 loc) • 7.06 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var compileCoffeescript, compilers, cs, fs, lmCache, log, path, projectPath, requireLocalModule;
fs = require('fs');
path = require('path');
log = require('./log');
compilers = {};
lmCache = {};
compilers.argv = {};
projectPath = path.resolve(process.cwd());
requireLocalModule = function(localModule, _path) {
var error, modulePath, relativePath;
modulePath = projectPath + "/node_modules/" + localModule;
try {
return lmCache[localModule] || (lmCache[localModule] = require(modulePath));
} catch (error1) {
error = error1;
relativePath = path.relative(projectPath, _path);
log.error("Unable to load <green>" + localModule + "</green> module to compile <yellow>" + relativePath + "</yellow>");
log.error("Try to use 'npm install " + localModule + "' in your project directory.");
if (log.VERBOSE) {
log.error(error, false);
}
return process.exit();
}
};
compilers.js = compilers.css = function(_path) {
return fs.readFileSync(_path, 'utf8');
};
require.extensions['.css'] = function(module, filename) {
var source;
source = JSON.stringify(compilers.css(filename));
return module._compile("module.exports = " + source, filename);
};
compilers.tmpl = function(_path) {
var content;
content = fs.readFileSync(_path, 'utf8');
return "module.exports = " + (JSON.stringify(content)) + ";\n";
};
require.extensions['.tmpl'] = function(module, filename) {
return module._compile(compilers.tmpl(filename), filename);
};
compilers.html = function(_path) {
var content;
content = fs.readFileSync(_path, 'utf8');
content = content.replace(/\n/g, "").replace(/[\t ]+\</g, "<").replace(/\>[\t ]+\</g, "><").replace(/\>[\t ]+$/g, ">");
return "module.exports = " + (JSON.stringify(content)) + ";\n";
};
require.extensions['.html'] = function(module, filename) {
return module._compile(compilers.html(filename), filename);
};
cs = require('coffee-script');
compilers.coffee = function(_path) {
return compileCoffeescript(_path);
};
compilers.litcoffee = function(_path) {
return compileCoffeescript(_path, true);
};
compileCoffeescript = function(_path, literate) {
var err;
if (literate == null) {
literate = false;
}
try {
return cs.compile(fs.readFileSync(_path, 'utf8'), {
filename: _path,
literate: literate
});
} catch (error1) {
err = error1;
err.message = "Coffeescript Error: " + err.message;
err.path = "Coffeescript Path: " + _path;
if (err.location) {
err.path = err.path + ":" + (err.location.first_line + 1);
}
throw err;
}
};
compilers.eco = function(_path) {
var content, eco, err;
eco = requireLocalModule('eco', _path);
try {
content = eco.precompile(fs.readFileSync(_path, 'utf8'));
} catch (error1) {
err = error1;
err = new Error(err);
err.message = "eco Error: " + err.message;
err.path = "eco Path: " + _path;
throw err;
}
return "var content = " + content + ";\nmodule.exports = content;";
};
compilers.jeco = function(_path) {
var content, eco, err;
eco = requireLocalModule('eco', _path);
try {
content = eco.precompile(fs.readFileSync(_path, 'utf8'));
} catch (error1) {
err = error1;
err = new Error(err);
err.message = "jeco Error: " + err.message;
err.path = "jeco Path: " + _path;
throw err;
}
return "module.exports = function(values, data){\n var $ = jQuery, result = $();\n values = $.makeArray(values);\n data = data || {};\n for(var i=0; i < values.length; i++) {\n var value = $.extend({}, values[i], data, {index: i});\n var elem = $((" + content + ")(value));\n elem.data('item', value);\n $.merge(result, elem);\n }\n return result;\n};";
};
require.extensions['.jeco'] = require.extensions['.eco'];
compilers.pug = function(_path) {
var content, ex, pug, source, template;
pug = requireLocalModule('pug', _path);
content = fs.readFileSync(_path, 'utf8');
try {
template = pug.compileClient(content, {
filename: _path,
compileDebug: this.argv.command === "server"
});
source = template.toString();
return "module.exports = " + source + ";";
} catch (error1) {
ex = error1;
throw new Error(ex + " in " + _path);
}
};
require.extensions['.pug'] = function(module, filename) {
return module._compile(compilers.pug(filename), filename);
};
compilers.jade = function(_path) {
var content, ex, jCompile, jade, source, template;
jade = requireLocalModule('jade', _path);
content = fs.readFileSync(_path, 'utf8');
try {
jCompile = jade.compileClient || jade.compile;
template = jCompile(content, {
filename: _path,
compileDebug: this.argv.command === "server",
client: true
});
source = template.toString();
return "module.exports = " + source + ";";
} catch (error1) {
ex = error1;
throw new Error(ex + " in " + _path);
}
};
require.extensions['.jade'] = function(module, filename) {
return module._compile(compilers.jade(filename), filename);
};
compilers.stylus = function(_path) {
var content, result, stylus;
stylus = requireLocalModule('stylus', _path);
content = fs.readFileSync(_path, 'utf8');
result = '';
stylus(content).set('include css', true).include(path.dirname(_path)).render(function(err, css) {
if (err) {
throw err;
}
return result = css;
});
return result;
};
require.extensions['.styl'] = function(module, filename) {
var source;
source = JSON.stringify(compilers.stylus(filename));
return module._compile("module.exports = " + source, filename);
};
compilers.less = function(_path) {
var content, less, result;
less = requireLocalModule('less', _path);
content = fs.readFileSync(_path, 'utf8');
result = '';
less.render(content, function(err, css) {
if (err) {
throw err;
}
return result = css;
});
return result;
};
require.extensions['.less'] = function(module, filename) {
var source;
source = JSON.stringify(compilers.less(filename));
return module._compile("module.exports = " + source, filename);
};
compilers.env = function(_path) {
var content, envhash, key, packjson;
content = fs.readFileSync(_path, 'utf8');
envhash = JSON.parse(content);
packjson = JSON.parse(fs.readFileSync(path.join(projectPath, 'package.json'), 'utf8'));
for (key in envhash) {
if (packjson[key]) {
envhash[key] = packjson[key];
}
if (process.env[key]) {
envhash[key] = process.env[key];
}
}
return "module.exports = " + JSON.stringify(envhash);
};
module.exports = compilers;
}).call(this);