stackpress
Version:
Incept is a content management framework.
28 lines (27 loc) • 846 B
JavaScript
import path from 'node:path';
import { fileURLToPath } from 'node:url';
export default function plugin(ctx) {
ctx.on('listen', (_req, _res, ctx) => {
try {
const client = ctx.plugin('client');
if (!client?.model)
return;
for (const model of Object.values(client.model)) {
ctx.use(model.events);
}
}
catch (e) { }
});
ctx.on('idea', async (req) => {
const transformer = req.data('transformer');
const schema = await transformer.schema();
if (!schema.plugin) {
schema.plugin = {};
}
const dirname = typeof __dirname === 'undefined'
? path.dirname(fileURLToPath(import.meta.url))
: __dirname;
schema.plugin[`${dirname}/transform`] = {};
});
}
;