Skip to content

Commit 72e7c2d

Browse files
committed
在启动开发服务器之前同步用户配置和公共资产
1 parent aff0c80 commit 72e7c2d

File tree

4 files changed

+87
-30
lines changed

4 files changed

+87
-30
lines changed

packages/cli/src/commands/dev.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ export function registerDevCommand(cli) {
4343
let debounceTimer;
4444

4545
const startServer = () => {
46+
// Sync config and assets before starting
47+
const userConfigPath = path.resolve(process.cwd(), 'objectdocs.json');
48+
if (fs.existsSync(userConfigPath)) {
49+
fs.cpSync(userConfigPath, path.join(nextAppDir, 'objectdocs.json'));
50+
}
51+
52+
const userPublicPath = path.resolve(process.cwd(), 'public');
53+
if (fs.existsSync(userPublicPath)) {
54+
const targetPublicDir = path.join(nextAppDir, 'public');
55+
if (!fs.existsSync(targetPublicDir)) {
56+
fs.mkdirSync(targetPublicDir, { recursive: true });
57+
}
58+
fs.cpSync(userPublicPath, targetPublicDir, { recursive: true, force: true });
59+
}
60+
4661
child = spawn(nextCmd, args, {
4762
stdio: 'inherit',
4863
env,

packages/site/lib/site-config.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import fs from 'node:fs';
2-
import path from 'node:path';
31
import { deepMerge } from './deep-merge';
2+
import objectDocsConfig from '@/objectdocs.json';
43

54
export interface SiteConfig {
65
meta: {
@@ -141,33 +140,7 @@ const defaultConfig: SiteConfig = {
141140
};
142141

143142
export function getSiteConfig(): SiteConfig {
144-
try {
145-
// Determine path to objectdocs.json.
146-
// Assuming process.cwd() is packages/site during build, or root during dev?
147-
// Let's look for objectdocs.json in a few places.
148-
149-
// 1. Check relative to current working directory (if run from root)
150-
let configPath = path.resolve(process.cwd(), 'objectdocs.json');
151-
if (fs.existsSync(configPath)) {
152-
const content = fs.readFileSync(configPath, 'utf-8');
153-
console.log('Loaded objectdocs.json from:', configPath);
154-
return deepMerge(defaultConfig, JSON.parse(content));
155-
}
156-
157-
// 2. Check relative to package root (../../objectdocs.json) if run from packages/site
158-
configPath = path.resolve(process.cwd(), '../../objectdocs.json');
159-
if (fs.existsSync(configPath)) {
160-
const content = fs.readFileSync(configPath, 'utf-8');
161-
console.log('Loaded objectdocs.json from:', configPath);
162-
return deepMerge(defaultConfig, JSON.parse(content));
163-
}
164-
165-
console.warn('objectdocs.json not found at:', configPath, 'using default config');
166-
} catch (error) {
167-
console.error('Error loading objectdocs.json:', error);
168-
}
169-
170-
return defaultConfig;
143+
return deepMerge(defaultConfig, objectDocsConfig);
171144
}
172145

173146
export const siteConfig = getSiteConfig();

packages/site/objectdocs.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"meta": {
3+
"title": "ObjectStack Docs",
4+
"description": "Enterprise-grade low-code platform documentation",
5+
"url": "https://docs.objectstack.ai",
6+
"favicon": "/favicon.ico"
7+
},
8+
"i18n": {
9+
"enabled": true,
10+
"defaultLanguage": "en",
11+
"languages": ["en", "cn"
12+
]
13+
},
14+
"branding": {
15+
"logo": {
16+
"text": "ObjectStack",
17+
"light": "/logo.svg",
18+
"dark": "/logo.svg"
19+
},
20+
"theme": {
21+
"accentColor": "blue",
22+
"radius": "0.5rem"
23+
}
24+
},
25+
"layout": {
26+
"navbar": {
27+
"enabled": true,
28+
"transparentMode": "top",
29+
"links": [
30+
{
31+
"text": "Home",
32+
"url": "https://www.objectstack.ai",
33+
"external": true
34+
}
35+
],
36+
"socials": [
37+
{ "platform": "github", "url": "https://github.com/objectstack-ai/" }
38+
]
39+
},
40+
"sidebar": {
41+
"enabled": true,
42+
"prefetch": true,
43+
"defaultOpenLevel": 1,
44+
"collapsible": true,
45+
"tabs": []
46+
},
47+
"toc": {
48+
"enabled": true,
49+
"depth": 3
50+
},
51+
"footer": {
52+
"enabled": false,
53+
"copyright": "© 2026 ObjectStack Inc."
54+
}
55+
},
56+
"page": {
57+
"showLastUpdate": true,
58+
"showEditLink": true,
59+
"repoBaseUrl": "https://github.com/objectstack-ai/docs"
60+
},
61+
"content": {
62+
"math": false,
63+
"imageZoom": true,
64+
"codeBlock": {
65+
"theme": "vesper",
66+
"showLineNumbers": true
67+
}
68+
}
69+
}

packages/site/proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export default createI18nMiddleware(i18n);
66
export const config = {
77
// Matcher ignoring `/_next/` and `/api/`
88
// You may need to adjust it to ignore static assets in `/public` folder
9-
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
9+
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|logo.svg).*)'],
1010
};

0 commit comments

Comments
 (0)