mirror of
https://github.com/directus/directus.git
synced 2026-01-29 03:37:56 -05:00
30 lines
692 B
TypeScript
30 lines
692 B
TypeScript
import { i18n } from '@/lang/';
|
|
import { ModuleDefineParam, ModuleContext, ModuleConfig } from './types';
|
|
|
|
export function defineModule(config: ModuleDefineParam | ((context: ModuleContext) => ModuleConfig)): ModuleConfig {
|
|
let options: ModuleConfig;
|
|
|
|
if (typeof config === 'function') {
|
|
const context: ModuleContext = { i18n };
|
|
options = config(context);
|
|
} else {
|
|
options = config;
|
|
}
|
|
|
|
if (options.routes !== undefined) {
|
|
options.routes = options.routes.map((route) => {
|
|
if (route.path) {
|
|
route.path = `/${options.id}${route.path}`;
|
|
}
|
|
|
|
if (route.redirect) {
|
|
route.redirect = `/${options.id}${route.redirect}`;
|
|
}
|
|
|
|
return route;
|
|
});
|
|
}
|
|
|
|
return options;
|
|
}
|