31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = grabConfig;
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const grab_dir_names_1 = __importDefault(require("../names/grab-dir-names"));
|
|
const ejson_1 = __importDefault(require("../../ejson"));
|
|
const envsub_1 = __importDefault(require("../../envsub"));
|
|
function grabConfig(params) {
|
|
const { appConfigJSONFile, userConfigJSONFilePath } = (0, grab_dir_names_1.default)({
|
|
userId: params === null || params === void 0 ? void 0 : params.userId,
|
|
});
|
|
const appConfigJSON = (0, envsub_1.default)(fs_1.default.readFileSync(appConfigJSONFile, "utf-8"));
|
|
const appConfig = ejson_1.default.parse(appConfigJSON);
|
|
if (!userConfigJSONFilePath) {
|
|
return { appConfig, userConfig: null };
|
|
}
|
|
if (!fs_1.default.existsSync(userConfigJSONFilePath)) {
|
|
fs_1.default.writeFileSync(userConfigJSONFilePath, JSON.stringify({
|
|
main: {},
|
|
}), "utf-8");
|
|
}
|
|
const userConfigJSON = (0, envsub_1.default)(fs_1.default.readFileSync(userConfigJSONFilePath, "utf-8"));
|
|
const userConfig = (ejson_1.default.parse(userConfigJSON) || {
|
|
main: {},
|
|
});
|
|
return { appConfig, userConfig };
|
|
}
|