@crowdin/app-project-module
Version:
Module that generates for you all common endpoints for serving standalone Crowdin App
31 lines (30 loc) • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
const util_1 = require("../../util");
function register({ config, app }) {
var _a, _b;
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
if (!config.contextMenu) {
return;
}
if (Array.isArray(config.contextMenu)) {
config.contextMenu.forEach((contextMenu) => {
if ((contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.uiPath) || (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.formSchema)) {
app.use(`/context-${contextMenu.key}`, (0, ui_module_1.default)({ config, allowUnauthorized, moduleType: contextMenu.key }), (0, render_ui_module_1.default)(contextMenu));
}
});
}
else {
// backward compatibility will be removed after migration
if (((_a = config.contextMenu) === null || _a === void 0 ? void 0 : _a.uiPath) || ((_b = config.contextMenu) === null || _b === void 0 ? void 0 : _b.formSchema)) {
app.use('/context', (0, ui_module_1.default)({ config, allowUnauthorized, moduleType: config.contextMenu.key }), (0, render_ui_module_1.default)(config.contextMenu));
}
}
}
exports.register = register;