UNPKG

@grouparoo/core

Version:
63 lines (62 loc) 3.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Apply = void 0; const cli_1 = require("../modules/cli"); const actionhero_1 = require("actionhero"); const cls_1 = require("../modules/cls"); const configLoaders_1 = require("../modules/configLoaders"); const pluginDetails_1 = require("../modules/pluginDetails"); const pluralize_1 = __importDefault(require("pluralize")); const migrations_1 = require("ah-sequelize-plugin/dist/modules/migrations"); const setting_1 = require("../modules/ops/setting"); class Apply extends actionhero_1.CLI { constructor() { super(); this.name = "apply"; this.description = "Apply changes from code config"; this.inputs = { local: { description: "Disable external validation. You can optionally pass object IDs to only disable external validation for those specific config objects and their dependents.", letter: "l", variadic: true, placeholder: "object ids", }, }; this.preInitialize = () => { cli_1.GrouparooCLI.setGrouparooRunMode(this); cli_1.GrouparooCLI.setNextDevelopmentMode(); }; cli_1.GrouparooCLI.timestampOption(this); } async run({ params }) { var _a; cli_1.GrouparooCLI.logCLI(this.name); const configDir = await (0, pluginDetails_1.getConfigDir)(true); const { configObjects, errors } = await (0, configLoaders_1.loadConfigObjects)(configDir); if (errors.length > 0) throw new Error(errors.join("; ")); const response = await cls_1.CLS.wrap(async () => { var _a; await migrations_1.Migrations.migrate(actionhero_1.config.sequelize, actionhero_1.api.sequelize, actionhero_1.log, actionhero_1.config.sequelize.migrationLogLevel); await setting_1.SettingOps.prepare(); cli_1.GrouparooCLI.logger.log(`Applying ${configObjects.length} ${(0, pluralize_1.default)("object", configObjects.length)}...`); // start the config apply process const canExternallyValidate = ((_a = params === null || params === void 0 ? void 0 : params.local) === null || _a === void 0 ? void 0 : _a.toString()) !== "true"; const locallyValidateIds = Array.isArray(params.local) && new Set(params.local); const { errors, seenIds } = await (0, configLoaders_1.processConfigObjects)(configObjects, canExternallyValidate, locallyValidateIds); if (errors.length > 0) throw errors; await (0, configLoaders_1.deleteLockedObjects)(seenIds); cli_1.GrouparooCLI.logger.log(""); cli_1.GrouparooCLI.logger.log(`✅ Config applied - ${configObjects.length} config ${(0, pluralize_1.default)("object", configObjects.length)} up-to-date!`); }, { catchError: true }); if (response instanceof Error) { (0, actionhero_1.log)((_a = response.message) !== null && _a !== void 0 ? _a : String(response), "error"); } return true; } } exports.Apply = Apply;