Skip to content

Commit 125bdb2

Browse files
Copilothotlong
andcommitted
feat(crm): add console plugin integration and dev mode for standalone debugging
- Add ConsolePlugin to objectstack.config.ts plugins array for CLI-based serving - Add `dev` script for development mode with hot-reload and Studio UI - Add `plugin.ts` with CRMPlugin class for importing as a plugin in other projects - Add `./plugin` export path in package.json for plugin consumption - Update server.ts to import ConsolePlugin directly from @object-ui/console - Add `type: module` to package.json for ESM compatibility Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 87c988e commit 125bdb2

5 files changed

Lines changed: 70 additions & 5 deletions

File tree

examples/crm/objectstack.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { OrderObject } from './src/objects/order.object';
88
import { UserObject } from './src/objects/user.object';
99
import { ProjectObject } from './src/objects/project.object';
1010
import { EventObject } from './src/objects/event.object';
11+
import { ConsolePlugin } from '@object-ui/console';
1112

1213
export default defineStack({
1314
objects: [
@@ -686,5 +687,8 @@ export default defineStack({
686687
}
687688
]
688689

689-
}
690-
});
690+
},
691+
plugins: [
692+
new ConsolePlugin(),
693+
],
694+
} as any);

examples/crm/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"version": "1.0.0",
44
"description": "CRM Metadata Example using ObjectStack Protocol",
55
"private": true,
6+
"type": "module",
67
"main": "dist/objectstack.json",
78
"types": "src/index.ts",
89
"exports": {
910
".": "./src/index.ts",
10-
"./objectstack.config": "./objectstack.config.ts"
11+
"./objectstack.config": "./objectstack.config.ts",
12+
"./plugin": "./plugin.ts"
1113
},
1214
"scripts": {
15+
"dev": "objectstack serve --dev objectstack.config.ts",
1316
"serve": "objectstack serve objectstack.config.ts",
1417
"build": "objectstack compile objectstack.config.ts",
1518
"start": "tsx server.ts"

examples/crm/plugin.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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;

examples/crm/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { InMemoryDriver } from '@objectstack/driver-memory';
77
import { AuthPlugin } from '@objectstack/plugin-auth';
88
import config from './objectstack.config';
99
import { pino } from 'pino';
10-
import { ConsolePlugin } from './console-plugin';
10+
import { ConsolePlugin } from '@object-ui/console';
1111

1212
async function startServer() {
1313
const logger = pino({

examples/crm/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"strict": true,
77
"skipLibCheck": true
88
},
9-
"include": ["src/**/*", "objectstack.config.ts", "server.ts", "console-plugin.ts"]
9+
"include": ["src/**/*", "objectstack.config.ts", "server.ts", "console-plugin.ts", "plugin.ts"]
1010
}

0 commit comments

Comments
 (0)