diff --git a/examples/crm/objectstack.config.ts b/examples/crm/objectstack.config.ts index 2cbf6ec7..23644b4d 100644 --- a/examples/crm/objectstack.config.ts +++ b/examples/crm/objectstack.config.ts @@ -8,6 +8,7 @@ import { OrderObject } from './src/objects/order.object'; import { UserObject } from './src/objects/user.object'; import { ProjectObject } from './src/objects/project.object'; import { EventObject } from './src/objects/event.object'; +import { ConsolePlugin } from '@object-ui/console'; export default defineStack({ objects: [ @@ -686,5 +687,8 @@ export default defineStack({ } ] - } -}); + }, + plugins: [ + new ConsolePlugin(), + ], +} as any); diff --git a/examples/crm/package.json b/examples/crm/package.json index f91eb209..3fae7d94 100644 --- a/examples/crm/package.json +++ b/examples/crm/package.json @@ -3,13 +3,16 @@ "version": "1.0.0", "description": "CRM Metadata Example using ObjectStack Protocol", "private": true, + "type": "module", "main": "dist/objectstack.json", "types": "src/index.ts", "exports": { ".": "./src/index.ts", - "./objectstack.config": "./objectstack.config.ts" + "./objectstack.config": "./objectstack.config.ts", + "./plugin": "./plugin.ts" }, "scripts": { + "dev": "objectstack serve --dev objectstack.config.ts", "serve": "objectstack serve objectstack.config.ts", "build": "objectstack compile objectstack.config.ts", "start": "tsx server.ts" diff --git a/examples/crm/plugin.ts b/examples/crm/plugin.ts new file mode 100644 index 00000000..7b971144 --- /dev/null +++ b/examples/crm/plugin.ts @@ -0,0 +1,58 @@ +/** + * CRM Example Plugin + * + * Exports the CRM configuration as an ObjectStack plugin that can be + * loaded by any ObjectStack application. Other projects can import + * the CRM metadata (objects, apps, dashboards, manifest) without + * needing to know the internal structure. + * + * Usage in another project: + * + * import { CRMPlugin } from '@object-ui/example-crm/plugin'; + * + * const kernel = new ObjectKernel(); + * kernel.use(new CRMPlugin()); + * + * Or import the raw config for merging: + * + * import { crmConfig } from '@object-ui/example-crm/plugin'; + */ + +import config from './objectstack.config'; + +/** Raw CRM stack configuration for direct merging */ +export const crmConfig = config; + +/** + * CRM Plugin — wraps the CRM metadata as a kernel-compatible plugin. + * + * When loaded via `kernel.use(new CRMPlugin())`, ObjectStack's AppPlugin + * will register all CRM objects, apps, dashboards, and seed data. + */ +export class CRMPlugin { + readonly name = '@object-ui/example-crm'; + readonly version = '1.0.0'; + readonly type = 'app-metadata' as const; + readonly description = 'CRM application metadata (objects, apps, dashboards, seed data)'; + + async init() { + // No initialization needed + } + + async start(ctx: any) { + const logger = ctx.logger || console; + + try { + // Dynamically import AppPlugin to keep plugin.ts dependency-light + const { AppPlugin } = await import('@objectstack/runtime'); + const appPlugin = new AppPlugin(config); + await ctx.kernel?.use?.(appPlugin); + logger.info('[CRM] Metadata loaded: objects, apps, dashboards, seed data'); + } catch (e: any) { + logger.warn(`[CRM] Could not auto-register via AppPlugin: ${e.message}`); + logger.info('[CRM] Config is available via crmConfig export for manual merging'); + } + } +} + +export default CRMPlugin; diff --git a/examples/crm/server.ts b/examples/crm/server.ts index 60082937..dbd09b53 100644 --- a/examples/crm/server.ts +++ b/examples/crm/server.ts @@ -7,7 +7,7 @@ import { InMemoryDriver } from '@objectstack/driver-memory'; import { AuthPlugin } from '@objectstack/plugin-auth'; import config from './objectstack.config'; import { pino } from 'pino'; -import { ConsolePlugin } from './console-plugin'; +import { ConsolePlugin } from '@object-ui/console'; async function startServer() { const logger = pino({ diff --git a/examples/crm/tsconfig.json b/examples/crm/tsconfig.json index 7734892f..421f1120 100644 --- a/examples/crm/tsconfig.json +++ b/examples/crm/tsconfig.json @@ -6,5 +6,5 @@ "strict": true, "skipLibCheck": true }, - "include": ["src/**/*", "objectstack.config.ts", "server.ts", "console-plugin.ts"] + "include": ["src/**/*", "objectstack.config.ts", "server.ts", "console-plugin.ts", "plugin.ts"] }