forked from yavorsky/riot-brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (56 loc) · 1.66 KB
/
index.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
58
59
60
61
62
63
'use strict';
const compile = require('riot').compile;
const progeny = require('progeny');
class RiotCompiler {
constructor(config) {
this.config = config.plugins.riot || {};
this.rootPath = config.paths.root;
// grab any compiler options
this.compiler_options = {};
if (this.config.template) {
this.compiler_options.template = this.config.template;
}
this.compiler_options.type = this.config.type;
// We prefer, in this order, an explicit pattern, an explicit
// extention, or a default extension
if (this.config.pattern) {
this.pattern = this.config.pattern;
} else if (this.config.extension) {
this.extension = this.config.extension;
} else {
this.pattern = /\.tag$/;
}
// Don't try checking for dependencies unless the tag
// pre-processor supports it, since progeny may fail
// on types it doesn't support.
if (this.compiler_options.type == 'jade') {
this.getDependencies = file => {
return new Promise((resolve, reject) => {
progeny({
rootPath: this.rootPath,
})(file.path, file.data, (err, res) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
});
};
}
}
compile(file) {
try {
return compile(file.data, this.compiler_options, file.path);
} catch (err) {
const loc = err.location;
if (loc) {
throw `${loc.first_line}:${loc.first_column} ${err}`;
}
throw `${err}`;
}
}
}
RiotCompiler.prototype.brunchPlugin = true;
RiotCompiler.prototype.type = 'javascript';
module.exports = RiotCompiler;