-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_templates.js
38 lines (34 loc) · 1.17 KB
/
build_templates.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
/**
* build_templates uses node API to read all jinja templates from the FS
* at build time and writes them out to a single templates.js file for
* downstream consumption to avoid FS calls in the browser.
*/
const fs = require("fs");
const yaml = require("js-yaml");
const utils = require("@mat3ra/code/dist/js/utils");
function buildAsset({ assetPath, targetPath, dataKey = "" }) {
const fileContent = fs.readFileSync(assetPath);
const obj = yaml.load(fileContent, { schema: utils.JsYamlAllSchemas });
const ignore = "/* eslint-disable */\n";
fs.writeFileSync(
targetPath,
ignore + `module.exports = {${dataKey}: ` + JSON.stringify(obj) + "}\n",
"utf8",
);
console.log(`Written asset "${assetPath}" to "${targetPath}"`);
}
buildAsset({
assetPath: "./templates/templates.yml",
targetPath: "./src/js/data/templates.js",
dataKey: "allTemplates",
});
buildAsset({
assetPath: "./applications/application_data.yml",
targetPath: "./src/js/data/application_data.js",
dataKey: "applicationData",
});
buildAsset({
assetPath: "./executables/tree.yml",
targetPath: "./src/js/data/tree.js",
dataKey: "applicationTree",
});