-
Notifications
You must be signed in to change notification settings - Fork 35
/
handlebars-tree.js
50 lines (45 loc) · 1.46 KB
/
handlebars-tree.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
/*!
* Copyright (c) 2014-present Cliqz GmbH. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
const fs = require('fs');
const Funnel = require('broccoli-funnel');
const concat = require('broccoli-concat');
const MergeTrees = require('broccoli-merge-trees');
const broccoliHandlebars = require('broccoli-handlebars-precompiler');
const cliqzConfig = require('../config');
module.exports = function getHandlebarsTree(modulesTree) {
const trees = cliqzConfig.modules.filter((name) => {
const modulePath = `modules/${name}`;
try {
fs.statSync(`${modulePath}/sources/templates`); // throws if not found
return true;
} catch (e) {
return false;
}
}).map((name) => {
const tree = new Funnel(modulesTree, {
include: ['**/*.hbs'],
srcDir: `${name}/sources/templates`,
destDir: `${name}/templates`
});
return {
name,
tree: broccoliHandlebars(tree, {
srcDir: `${name}/templates`,
namespace: 'templates'
})
};
}).map(templatesTree => concat(templatesTree.tree, {
outputFile: `${templatesTree.name}/templates.js`,
inputFiles: [
'**/*.js'
],
header: "'use strict'; import Handlebars from 'handlebars';",
footer: 'export default templates;'
}));
return new MergeTrees(trees);
};