stackpress
Version:
Incept is a content management framework.
37 lines (36 loc) • 1.23 kB
JavaScript
import path from 'node:path';
import { fileURLToPath } from 'node:url';
export default function plugin(ctx) {
if (!ctx.config.has('view'))
return;
ctx.on('config', async (_req, _res, ctx) => {
const mode = ctx.config.path('server.mode', 'production');
if (mode === 'production') {
const { config } = await import('./config/production.js');
config(ctx);
}
else {
const { config } = await import('./config/development.js');
config(ctx);
}
});
ctx.on('route', async (_req, _res, ctx) => {
const mode = ctx.config.path('server.mode', 'production');
if (mode !== 'production') {
const { route } = await import('./config/development.js');
route(ctx);
}
});
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`] = {};
});
}
;