Files
directus/src/modules/define.ts
Rijk van Zanten 7a2ee0215f Support link-modules and add docs link (#368)
* Allow link type modules

* Add docs module

* Allow buttons to render as <a>

* Update button readme

* Use link buttons in module sidebar when needed
2020-04-09 10:23:07 -04:00

32 lines
713 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 = `/:project/${options.id}${route.path}`;
}
if (route.redirect) {
route.redirect = `/:project/${options.id}${route.redirect}`;
}
return route;
});
}
return options;
}