Roll Back compile version
This commit is contained in:
+18
-12
@@ -1,23 +1,29 @@
|
||||
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({
|
||||
"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 = envsub(fs.readFileSync(appConfigJSONFile, "utf-8"));
|
||||
const appConfig = EJSON.parse(appConfigJSON);
|
||||
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.existsSync(userConfigJSONFilePath)) {
|
||||
fs.writeFileSync(userConfigJSONFilePath, JSON.stringify({
|
||||
if (!fs_1.default.existsSync(userConfigJSONFilePath)) {
|
||||
fs_1.default.writeFileSync(userConfigJSONFilePath, JSON.stringify({
|
||||
main: {},
|
||||
}), "utf-8");
|
||||
}
|
||||
const userConfigJSON = envsub(fs.readFileSync(userConfigJSONFilePath, "utf-8"));
|
||||
const userConfig = (EJSON.parse(userConfigJSON) || {
|
||||
const userConfigJSON = (0, envsub_1.default)(fs_1.default.readFileSync(userConfigJSONFilePath, "utf-8"));
|
||||
const userConfig = (ejson_1.default.parse(userConfigJSON) || {
|
||||
main: {},
|
||||
});
|
||||
return { appConfig, userConfig };
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import grabConfig from "./grab-config";
|
||||
export default function grabMainConfig(params) {
|
||||
const { appConfig } = grabConfig();
|
||||
const { userConfig } = grabConfig({ userId: params === null || params === void 0 ? void 0 : params.userId });
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabMainConfig;
|
||||
const grab_config_1 = __importDefault(require("./grab-config"));
|
||||
function grabMainConfig(params) {
|
||||
const { appConfig } = (0, grab_config_1.default)();
|
||||
const { userConfig } = (0, grab_config_1.default)({ userId: params === null || params === void 0 ? void 0 : params.userId });
|
||||
return { appMainConfig: appConfig.main, userMainConfig: userConfig === null || userConfig === void 0 ? void 0 : userConfig.main };
|
||||
}
|
||||
|
||||
+16
-10
@@ -1,25 +1,31 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "../names/grab-dir-names";
|
||||
import grabConfig from "./grab-config";
|
||||
import _ from "lodash";
|
||||
export default function updateUserConfig({ newConfig, userId, }) {
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = updateUserConfig;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const grab_dir_names_1 = __importDefault(require("../names/grab-dir-names"));
|
||||
const grab_config_1 = __importDefault(require("./grab-config"));
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
function updateUserConfig({ newConfig, userId, }) {
|
||||
if (!userId || !newConfig) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `UserID or newConfig not provided`,
|
||||
};
|
||||
}
|
||||
const { userConfigJSONFilePath } = grabDirNames({
|
||||
const { userConfigJSONFilePath } = (0, grab_dir_names_1.default)({
|
||||
userId,
|
||||
});
|
||||
if (!userConfigJSONFilePath || !fs.existsSync(userConfigJSONFilePath)) {
|
||||
if (!userConfigJSONFilePath || !fs_1.default.existsSync(userConfigJSONFilePath)) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `userConfigJSONFilePath not found!`,
|
||||
};
|
||||
}
|
||||
const { userConfig: existingUserConfig } = grabConfig({ userId });
|
||||
const updateConfig = _.merge(existingUserConfig, newConfig);
|
||||
fs.writeFileSync(userConfigJSONFilePath, JSON.stringify(updateConfig), "utf-8");
|
||||
const { userConfig: existingUserConfig } = (0, grab_config_1.default)({ userId });
|
||||
const updateConfig = lodash_1.default.merge(existingUserConfig, newConfig);
|
||||
fs_1.default.writeFileSync(userConfigJSONFilePath, JSON.stringify(updateConfig), "utf-8");
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user