@linyjs/plugin-docs 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/docs/getting-started/quick-start.md +64 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,22 @@ cat node_modules/@linyjs/plugin-docs/docs/getting-started/quick-start.md
|
|
|
33
33
|
ls node_modules/@linyjs/plugin-docs/docs/api-reference/
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
### 快速创建插件项目
|
|
37
|
+
|
|
38
|
+
使用 CLI 工具创建新的插件项目:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# 创建新的插件项目
|
|
42
|
+
npx @linyjs/cli init my-plugin
|
|
43
|
+
cd my-plugin
|
|
44
|
+
npm install
|
|
45
|
+
|
|
46
|
+
# 进入开发模式
|
|
47
|
+
npx @linyjs/cli dev
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
CLI 工具会自动创建完整的项目结构,包含 package.json、TypeScript 配置和示例代码。
|
|
51
|
+
|
|
36
52
|
### 生成示例项目
|
|
37
53
|
|
|
38
54
|
使用 CLI 工具生成示例项目:
|
|
@@ -24,6 +24,25 @@
|
|
|
24
24
|
|
|
25
25
|
### 步骤 1: 初始化项目
|
|
26
26
|
|
|
27
|
+
**推荐方式:使用 CLI 工具自动创建项目**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# 使用 @linyjs/cli 创建项目目录和基本文件
|
|
31
|
+
npx @linyjs/cli init hello-plugin
|
|
32
|
+
cd hello-plugin
|
|
33
|
+
|
|
34
|
+
# 安装依赖
|
|
35
|
+
npm install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
CLI 工具会自动创建:
|
|
39
|
+
- package.json (已配置依赖和脚本)
|
|
40
|
+
- tsconfig.json (TypeScript 配置)
|
|
41
|
+
- src/server/index.ts (服务端代码模板)
|
|
42
|
+
- src/client/index.tsx (客户端代码模板)
|
|
43
|
+
|
|
44
|
+
**传统方式:手动创建项目**
|
|
45
|
+
|
|
27
46
|
```bash
|
|
28
47
|
# 创建项目目录
|
|
29
48
|
mkdir hello-plugin && cd hello-plugin
|
|
@@ -36,20 +55,24 @@ npm install @linyjs/server-module-interface @linyjs/client-module-interface reac
|
|
|
36
55
|
npm install -D typescript @types/react
|
|
37
56
|
```
|
|
38
57
|
|
|
39
|
-
### 步骤 2:
|
|
58
|
+
### 步骤 2: 项目结构
|
|
59
|
+
|
|
60
|
+
使用 CLI 工具创建的项目已经包含了完整的文件结构:
|
|
40
61
|
|
|
41
62
|
```
|
|
42
63
|
hello-plugin/
|
|
43
|
-
├── package.json
|
|
44
|
-
├── tsconfig.json
|
|
64
|
+
├── package.json # 已预配置的依赖和脚本
|
|
65
|
+
├── tsconfig.json # 已配置 TypeScript
|
|
45
66
|
└── src/
|
|
46
67
|
├── server/
|
|
47
|
-
│ └── index.ts # 服务端入口
|
|
68
|
+
│ └── index.ts # 服务端入口 (已包含示例代码)
|
|
48
69
|
└── client/
|
|
49
|
-
└── index.tsx # 客户端入口
|
|
70
|
+
└── index.tsx # 客户端入口 (已包含示例代码)
|
|
50
71
|
```
|
|
51
72
|
|
|
52
|
-
|
|
73
|
+
**注意**:使用 CLI 创建的项目已经包含了预配置的 package.json 和 tsconfig.json,无需手动创建。
|
|
74
|
+
|
|
75
|
+
如果你使用了传统方式,需要**手动创建 tsconfig.json:**
|
|
53
76
|
|
|
54
77
|
```json
|
|
55
78
|
{
|
|
@@ -72,7 +95,9 @@ hello-plugin/
|
|
|
72
95
|
|
|
73
96
|
### 步骤 3: 编写服务端代码
|
|
74
97
|
|
|
75
|
-
|
|
98
|
+
**使用 CLI 创建的项目已经包含了示例代码**,你已经可以开始开发或修改现有代码。
|
|
99
|
+
|
|
100
|
+
如果你需要自定义或创建新的服务端代码,编辑 `src/server/index.ts`:
|
|
76
101
|
|
|
77
102
|
```typescript
|
|
78
103
|
import type { IModule } from '@linyjs/server-module-interface';
|
|
@@ -103,7 +128,9 @@ export const helloServerModule: IModule = {
|
|
|
103
128
|
|
|
104
129
|
### 步骤 4: 编写客户端代码
|
|
105
130
|
|
|
106
|
-
|
|
131
|
+
**使用 CLI 创建的项目已经包含了示例代码**,你已经可以开始开发或修改现有代码。
|
|
132
|
+
|
|
133
|
+
如果你需要自定义或创建新的客户端代码,编辑 `src/client/index.tsx`:
|
|
107
134
|
|
|
108
135
|
```typescript
|
|
109
136
|
import type { IModule } from '@linyjs/client-module-interface';
|
|
@@ -140,9 +167,25 @@ export const helloClientModule: IModule = {
|
|
|
140
167
|
|
|
141
168
|
### 步骤 5: 构建和打包
|
|
142
169
|
|
|
170
|
+
**推荐方式:使用开发模式 (dev)**
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# 一键打包、安装到开发环境
|
|
174
|
+
npx @linyjs/cli dev
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
这会:
|
|
178
|
+
1. 自动编译 TypeScript
|
|
179
|
+
2. 打包为 .mpk 文件
|
|
180
|
+
3. 安装到 SSR 的 extensions 目录
|
|
181
|
+
4. 注册到 packages.json
|
|
182
|
+
5. 准备就绪后重启 SSR 服务器即可测试
|
|
183
|
+
|
|
184
|
+
**传统方式:手动打包**
|
|
185
|
+
|
|
143
186
|
```bash
|
|
144
187
|
# 编译 TypeScript
|
|
145
|
-
|
|
188
|
+
npm run build
|
|
146
189
|
|
|
147
190
|
# 使用 CLI 打包为 .mpk 文件
|
|
148
191
|
npx @linyjs/cli pack
|
|
@@ -152,6 +195,18 @@ npx @linyjs/cli pack
|
|
|
152
195
|
|
|
153
196
|
### 步骤 6: 测试插件
|
|
154
197
|
|
|
198
|
+
**使用 CLI dev 模式**(已自动完成安装和注册):
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# 启动 SSR 服务器
|
|
202
|
+
cd /path/to/linyjs/packages/ssr
|
|
203
|
+
npx tsx src/demo/dev-server-with-pkg.tsx
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
访问 `http://localhost:3000/hello` 查看你的插件!
|
|
207
|
+
|
|
208
|
+
**手动部署**:
|
|
209
|
+
|
|
155
210
|
```bash
|
|
156
211
|
# 将插件复制到 extensions 目录
|
|
157
212
|
cp hello-plugin.mpk /path/to/linyjs/packages/ssr/extensions/
|