From ffcdb181d5eeacfac58166946c7d91d6592eec44 Mon Sep 17 00:00:00 2001 From: hensm Date: Wed, 24 Aug 2022 19:08:33 +0100 Subject: [PATCH] Replace JSON config import --- app/bin/build.js | 2 +- app/bin/lib/config.js | 35 +++++++++++++++++++++++++++++++++++ app/bin/lib/paths.js | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 app/bin/lib/config.js diff --git a/app/bin/build.js b/app/bin/build.js index ed44379..0139c65 100644 --- a/app/bin/build.js +++ b/app/bin/build.js @@ -10,7 +10,7 @@ import mustache from "mustache"; import pkg from "pkg"; import yargs from "yargs"; -import config from "../config.json" assert { type: "json" }; +import config from "./lib/config.js"; import * as paths from "./lib/paths.js"; const argv = await yargs() diff --git a/app/bin/lib/config.js b/app/bin/lib/config.js new file mode 100644 index 0000000..6f25bb3 --- /dev/null +++ b/app/bin/lib/config.js @@ -0,0 +1,35 @@ +// @ts-check + +import fs from "fs"; +import path from "path"; +import url from "url"; + +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); + +/** + * @typedef {object} Config + * @prop {string} author + * @prop {string} homepageUrl + * @prop {string} applicationName + * @prop {string} applicationVersion + * @prop {string} applicationDirectoryName + * @prop {string} applicationExecutableName + * @prop {string} extensionId + */ + +/** @type {Config} */ +// +let config; + +try { + config = JSON.parse( + fs.readFileSync(path.join(__dirname, "../../config.json"), { + encoding: "utf-8" + }) + ); +} catch (err) { + console.error("Error: Failed to load build config!", err); + process.exit(1); +} + +export default config; diff --git a/app/bin/lib/paths.js b/app/bin/lib/paths.js index 88ac735..26bb113 100644 --- a/app/bin/lib/paths.js +++ b/app/bin/lib/paths.js @@ -3,7 +3,7 @@ import path from "path"; import url from "url"; -import config from "../../config.json" assert { type: "json" }; +import config from "./config.js"; const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const rootPath = path.join(__dirname, "../../../");