-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobjectstack.config.ts
More file actions
134 lines (119 loc) · 4.9 KB
/
objectstack.config.ts
File metadata and controls
134 lines (119 loc) · 4.9 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// @ts-ignore
globalThis.require = require;
import { sharedConfig, appConfigs } from './objectstack.shared';
// @ts-ignore
import * as MSWPluginPkg from '@objectstack/plugin-msw';
// @ts-ignore
import * as ObjectQLPluginPkg from '@objectstack/objectql';
// @ts-ignore
import * as HonoServerPluginPkg from '@objectstack/plugin-hono-server';
// @ts-ignore
import * as AuthPluginPkg from '@objectstack/plugin-auth';
// @ts-ignore
import * as SetupPluginPkg from '@objectstack/plugin-setup';
// @ts-ignore
import * as DriverMemoryPkg from '@objectstack/driver-memory';
// @ts-ignore
import * as RuntimePkg from '@objectstack/runtime';
// @ts-ignore
import * as CorePkg from '@objectstack/core';
const MSWPlugin = MSWPluginPkg.MSWPlugin || (MSWPluginPkg as any).default?.MSWPlugin || (MSWPluginPkg as any).default;
const ObjectQLPlugin = ObjectQLPluginPkg.ObjectQLPlugin || (ObjectQLPluginPkg as any).default?.ObjectQLPlugin || (ObjectQLPluginPkg as any).default;
const InMemoryDriver = DriverMemoryPkg.InMemoryDriver || (DriverMemoryPkg as any).default?.InMemoryDriver || (DriverMemoryPkg as any).default;
const DriverPlugin = RuntimePkg.DriverPlugin || (RuntimePkg as any).default?.DriverPlugin || (RuntimePkg as any).default;
const AppPlugin = RuntimePkg.AppPlugin || (RuntimePkg as any).default?.AppPlugin || (RuntimePkg as any).default;
const HonoServerPlugin = HonoServerPluginPkg.HonoServerPlugin || (HonoServerPluginPkg as any).default?.HonoServerPlugin || (HonoServerPluginPkg as any).default;
const AuthPlugin = AuthPluginPkg.AuthPlugin || (AuthPluginPkg as any).default?.AuthPlugin || (AuthPluginPkg as any).default;
const SetupPlugin = SetupPluginPkg.SetupPlugin || (SetupPluginPkg as any).default?.SetupPlugin || (SetupPluginPkg as any).default;
const createMemoryI18n = CorePkg.createMemoryI18n || (CorePkg as any).default?.createMemoryI18n;
import { ConsolePlugin } from './plugin';
/**
* Lightweight plugin that registers the in-memory i18n service during the
* init phase. This is critical for server mode (`pnpm start`) because:
*
* 1. AppPlugin.start() → loadTranslations() needs an i18n service.
* 2. The kernel's own memory i18n fallback is auto-registered in
* validateSystemRequirements() — which runs AFTER all plugin starts.
* 3. Without an early-registered i18n service, loadTranslations() finds
* nothing and silently skips — translations never get loaded.
*
* By registering the service during init (Phase 1), AppPlugin.start()
* (Phase 2) finds it and loads the spec-format `translations` array.
*
* Name matches the CLI's dedup check so it won't attempt to also import
* @objectstack/service-i18n.
*/
class MemoryI18nPlugin {
readonly name = 'com.objectstack.service.i18n';
readonly version = '1.0.0';
readonly type = 'service' as const;
init(ctx: any) {
const svc = createMemoryI18n();
ctx.registerService('i18n', svc);
}
}
/**
* Plugin ordering matters for server mode (`pnpm start`):
*
* The CLI's isHostConfig() detects that config.plugins contains objects with
* init methods (ObjectQLPlugin, DriverPlugin, etc.) and treats this as a
* "host config" — skipping auto-registration of AppPlugin.
*
* We therefore include AppPlugin explicitly so that:
* - Objects/metadata are registered with the kernel
* - Seed data is loaded into the in-memory driver
* - Translations are loaded into the i18n service (via loadTranslations)
*
* MemoryI18nPlugin MUST come before AppPlugin so that the i18n service
* exists when AppPlugin.start() → loadTranslations() runs.
*
* SetupPlugin MUST load before AuthPlugin so that the setupNav service
* is registered and available when AuthPlugin.init() tries to contribute menu items.
*/
const plugins: any[] = [
new MemoryI18nPlugin(),
new ObjectQLPlugin(),
new DriverPlugin(new InMemoryDriver(), 'memory'),
// Each example stack loaded as an independent AppPlugin
...appConfigs.map((config: any) => new AppPlugin(config)),
// SetupPlugin must come before AuthPlugin (setupNav service dependency)
new SetupPlugin(),
// AuthPlugin contributes to setupNav during init, so it must come AFTER SetupPlugin
new AuthPlugin({
secret: process.env.AUTH_SECRET || 'objectui-server-secret',
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
}),
new HonoServerPlugin({ port: 3000 }),
new ConsolePlugin(),
];
// Re-enable MSW only if explicitly needed
if (process.env.ENABLE_MSW_PLUGIN === 'true') {
plugins.push(new MSWPlugin());
}
export default {
...sharedConfig,
build: {
outDir: './dist',
sourcemap: true,
minify: true,
target: 'node18',
},
datasources: {
default: {
driver: 'memory',
},
},
plugins,
dev: {
port: 3000,
host: '0.0.0.0',
watch: true,
hotReload: true,
},
deploy: {
target: 'static',
region: 'us-east-1',
},
};