-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdenali-build.js
50 lines (43 loc) · 1.42 KB
/
denali-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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { Builder } = require('denali-cli');
const path = require('path');
const fs = require('fs');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const Filter = require('broccoli-filter');
const ejs = require('ejs');
class TemplateCompiler extends Filter {
processString(contents) {
let options = { client: true };
return `module.exports = ${ ejs.compile(contents, options).toString() }`;
}
}
class TextTemplateCompiler extends TemplateCompiler {
constructor() {
super(...arguments);
this.extensions = [ 'txt' ];
this.targetExtension = 'txt.js';
}
}
class HtmlTemplateCompiler extends TemplateCompiler {
constructor() {
super(...arguments);
this.extensions = [ 'html' ];
this.targetExtension = 'html.js';
}
}
module.exports = class DenaliMailerBuilder extends Builder {
processParent(tree, dir) {
if (fs.existsSync(path.join(dir, 'app', 'mailers'))) {
let textTemplates = new Funnel(tree, {
include: [ 'app/mailers/*/template.txt' ]
});
let htmlTemplates = new Funnel(tree, {
include: [ 'app/mailers/*/template.html' ]
});
let compiledTextTemplates = new TextTemplateCompiler(textTemplates);
let compiledHtmlTemplates = new HtmlTemplateCompiler(htmlTemplates);
return new MergeTrees([ tree, compiledTextTemplates, compiledHtmlTemplates ], { overwrite: true });
}
return tree;
}
};