stackpress
Version:
Incept is a content management framework.
43 lines (42 loc) • 1.84 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.default = plugin;
const node_path_1 = __importDefault(require("node:path"));
const node_url_1 = require("node:url");
function plugin(ctx) {
if (!ctx.config.get('admin'))
return;
ctx.on('route', (_req, _res, ctx) => {
try {
const client = ctx.plugin('client');
for (const model of Object.values(client.model)) {
model.admin(ctx);
}
}
catch (e) { }
});
ctx.on('idea', (req) => __awaiter(this, void 0, void 0, function* () {
const transformer = req.data('transformer');
const schema = yield transformer.schema();
if (!schema.plugin) {
schema.plugin = {};
}
const dirname = typeof __dirname === 'undefined'
? node_path_1.default.dirname((0, node_url_1.fileURLToPath)(import.meta.url))
: __dirname;
schema.plugin[`${dirname}/transform`] = {};
}));
}
;