Skip to content

Commit 4dc6aba

Browse files
committed
feat(cli): add internal CLI for documentation automation
- Implemented commands for building, developing, and translating documentation. - Added support for AI translation of MDX files from English to Chinese. - Configured environment variables for documentation directories. - Created a structure for handling multilingual documentation with Next.js. - Introduced layout and page components for rendering documentation. - Added utility functions for file handling and translation logic. - Included SVG assets for documentation architecture and protocol-driven concepts. - Established a configuration file for TypeScript and Next.js.
1 parent d04cfd8 commit 4dc6aba

30 files changed

Lines changed: 696 additions & 35 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This repository contains the documentation for:
1717
- Target: Chinese (`content/docs-zh-CN`) - *Auto-translated via AI*
1818
- 📝 **MDX Content**: Interactive documentation with Type-safe components.
1919
- 🛠️ **Automated Workflows**:
20-
- AI Translation CLI (`packages/docs-cli`)
20+
- AI Translation CLI (`packages/cli`)
2121
- Broken link checking
2222
- SEO optimization
2323

@@ -56,7 +56,7 @@ We provide a custom CLI for translation tasks:
5656

5757
```bash
5858
# Translate all files
59-
pnpm docs-cli translate --all
59+
pnpm objectdocs translate --all
6060
```
6161

6262

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"translate": "docs-cli translate",
11-
"translate:all": "docs-cli translate --all"
10+
"translate": "objectdocs translate",
11+
"translate:all": "objectdocs translate --all"
1212
},
1313
"devDependencies": {
14-
"@docs/cli": "workspace:*"
14+
"@objectdocs/cli": "workspace:*"
1515
},
1616
"dependencies": {
1717
"@fumadocs/ui": "^16.4.7",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ dist
44
.DS_Store
55
*.log
66
coverage
7+
8+
# Next.js
9+
site/.next
10+
site/out
11+
.next
12+
out
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @docs/cli
1+
# objectdocs/cli
22

33
Internal CLI tool for automating documentation workflows for ObjectStack.
44

@@ -17,6 +17,20 @@ pnpm install
1717

1818
## Usage
1919

20+
### Site Management
21+
22+
The CLI can also be used to run the documentation site locally with a VitePress-like experience.
23+
24+
```bash
25+
# Start Dev Server
26+
# Usage: pnpm objectdocs dev [docs-directory]
27+
pnpm objectdocs dev ./content/docs
28+
29+
# Build Static Site
30+
# Usage: pnpm objectdocs build [docs-directory]
31+
pnpm objectdocs build ./content/docs
32+
```
33+
2034
### Translate Documentation
2135

2236
The `translate` command reads English documentation from `content/docs` and generates Chinese translations in `content/docs-zh-CN`.
@@ -33,16 +47,16 @@ OPENAI_BASE_URL=https://api.openai.com/v1 # Optional
3347

3448
```bash
3549
# Translate a specific file
36-
pnpm docs-cli translate content/docs/00-intro/index.mdx
50+
pnpm objectdocs translate content/docs/00-intro/index.mdx
3751

3852
# Translate multiple files
39-
pnpm docs-cli translate content/docs/00-intro/index.mdx content/docs/01-quickstart/index.mdx
53+
pnpm objectdocs translate content/docs/00-intro/index.mdx content/docs/01-quickstart/index.mdx
4054

4155
# Translate all files in content/docs
42-
pnpm docs-cli translate --all
56+
pnpm objectdocs translate --all
4357

4458
# Specify a custom model (default: gpt-4o)
45-
pnpm docs-cli translate --all --model gpt-4-turbo
59+
pnpm objectdocs translate --all --model gpt-4-turbo
4660
```
4761

4862
### CI/CD Integration
@@ -51,5 +65,5 @@ In CI environments, you can use the `CHANGED_FILES` environment variable to tran
5165

5266
```bash
5367
export CHANGED_FILES="content/docs/new-page.mdx"
54-
pnpm docs-cli translate
68+
pnpm objectdocs translate
5569
```
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
import { cac } from 'cac';
33
import 'dotenv/config';
44
import { registerTranslateCommand } from '../src/commands/translate.mjs';
5+
import { registerDevCommand } from '../src/commands/dev.mjs';
6+
import { registerBuildCommand } from '../src/commands/build.mjs';
57

6-
const cli = cac('docs-cli');
8+
const cli = cac('objectdocs');
79

810
registerTranslateCommand(cli);
11+
registerDevCommand(cli);
12+
registerBuildCommand(cli);
913

1014
cli.help();
1115
cli.version('0.0.1');

packages/cli/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@objectdocs/cli",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"bin": {
6+
"objectdocs": "./bin/cli.mjs"
7+
},
8+
"scripts": {
9+
"dev": "node ./bin/cli.mjs dev ../../content/docs",
10+
"build": "node ./bin/cli.mjs build ../../content/docs",
11+
"translate": "node ./bin/cli.mjs translate",
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
14+
"dependencies": {
15+
"@fumadocs/ui": "^16.4.7",
16+
"@tailwindcss/postcss": "^4.1.18",
17+
"@types/mdx": "^2.0.13",
18+
"@types/node": "^25.0.8",
19+
"@types/react": "^19.2.8",
20+
"autoprefixer": "^10.4.23",
21+
"cac": "^6.7.14",
22+
"dev": "^0.1.3",
23+
"dotenv": "^16.4.5",
24+
"fumadocs-core": "^16.4.7",
25+
"fumadocs-mdx": "^14.2.5",
26+
"fumadocs-ui": "^16.4.7",
27+
"next": "^16.1.2",
28+
"openai": "^4.0.0",
29+
"postcss": "^8.5.6",
30+
"react": "^19.2.3",
31+
"react-dom": "^19.2.3",
32+
"tailwindcss": "^4.1.18",
33+
"typescript": "^5.9.3"
34+
}
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { source } from '@/lib/source';
2+
import type { Metadata } from 'next';
3+
import { DocsPage, DocsBody } from 'fumadocs-ui/page';
4+
import { notFound } from 'next/navigation';
5+
6+
interface PageProps {
7+
params: Promise<{
8+
lang: string;
9+
slug?: string[];
10+
}>;
11+
}
12+
13+
export default async function Page({ params }: PageProps) {
14+
const { lang, slug = [] } = await params;
15+
16+
const page = source.getPage(slug, lang);
17+
18+
if (!page) {
19+
notFound();
20+
}
21+
22+
const MDX = page.data.body as any;
23+
24+
return (
25+
<DocsPage toc={page.data.toc as any} full={page.data.full as any}>
26+
<DocsBody>
27+
<MDX />
28+
</DocsBody>
29+
</DocsPage>
30+
);
31+
}
32+
33+
export async function generateStaticParams() {
34+
return source.generateParams();
35+
}
36+
37+
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
38+
const { lang, slug = [] } = await params;
39+
const page = source.getPage(slug, lang);
40+
41+
if (!page) notFound();
42+
43+
return {
44+
title: page.data.title,
45+
description: page.data.description,
46+
};
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { source } from '@/lib/source';
2+
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
3+
import type { ReactNode } from 'react';
4+
import { baseOptions } from '@/app/layout.config';
5+
6+
export default async function Layout({
7+
params,
8+
children,
9+
}: {
10+
params: Promise<{ lang: string }>;
11+
children: ReactNode;
12+
}) {
13+
const { lang } = await params;
14+
15+
return (
16+
<DocsLayout
17+
tree={source.getPageTree(lang)}
18+
{...baseOptions}
19+
>
20+
{children}
21+
</DocsLayout>
22+
);
23+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { I18nProvider } from 'fumadocs-ui/contexts/i18n';
2+
import { defineI18nUI } from 'fumadocs-ui/i18n';
3+
import type { ReactNode } from 'react';
4+
import { i18n } from '@/lib/i18n';
5+
import { cn } from '@/lib/i18n-ui';
6+
7+
const translations = {
8+
'zh-CN': cn,
9+
};
10+
11+
const i18nConfig = defineI18nUI(i18n, {
12+
translations: {
13+
en: {
14+
displayName: 'English',
15+
},
16+
'zh-CN': {
17+
...cn,
18+
displayName: '简体中文',
19+
},
20+
},
21+
});
22+
23+
export default async function LangLayout({
24+
params,
25+
children,
26+
}: {
27+
params: Promise<{ lang: string }>;
28+
children: ReactNode;
29+
}) {
30+
const { lang } = await params;
31+
const providerProps = i18nConfig.provider(lang);
32+
33+
return <I18nProvider {...providerProps}>{children}</I18nProvider>;
34+
}
35+
36+
export async function generateStaticParams() {
37+
return i18n.languages.map((lang) => ({ lang }));
38+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { redirect } from 'next/navigation';
2+
3+
export default async function LangPage({
4+
params,
5+
}: {
6+
params: Promise<{ lang: string }>;
7+
}) {
8+
const { lang } = await params;
9+
redirect(`/${lang}/docs`);
10+
}

0 commit comments

Comments
 (0)