datasquirel/dist/package-shared/utils/backend/config/grab-config.js
Benjamin Toby 7e8bb37c09 Updates
2025-07-05 14:59:30 +01:00

25 lines
938 B
JavaScript

import fs from "fs";
import grabDirNames from "../names/grab-dir-names";
import EJSON from "../../ejson";
import envsub from "../../envsub";
export default function grabConfig(params) {
const { appConfigJSONFile, userConfigJSONFilePath } = grabDirNames({
userId: params === null || params === void 0 ? void 0 : params.userId,
});
const appConfigJSON = envsub(fs.readFileSync(appConfigJSONFile, "utf-8"));
const appConfig = EJSON.parse(appConfigJSON);
if (!userConfigJSONFilePath) {
return { appConfig, userConfig: null };
}
if (!fs.existsSync(userConfigJSONFilePath)) {
fs.writeFileSync(userConfigJSONFilePath, JSON.stringify({
main: {},
}), "utf-8");
}
const userConfigJSON = envsub(fs.readFileSync(userConfigJSONFilePath, "utf-8"));
const userConfig = (EJSON.parse(userConfigJSON) || {
main: {},
});
return { appConfig, userConfig };
}