payload-swagger
Version:
Swagger plugin for payload cms
35 lines (34 loc) • 2.21 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.swagger = void 0;
const swagger_1 = require("./swagger");
const path_1 = __importDefault(require("path"));
/**
* Payload swagger plugin
*/
const swagger = (options) => (config) => (Object.assign(Object.assign({}, config), { admin: Object.assign(Object.assign({}, config.admin), { webpack: webpackConfig => {
var _a, _b, _c;
const modifiedConfig = Object.assign(Object.assign({}, webpackConfig), { resolve: Object.assign(Object.assign({}, webpackConfig.resolve), { fallback: Object.assign({ fs: false }, (_a = webpackConfig.resolve) === null || _a === void 0 ? void 0 : _a.fallback), alias: Object.assign(Object.assign({}, (_b = webpackConfig.resolve) === null || _b === void 0 ? void 0 : _b.alias), { [path_1.default.resolve(__dirname, './swagger')]: path_1.default.resolve(__dirname, 'utils/dummy-module') }) }) });
if ((_c = config.admin) === null || _c === void 0 ? void 0 : _c.webpack) {
return config.admin.webpack(modifiedConfig);
}
return modifiedConfig;
} }), onInit: (payload) => __awaiter(void 0, void 0, void 0, function* () {
yield (0, swagger_1.loadSwagger)(payload, options);
if (config.onInit) {
return config.onInit(payload);
}
}) }));
exports.swagger = swagger;