Skip to content

Commit

Permalink
refactor: use asset functions from code.js - part2
Browse files Browse the repository at this point in the history
  • Loading branch information
azech-hqs committed Oct 27, 2023
1 parent 93dc67e commit 7da589b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
20 changes: 3 additions & 17 deletions build_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,21 @@
* 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("@exabyte-io/code.js/dist/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({
utils.buildJsAssetFromYaml({
assetPath: "./templates/templates.yml",
targetPath: "./src/js/data/templates.js",
dataKey: "allTemplates",
});

buildAsset({
utils.buildJsAssetFromYaml({
assetPath: "./applications/application_data.yml",
targetPath: "./src/js/data/application_data.js",
dataKey: "applicationData",
});

buildAsset({
utils.buildJsAssetFromYaml({
assetPath: "./executables/tree.yml",
targetPath: "./src/js/data/tree.js",
dataKey: "applicationTree",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"homepage": "https://github.com/Exabyte-io/application-flavors",
"devDependencies": {
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/code.js": "git+https://github.com/Exabyte-io/code.js.git#14d84f7809b76c6fcc3339a1d48d436c15af4d50",
"@exabyte-io/code.js": "git+https://github.com/Exabyte-io/code.js.git#590a1d5ddbd532e513af6651176132e874f13d9c",
"chai": "^4.3.4",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^19.0.2",
Expand Down

0 comments on commit 7da589b

Please sign in to comment.