-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
36 lines (31 loc) · 878 Bytes
/
build.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
var DOMParser = require('xmldom').DOMParser;
var Compile = require('./compile.js');
var fs = require('fs');
var Parser = new DOMParser();
module.exports = function(files, as_module) {
if (!(files instanceof Array)) {
files = [files];
}
var pool = {};
files.forEach(function(file) {
new Compile(
Parser.parseFromString(
fs.readFileSync(file, {encoding: 'utf8'})
), pool
).build(file.split('/').pop().split('.')[0]);
});
var template, pool_code = [];
for (template in pool) {
pool_code.push('"' + template + '":' + pool[template]);
}
return {
m: [
'var jext = require("jext");',
'module.exports = {' + pool_code.join(',') + '}'
],
w: [
'var template_list = {' + pool_code.join(',') + '};',
'window.templates = jext.pool(template_list);'
]
}[as_module ? 'm' : 'w'].join("\n");
};