|
| 1 | +/** |
| 2 | + * CRM Example Plugin |
| 3 | + * |
| 4 | + * Exports the CRM configuration as an ObjectStack plugin that can be |
| 5 | + * loaded by any ObjectStack application. Other projects can import |
| 6 | + * the CRM metadata (objects, apps, dashboards, manifest) without |
| 7 | + * needing to know the internal structure. |
| 8 | + * |
| 9 | + * Usage in another project: |
| 10 | + * |
| 11 | + * import { CRMPlugin } from '@object-ui/example-crm/plugin'; |
| 12 | + * |
| 13 | + * const kernel = new ObjectKernel(); |
| 14 | + * kernel.use(new CRMPlugin()); |
| 15 | + * |
| 16 | + * Or import the raw config for merging: |
| 17 | + * |
| 18 | + * import { crmConfig } from '@object-ui/example-crm/plugin'; |
| 19 | + */ |
| 20 | + |
| 21 | +import config from './objectstack.config'; |
| 22 | + |
| 23 | +/** Raw CRM stack configuration for direct merging */ |
| 24 | +export const crmConfig = config; |
| 25 | + |
| 26 | +/** |
| 27 | + * CRM Plugin — wraps the CRM metadata as a kernel-compatible plugin. |
| 28 | + * |
| 29 | + * When loaded via `kernel.use(new CRMPlugin())`, ObjectStack's AppPlugin |
| 30 | + * will register all CRM objects, apps, dashboards, and seed data. |
| 31 | + */ |
| 32 | +export class CRMPlugin { |
| 33 | + readonly name = '@object-ui/example-crm'; |
| 34 | + readonly version = '1.0.0'; |
| 35 | + readonly type = 'app-metadata' as const; |
| 36 | + readonly description = 'CRM application metadata (objects, apps, dashboards, seed data)'; |
| 37 | + |
| 38 | + async init() { |
| 39 | + // No initialization needed |
| 40 | + } |
| 41 | + |
| 42 | + async start(ctx: any) { |
| 43 | + const logger = ctx.logger || console; |
| 44 | + |
| 45 | + try { |
| 46 | + // Dynamically import AppPlugin to keep plugin.ts dependency-light |
| 47 | + const { AppPlugin } = await import('@objectstack/runtime'); |
| 48 | + const appPlugin = new AppPlugin(config); |
| 49 | + await ctx.kernel?.use?.(appPlugin); |
| 50 | + logger.info('[CRM] Metadata loaded: objects, apps, dashboards, seed data'); |
| 51 | + } catch (e: any) { |
| 52 | + logger.warn(`[CRM] Could not auto-register via AppPlugin: ${e.message}`); |
| 53 | + logger.info('[CRM] Config is available via crmConfig export for manual merging'); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +export default CRMPlugin; |
0 commit comments