/
compile.js
57 lines (56 loc) · 2.51 KB
/
compile.js
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
// Generated by CoffeeScript 1.9.1
(function() {
module.exports = {
before: "modules",
run: function(root, path, settings, doc, callback) {
var async, attachments, attachmentsPaths, coffee, compileAttachment, compileModule, extension_pattern, file_pattern, modules, modulesPaths, precompiler, processAttachments, processModules, ref, ref1, utils;
modulesPaths = (ref = settings["coffee-script"]) != null ? ref["modules"] : void 0;
attachmentsPaths = (ref1 = settings["coffee-script"]) != null ? ref1["attachments"] : void 0;
if (!((modulesPaths != null) || (attachmentsPaths != null))) {
console.log("CoffeeScript precompiler requires either a 'modules' or an 'attachment' setting");
return callback(null, doc);
}
if (modulesPaths == null) {
modulesPaths = [];
}
if (attachmentsPaths == null) {
attachmentsPaths = [];
}
async = require("async");
utils = require("kanso-utils/utils");
precompiler = require("kanso-precompiler-base");
coffee = require("coffee-script");
file_pattern = /.*\.coffee$/i;
extension_pattern = /\.coffee$/;
compileAttachment = function(filename, callback) {
var js, name, rel;
rel = utils.relpath(filename, path);
console.log("Compiling attachment " + rel);
js = coffee.compile(fs.readFileSync(filename, 'utf8'), {
filename: rel
});
name = rel.replace(extension_pattern, ".js");
precompiler.addAttachment(doc, name, filename, js);
return callback(null, doc);
};
compileModule = function(filename, callback) {
var js, name, rel;
rel = utils.relpath(filename, path);
console.log("Compiling module " + rel);
js = coffee.compile(fs.readFileSync(filename, 'utf8'), {
filename: rel
});
name = rel.replace(extension_pattern, "");
precompiler.addModule(doc, name, filename, js);
return callback(null, doc);
};
modules = precompiler.normalizePaths(settings["coffee-script"]["modules"], path);
attachments = precompiler.normalizePaths(attachmentsPaths, path);
processModules = async.apply(precompiler.processPaths, modules, file_pattern, compileModule);
processAttachments = async.apply(precompiler.processPaths, attachments, file_pattern, compileAttachment);
return async.parallel([processModules, processAttachments], function(err, results) {
return callback(err, doc);
});
}
};
}).call(this);