Skip to content

Commit 8281670

Browse files
committed
feat: auto-register plugins in serve command and update dependencies
1 parent 82b5de2 commit 8281670

4 files changed

Lines changed: 47 additions & 19 deletions

File tree

examples/app-todo/objectstack.config.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { defineStack } from '@objectstack/spec';
22
import { App } from '@objectstack/spec/ui';
33
import { TodoTask } from './src/domains/todo/task.object';
44

5-
// Runtime Plugins
6-
import { ObjectQLPlugin } from '@objectstack/objectql';
7-
import { DriverPlugin } from '@objectstack/runtime';
8-
import { InMemoryDriver } from '@objectstack/driver-memory';
9-
105
export default defineStack({
116
objects: [
127
TodoTask
@@ -54,10 +49,6 @@ export default defineStack({
5449
]
5550
}
5651
]
57-
},
58-
plugins: [
59-
new ObjectQLPlugin(),
60-
new DriverPlugin(new InMemoryDriver())
61-
]
52+
}
6253
});
6354

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"license": "MIT",
2424
"dependencies": {
2525
"@objectstack/core": "workspace:*",
26+
"@objectstack/driver-memory": "workspace:^",
27+
"@objectstack/objectql": "workspace:^",
2628
"@objectstack/plugin-hono-server": "workspace:*",
2729
"@objectstack/runtime": "workspace:^",
2830
"@objectstack/spec": "workspace:*",

packages/cli/src/commands/serve.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,44 @@ export const serveCommand = new Command('serve')
9696
logger: loggerConfig
9797
});
9898

99-
// Auto-register AppPlugin if config contains app definitions
99+
// Load plugins from configuration
100+
let plugins = config.plugins || [];
101+
102+
// Merge devPlugins if in dev mode
103+
if (options.dev && config.devPlugins) {
104+
console.log(chalk.blue(`📦 Loading development plugins...`));
105+
plugins = [...plugins, ...config.devPlugins];
106+
}
107+
108+
// 1. Auto-register ObjectQL Plugin if objects define but plugins missing
109+
const hasObjectQL = plugins.some((p: any) => p.name?.includes('objectql') || p.constructor?.name?.includes('ObjectQL'));
110+
if (config.objects && !hasObjectQL) {
111+
try {
112+
console.log(chalk.dim(` Auto-injecting ObjectQL Engine...`));
113+
const { ObjectQLPlugin } = await import('@objectstack/objectql');
114+
kernel.use(new ObjectQLPlugin());
115+
console.log(chalk.green(` ✓ Registered ObjectQL Plugin (auto-detected)`));
116+
} catch (e: any) {
117+
console.warn(chalk.yellow(` ⚠ Could not auto-load ObjectQL: ${e.message}`));
118+
}
119+
}
120+
121+
// 2. Auto-register Memory Driver if in Dev and no driver configured
122+
const hasDriver = plugins.some((p: any) => p.name?.includes('driver') || p.constructor?.name?.includes('Driver'));
123+
if (isDev && !hasDriver && config.objects) {
124+
try {
125+
console.log(chalk.dim(` Auto-injecting Memory Driver (Dev Mode)...`));
126+
const { DriverPlugin } = await import('@objectstack/runtime');
127+
const { InMemoryDriver } = await import('@objectstack/driver-memory');
128+
kernel.use(new DriverPlugin(new InMemoryDriver()));
129+
console.log(chalk.green(` ✓ Registered Memory Driver (auto-detected)`));
130+
} catch (e: any) {
131+
// Silent fail - maybe they don't want a driver or don't have the package
132+
console.log(chalk.dim(` ℹ No default driver loaded: ${e.message}`));
133+
}
134+
}
135+
136+
// 3. Auto-register AppPlugin if config contains app definitions
100137
if (config.objects || config.manifest || config.apps) {
101138
try {
102139
const { AppPlugin } = await import('@objectstack/runtime');
@@ -107,14 +144,6 @@ export const serveCommand = new Command('serve')
107144
}
108145
}
109146

110-
// Load plugins from configuration
111-
let plugins = config.plugins || [];
112-
113-
// Merge devPlugins if in dev mode
114-
if (options.dev && config.devPlugins) {
115-
console.log(chalk.blue(`📦 Loading development plugins...`));
116-
plugins = [...plugins, ...config.devPlugins];
117-
}
118147

119148
if (plugins.length > 0) {
120149
console.log(chalk.yellow(`📦 Loading ${plugins.length} plugin(s)...`));

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)