-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.ts
More file actions
68 lines (59 loc) · 2.03 KB
/
plugin.ts
File metadata and controls
68 lines (59 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* 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 type { AppPluginContext } from '@object-ui/types';
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: AppPluginContext) {
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');
}
}
async stop() {
// Teardown: no persistent resources to release
}
/** Raw stack configuration for legacy/manual merging */
getConfig() {
return config;
}
}
export default CRMPlugin;