Skip to content

Commit 58313e1

Browse files
committed
fix: refactor app configuration to use shared config file and update imports across the application
1 parent b5fafe4 commit 58313e1

File tree

12 files changed

+108
-114
lines changed

12 files changed

+108
-114
lines changed

apps/console/objectstack.config.ts

Lines changed: 50 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
12
import { createRequire } from 'module';
23
const require = createRequire(import.meta.url);
34
// @ts-ignore
45
globalThis.require = require;
56

67
import { defineConfig } from './src/config';
8+
import { sharedConfig } from './objectstack.shared';
9+
710
// @ts-ignore
811
import * as MSWPluginPkg from '@objectstack/plugin-msw';
912
// @ts-ignore
@@ -15,6 +18,8 @@ const MSWPlugin = MSWPluginPkg.MSWPlugin || (MSWPluginPkg as any).default?.MSWPl
1518
const ObjectQLPlugin = ObjectQLPluginPkg.ObjectQLPlugin || (ObjectQLPluginPkg as any).default?.ObjectQLPlugin || (ObjectQLPluginPkg as any).default;
1619
const HonoServerPlugin = HonoServerPluginPkg.HonoServerPlugin || (HonoServerPluginPkg as any).default?.HonoServerPlugin || (HonoServerPluginPkg as any).default;
1720

21+
import ConsolePluginConfig from './plugin.js';
22+
1823
// FIX: Ensure init is own property for runtime compatibility
1924
class PatchedMSWPlugin extends MSWPlugin {
2025
constructor(...args: any[]) {
@@ -31,55 +36,55 @@ class PatchedHonoServerPlugin extends HonoServerPlugin {
3136
super(...args);
3237
// @ts-ignore
3338
this.init = this.init.bind(this);
34-
// @ts-ignore
35-
this.start = this.start?.bind(this);
36-
}
37-
38-
async start(ctx: any) {
39-
// @ts-ignore
40-
await super.start(ctx);
4139

42-
// SPA Fallback: Serve index.html for unknown routes (excluding /api)
40+
// Capture original start method (which is an arrow function property)
4341
// @ts-ignore
44-
const app = this.server.getRawApp();
42+
const originalStart = this.start;
43+
44+
// Override start with custom logic
4545
// @ts-ignore
46-
const staticRoot = this.options.staticRoot;
47-
48-
if (staticRoot) {
49-
const fs = require('fs');
50-
const path = require('path');
46+
this.start = async (ctx: any) => {
47+
// Call original start
48+
if (originalStart) {
49+
await originalStart(ctx);
50+
}
51+
52+
// SPA Fallback: Serve index.html for unknown routes (excluding /api)
53+
// @ts-ignore
54+
const app = this.server.getRawApp();
55+
// @ts-ignore
56+
const staticRoot = this.options.staticRoot;
5157

52-
// Register fallback after serveStatic (which is added in listen/super.start)
53-
app.get('*', async (c: any) => {
54-
// Ignore API calls -> let them 404
55-
if (c.req.path.startsWith('/api') || c.req.path.startsWith('/assets')) {
56-
// return c.notFound(); // Hono's c.notFound() isn't standard in all versions, let's use status
57-
return c.text('Not Found', 404);
58-
}
58+
if (staticRoot) {
59+
const fs = require('fs');
60+
const path = require('path');
5961

60-
try {
61-
// Try to serve index.html
62-
// Ensure we resolve relative to CWD or config location
63-
const indexPath = path.resolve(staticRoot, 'index.html');
64-
if (fs.existsSync(indexPath)) {
65-
const indexContent = fs.readFileSync(indexPath, 'utf-8');
66-
return c.html(indexContent);
62+
// Register fallback after serveStatic (which is added in listen/originalStart)
63+
app.get('*', async (c: any) => {
64+
// Ignore API calls -> let them 404
65+
if (c.req.path.startsWith('/api') || c.req.path.startsWith('/assets')) {
66+
return c.text('Not Found', 404);
6767
}
68-
return c.text('SPA Index Not Found', 404);
69-
} catch (e: any) {
70-
return c.text('Server Error: ' + e.message, 500);
71-
}
72-
});
73-
console.log('SPA Fallback route registered for ' + staticRoot);
74-
}
68+
69+
try {
70+
// Try to serve index.html
71+
// Ensure we resolve relative to CWD or config location
72+
const indexPath = path.resolve(staticRoot, 'index.html');
73+
if (fs.existsSync(indexPath)) {
74+
const indexContent = fs.readFileSync(indexPath, 'utf-8');
75+
return c.html(indexContent);
76+
}
77+
return c.text('SPA Index Not Found', 404);
78+
} catch (e: any) {
79+
return c.text('Server Error: ' + e.message, 500);
80+
}
81+
});
82+
console.log('SPA Fallback route registered for ' + staticRoot);
83+
}
84+
};
7585
}
7686
}
7787

78-
import ConsolePluginConfig from './plugin.js';
79-
import crmConfig from '@object-ui/example-crm/objectstack.config';
80-
import todoConfig from '@object-ui/example-todo/objectstack.config';
81-
import kitchenSinkConfig from '@object-ui/example-kitchen-sink/objectstack.config';
82-
8388
const FixedConsolePlugin = {
8489
...ConsolePluginConfig,
8590
init: () => {}
@@ -91,7 +96,6 @@ const DummyApiRegistryPlugin = {
9196
version: '1.0.0',
9297
init: (ctx: any) => {
9398
// Polyfill missing critical services to pass the Runtime health check
94-
// These are normally provided by standard plugins not currently included in this lightweight setup
9599

96100
ctx.registerService('metadata', {
97101
getApp: () => null,
@@ -117,15 +121,13 @@ const DummyApiRegistryPlugin = {
117121
const apiEndpoints: any[] = [];
118122
ctx.registerService('api-registry', {
119123
registerApi: (entry: any) => {
120-
// console.log('Mock: Registering API', entry.id);
121124
apiEndpoints.push(entry);
122125
},
123126
getRegistry: () => ({
124127
apis: apiEndpoints,
125128
totalApis: apiEndpoints.length,
126129
totalEndpoints: apiEndpoints.reduce((acc, api) => acc + (api.endpoints?.length || 0), 0)
127130
}),
128-
// Add other potential methods if needed
129131
registerRoute: () => {},
130132
getRoutes: () => []
131133
});
@@ -137,31 +139,21 @@ const DummyApiRegistryPlugin = {
137139

138140
const plugins: any[] = [
139141
new ObjectQLPlugin(),
140-
// new PatchedMSWPlugin(), // Disabled in production mode as per requirement
142+
// new PatchedMSWPlugin(), // Disabled in production mode
141143
new PatchedHonoServerPlugin({
142144
staticRoot: './dist'
143145
}),
144146
FixedConsolePlugin,
145147
DummyApiRegistryPlugin
146148
];
147149

148-
// Re-enable MSW only if explicitly needed (e.g. via test env var, though technically pnpm dev uses browser MSW)
150+
// Re-enable MSW only if explicitly needed
149151
if (process.env.ENABLE_MSW_PLUGIN === 'true') {
150152
plugins.push(new PatchedMSWPlugin());
151153
}
152154

153155
export default defineConfig({
154-
// ============================================================================
155-
// Project Metadata
156-
// ============================================================================
157-
158-
name: '@object-ui/console',
159-
version: '0.1.0',
160-
description: 'ObjectStack Console',
161-
162-
// ============================================================================
163-
// Build Settings
164-
// ============================================================================
156+
...sharedConfig,
165157

166158
build: {
167159
outDir: './dist',
@@ -170,56 +162,13 @@ export default defineConfig({
170162
target: 'node18',
171163
},
172164

173-
// ============================================================================
174-
// Database Configuration
175-
// ============================================================================
176-
177165
datasources: {
178166
default: {
179-
driver: 'memory', // Use memory driver for browser example
167+
driver: 'memory',
180168
},
181169
},
182170

183-
// ============================================================================
184-
// Plugin Configuration
185-
// ============================================================================
186-
187171
plugins,
188-
189-
// ============================================================================
190-
// Merged Stack Configuration (CRM + Todo + Kitchen Sink + Mock Metadata)
191-
// ============================================================================
192-
objects: [
193-
...(crmConfig.objects || []),
194-
...(todoConfig.objects || []),
195-
...(kitchenSinkConfig.objects || [])
196-
],
197-
apps: [
198-
...(crmConfig.apps || []),
199-
...(todoConfig.apps || []),
200-
...(kitchenSinkConfig.apps || [])
201-
],
202-
dashboards: [
203-
...(crmConfig.dashboards || []),
204-
...(todoConfig.dashboards || []),
205-
...(kitchenSinkConfig.dashboards || [])
206-
],
207-
pages: [
208-
...(crmConfig.pages || []),
209-
...(todoConfig.pages || []),
210-
...(kitchenSinkConfig.pages || [])
211-
],
212-
manifest: {
213-
data: [
214-
...(crmConfig.manifest?.data || []),
215-
...(todoConfig.manifest?.data || []),
216-
...(kitchenSinkConfig.manifest?.data || [])
217-
]
218-
},
219-
220-
// ============================================================================
221-
// Development Server
222-
// ============================================================================
223172

224173
dev: {
225174
port: 3000,
@@ -228,12 +177,8 @@ export default defineConfig({
228177
hotReload: true,
229178
},
230179

231-
// ============================================================================
232-
// Deployment
233-
// ============================================================================
234-
235180
deploy: {
236-
target: 'static', // This is a static SPA
181+
target: 'static',
237182
region: 'us-east-1',
238183
},
239184
});

apps/console/objectstack.shared.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { defineConfig } from './src/config';
2+
import crmConfig from '@object-ui/example-crm/objectstack.config';
3+
import todoConfig from '@object-ui/example-todo/objectstack.config';
4+
import kitchenSinkConfig from '@object-ui/example-kitchen-sink/objectstack.config';
5+
6+
export const sharedConfig = {
7+
// ============================================================================
8+
// Project Metadata
9+
// ============================================================================
10+
11+
name: '@object-ui/console',
12+
version: '0.1.0',
13+
description: 'ObjectStack Console',
14+
15+
// ============================================================================
16+
// Merged Stack Configuration (CRM + Todo + Kitchen Sink + Mock Metadata)
17+
// ============================================================================
18+
objects: [
19+
...(crmConfig.objects || []),
20+
...(todoConfig.objects || []),
21+
...(kitchenSinkConfig.objects || [])
22+
],
23+
apps: [
24+
...(crmConfig.apps || []),
25+
...(todoConfig.apps || []),
26+
...(kitchenSinkConfig.apps || [])
27+
],
28+
dashboards: [
29+
...(crmConfig.dashboards || []),
30+
...(todoConfig.dashboards || []),
31+
...(kitchenSinkConfig.dashboards || [])
32+
],
33+
pages: [
34+
...(crmConfig.pages || []),
35+
...(todoConfig.pages || []),
36+
...(kitchenSinkConfig.pages || [])
37+
],
38+
manifest: {
39+
data: [
40+
...(crmConfig.manifest?.data || []),
41+
...(todoConfig.manifest?.data || []),
42+
...(kitchenSinkConfig.manifest?.data || [])
43+
]
44+
},
45+
};
46+
47+
export default defineConfig(sharedConfig);

apps/console/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ObjectForm } from '@object-ui/plugin-form';
55
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Empty, EmptyTitle } from '@object-ui/components';
66
import { SchemaRendererProvider } from '@object-ui/react';
77
import { ObjectStackDataSource } from './dataSource';
8-
import appConfig from '../objectstack.config';
8+
import appConfig from '../objectstack.shared';
99

1010
// Components
1111
import { ConsoleLayout } from './components/ConsoleLayout';

apps/console/src/__tests__/ConsoleApp.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MemoryRouter, Routes, Route } from 'react-router-dom';
77
// --- Mocks ---
88

99
// Mock ObjectStack Config
10-
vi.mock('../../objectstack.config', () => ({
10+
vi.mock('../../objectstack.shared', () => ({
1111
default: {
1212
apps: [
1313
{

apps/console/src/__tests__/PageView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MemoryRouter, Route, Routes } from 'react-router-dom';
55
import { PageView } from '../components/PageView';
66

77
// Mock appConfig
8-
vi.mock('../../objectstack.config', () => ({
8+
vi.mock('../../objectstack.shared', () => ({
99
default: {
1010
pages: [
1111
{

apps/console/src/__tests__/SpecCompliance.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { describe, it, expect } from 'vitest';
3-
import appConfig from '../../objectstack.config';
3+
import appConfig from '../../objectstack.shared';
44

55
/**
66
* Spec Compliance Tests

apps/console/src/components/AppSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
Database,
3636
ChevronRight,
3737
} from 'lucide-react';
38-
import appConfig from '../../objectstack.config';
38+
import appConfig from '../../objectstack.shared';
3939

4040
// Helper to get icon from Lucide
4141
function getIcon(name?: string) {

apps/console/src/components/DashboardView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { useParams } from 'react-router-dom';
77
import { DashboardRenderer } from '@object-ui/plugin-dashboard';
88
import { Empty, EmptyTitle, EmptyDescription } from '@object-ui/components';
9-
import appConfig from '../../objectstack.config';
9+
import appConfig from '../../objectstack.shared';
1010

1111
export function DashboardView() {
1212
const { dashboardName } = useParams<{ dashboardName: string }>();

apps/console/src/components/PageView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { useParams, useSearchParams } from 'react-router-dom';
77
import { SchemaRenderer } from '@object-ui/react';
88
import { Empty, EmptyTitle, EmptyDescription } from '@object-ui/components';
9-
import appConfig from '../../objectstack.config';
9+
import appConfig from '../../objectstack.shared';
1010

1111
export function PageView() {
1212
const { pageName } = useParams<{ pageName: string }>();

apps/console/src/mocks/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ObjectKernel, DriverPlugin, AppPlugin } from '@objectstack/runtime';
99
import { ObjectQLPlugin } from '@objectstack/objectql';
1010
import { InMemoryDriver } from '@objectstack/driver-memory';
1111
import { MSWPlugin } from '@objectstack/plugin-msw';
12-
import appConfig from '../../objectstack.config';
12+
import appConfig from '../../objectstack.shared';
1313

1414
let kernel: ObjectKernel | null = null;
1515
let driver: InMemoryDriver | null = null;

0 commit comments

Comments
 (0)