|
12 | 12 | * because CRM and Kitchen Sink both define an `account` object, which would |
13 | 13 | * trigger an ownership conflict in the ObjectQL Schema Registry. |
14 | 14 | * |
| 15 | + * Plugins: Each example app exports a plugin class (CRMPlugin, TodoPlugin, |
| 16 | + * KitchenSinkPlugin) that implements the AppMetadataPlugin interface. |
| 17 | + * For standalone use, each plugin can be loaded independently via |
| 18 | + * `kernel.use(new CRMPlugin())`. In the dev workspace, we collect their |
| 19 | + * configs via `getConfig()` and merge them into a single AppPlugin. |
15 | 20 | */ |
16 | 21 | import { defineStack } from '@objectstack/spec'; |
17 | 22 | import { AppPlugin, DriverPlugin } from '@objectstack/runtime'; |
18 | 23 | import { ObjectQLPlugin } from '@objectstack/objectql'; |
19 | 24 | import { InMemoryDriver } from '@objectstack/driver-memory'; |
20 | 25 | import { HonoServerPlugin } from '@objectstack/plugin-hono-server'; |
21 | 26 | import { ConsolePlugin } from '@object-ui/console'; |
22 | | -import CrmConfig from './examples/crm/objectstack.config'; |
23 | | -import TodoConfig from './examples/todo/objectstack.config'; |
24 | | -import KitchenSinkConfig from './examples/kitchen-sink/objectstack.config'; |
| 27 | +import { CRMPlugin } from './examples/crm/plugin'; |
| 28 | +import { TodoPlugin } from './examples/todo/plugin'; |
| 29 | +import { KitchenSinkPlugin } from './examples/kitchen-sink/plugin'; |
25 | 30 |
|
26 | | -const crm = (CrmConfig as any).default || CrmConfig; |
27 | | -const todo = (TodoConfig as any).default || TodoConfig; |
28 | | -const kitchenSink = (KitchenSinkConfig as any).default || KitchenSinkConfig; |
| 31 | +// Instantiate example plugins |
| 32 | +const plugins = [new CRMPlugin(), new TodoPlugin(), new KitchenSinkPlugin()]; |
29 | 33 |
|
30 | | -// Base objects from built-in examples |
31 | | -const baseObjects = [ |
32 | | - ...(crm.objects || []), |
33 | | - ...(todo.objects || []), |
34 | | - ...(kitchenSink.objects || []), |
35 | | -]; |
| 34 | +// Collect raw configs from each plugin via getConfig() |
| 35 | +const allConfigs = plugins.map((p) => { |
| 36 | + const raw = p.getConfig(); |
| 37 | + return (raw as any).default || raw; |
| 38 | +}); |
36 | 39 |
|
37 | | -// Collect all example configs for view merging |
38 | | -const allConfigs = [crm, todo, kitchenSink]; |
| 40 | +// Base objects from all plugins |
| 41 | +const baseObjects = allConfigs.flatMap((cfg: any) => cfg.objects || []); |
39 | 42 |
|
40 | 43 | // --------------------------------------------------------------------------- |
41 | 44 | // Merge stack-level views into object definitions. |
@@ -110,44 +113,22 @@ function mergeActionsIntoObjects(objects: any[], configs: any[]): any[] { |
110 | 113 | }); |
111 | 114 | } |
112 | 115 |
|
113 | | -// Merge all example configs into a single app bundle for AppPlugin |
| 116 | +// Merge all plugin configs into a single app bundle for AppPlugin |
114 | 117 | const mergedApp = defineStack({ |
115 | 118 | manifest: { |
116 | 119 | id: 'dev-workspace', |
117 | 120 | name: 'dev_workspace', |
118 | 121 | version: '0.0.0', |
119 | 122 | description: 'ObjectUI monorepo development workspace', |
120 | 123 | type: 'app', |
121 | | - data: [ |
122 | | - ...(crm.manifest?.data || []), |
123 | | - ...(todo.manifest?.data || []), |
124 | | - ...(kitchenSink.manifest?.data || []), |
125 | | - ], |
| 124 | + data: allConfigs.flatMap((cfg: any) => cfg.manifest?.data || []), |
126 | 125 | }, |
127 | 126 | objects: baseObjects, |
128 | | - views: [ |
129 | | - ...(crm.views || []), |
130 | | - ...(todo.views || []), |
131 | | - ...(kitchenSink.views || []), |
132 | | - ], |
133 | | - apps: [ |
134 | | - ...(crm.apps || []), |
135 | | - ...(todo.apps || []), |
136 | | - ...(kitchenSink.apps || []), |
137 | | - ], |
138 | | - dashboards: [ |
139 | | - ...(crm.dashboards || []), |
140 | | - ...(todo.dashboards || []), |
141 | | - ...(kitchenSink.dashboards || []), |
142 | | - ], |
143 | | - reports: [ |
144 | | - ...(crm.reports || []), |
145 | | - ], |
146 | | - pages: [ |
147 | | - ...(crm.pages || []), |
148 | | - ...(todo.pages || []), |
149 | | - ...(kitchenSink.pages || []), |
150 | | - ], |
| 127 | + views: allConfigs.flatMap((cfg: any) => cfg.views || []), |
| 128 | + apps: allConfigs.flatMap((cfg: any) => cfg.apps || []), |
| 129 | + dashboards: allConfigs.flatMap((cfg: any) => cfg.dashboards || []), |
| 130 | + reports: allConfigs.flatMap((cfg: any) => cfg.reports || []), |
| 131 | + pages: allConfigs.flatMap((cfg: any) => cfg.pages || []), |
151 | 132 | } as any); |
152 | 133 |
|
153 | 134 | // Re-merge listViews and actions that defineStack stripped from objects |
|
0 commit comments