2017-03-18 09:21:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-02 06:38:57 +00:00
|
|
|
// This creates a version of `require()` in the context of the current
|
|
|
|
// directory, so we iterate over its content, which is a map statically built by
|
|
|
|
// Webpack.
|
|
|
|
// Second argument says it's recursive, third makes sure we only load templates.
|
|
|
|
const requireViews = require.context(".", true, /\.tpl$/);
|
2016-12-18 15:53:28 +00:00
|
|
|
|
2018-01-02 06:38:57 +00:00
|
|
|
module.exports = requireViews.keys().reduce((acc, path) => {
|
|
|
|
// We are going to create nested properties on the accumulator object.
|
|
|
|
let tmp = acc;
|
2017-08-28 00:55:00 +00:00
|
|
|
|
2018-01-02 06:38:57 +00:00
|
|
|
// Split path by folders, and create a new property if necessary/
|
|
|
|
// First 2 characters are "./"/
|
|
|
|
// Last element in the array ends with `.tpl` and needs to be `require`d.
|
2019-07-17 09:33:59 +00:00
|
|
|
path.substr(2)
|
|
|
|
.split("/")
|
|
|
|
.forEach((key) => {
|
|
|
|
if (key.endsWith(".tpl")) {
|
|
|
|
//
|
|
|
|
tmp[key.substr(0, key.length - 4)] = requireViews(path);
|
|
|
|
} else {
|
|
|
|
tmp[key] = tmp[key] || {};
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
tmp = tmp[key];
|
|
|
|
});
|
2018-01-02 06:38:57 +00:00
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|