Replace JSON config import

This commit is contained in:
hensm
2022-08-24 19:08:33 +01:00
parent c720eaf4b2
commit ffcdb181d5
3 changed files with 37 additions and 2 deletions

View File

@@ -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()

35
app/bin/lib/config.js Normal file
View File

@@ -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;

View File

@@ -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, "../../../");