create-zhin-app 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,344 @@
1
+ # create-zhin-app
2
+
3
+ 快速创建 Zhin 机器人项目的脚手架工具,提供一键创建和配置新项目的能力。
4
+
5
+ ## 核心特性
6
+
7
+ - 🚀 **一键创建**: 使用标准的 `npm create` / `yarn create` / `pnpm create` 命令
8
+ - 🔧 **智能配置**: 自动处理项目初始化和依赖安装
9
+ - 📦 **零安装**: 无需全局安装,直接使用
10
+ - 🎯 **参数透传**: 完美支持所有 CLI 参数和选项
11
+
12
+ ## 快速开始
13
+
14
+ ### 使用不同包管理器创建项目
15
+
16
+ ```bash
17
+ # npm (推荐)
18
+ npm create zhin-app my-awesome-bot
19
+
20
+ # yarn
21
+ yarn create zhin-app my-awesome-bot
22
+
23
+ # pnpm
24
+ pnpm create zhin-app my-awesome-bot
25
+
26
+ # 使用最新版本
27
+ npx create-zhin-app@latest my-awesome-bot
28
+ ```
29
+
30
+ ## 工作原理
31
+
32
+ `create-zhin-app` 是 `@zhin.js/cli` 的轻量级包装器,它的工作流程如下:
33
+
34
+ 1. **启动脚手架**: 当你运行 `npm create zhin` 时
35
+ 2. **参数解析**: 解析项目名称和所有命令行参数
36
+ 3. **调用 CLI**: 自动调用 `zhin init` 命令
37
+ 4. **参数转发**: 将所有参数原样传递给 CLI 工具
38
+ 5. **项目创建**: 完成项目初始化和配置
39
+
40
+ ```javascript
41
+ // create-zhin-app 内部实现概览
42
+ const args = process.argv.slice(2);
43
+ const initArgs = ['init', ...args];
44
+
45
+ spawn('npx', ['zhin', ...initArgs], {
46
+ stdio: 'inherit',
47
+ cwd: process.cwd()
48
+ });
49
+ ```
50
+
51
+ ## 支持的参数
52
+
53
+ 所有 `zhin init` 支持的参数都可以通过 `create-zhin-app` 使用:
54
+
55
+ ### 基础用法
56
+
57
+ ```bash
58
+ # 使用默认配置创建项目
59
+ npm create zhin-app my-bot
60
+
61
+ # 交互式创建(会提示选择配置)
62
+ npm create zhin-app my-bot --interactive
63
+ ```
64
+
65
+ ### 高级配置
66
+
67
+ ```bash
68
+ # 完整配置示例
69
+ npm create zhin-app my-bot -- \
70
+ --config ts \
71
+ --package-manager pnpm \
72
+ --runtime bun \
73
+ --yes
74
+ ```
75
+
76
+ ### 参数详解
77
+
78
+ | 参数 | 短参数 | 说明 | 可选值 | 默认值 |
79
+ |------|--------|------|--------|--------|
80
+ | `--config` | `-c` | 配置文件格式 | `js`, `ts`, `json`, `yaml`, `toml` | `js` |
81
+ | `--package-manager` | `-p` | 包管理器 | `npm`, `yarn`, `pnpm` | `pnpm` |
82
+ | `--runtime` | `-r` | 运行时 | `node`, `bun` | `bun` |
83
+ | `--yes` | `-y` | 跳过交互式配置 | 无 | `false` |
84
+
85
+ ## 使用场景
86
+
87
+ ### 1. 快速原型开发
88
+
89
+ ```bash
90
+ # 使用默认配置快速创建
91
+ npm create zhin-app quick-prototype -y
92
+ cd quick-prototype
93
+ npm run dev
94
+ ```
95
+
96
+ ### 2. 生产项目创建
97
+
98
+ ```bash
99
+ # 使用 TypeScript + pnpm + bun 的生产配置
100
+ npm create zhin-app production-bot -- -c ts -p pnpm -r bun
101
+ ```
102
+
103
+ ### 3. 团队标准项目
104
+
105
+ ```bash
106
+ # 为团队创建标准化项目
107
+ npm create zhin-app team-bot -- \
108
+ --config ts \
109
+ --package-manager pnpm \
110
+ --runtime node \
111
+ --yes
112
+ ```
113
+
114
+ ### 4. 实验性项目
115
+
116
+ ```bash
117
+ # 使用最新技术栈
118
+ npm create zhin-app experimental-bot -- -c ts -r bun -y
119
+ ```
120
+
121
+ ## 生成的项目结构
122
+
123
+ 执行 `create-zhin-app` 后会生成完整的项目结构:
124
+
125
+ ```
126
+ my-awesome-bot/
127
+ ├── src/
128
+ │ ├── index.ts # 主入口文件
129
+ │ └── plugins/ # 插件目录
130
+ │ └── test-plugin.ts # 示例插件
131
+ ├── lib/ # 构建输出目录
132
+ ├── data/ # 数据存储目录
133
+ ├── logs/ # 日志目录(如果配置了)
134
+ ├── zhin.config.[ext] # 配置文件
135
+ ├── package.json # 项目依赖和脚本
136
+ ├── tsconfig.json # TypeScript配置
137
+ ├── .gitignore # Git忽略规则
138
+ ├── .env.example # 环境变量模板
139
+ ├── pnpm-workspace.yaml # pnpm工作空间(如果使用pnpm)
140
+ └── README.md # 项目说明文档
141
+ ```
142
+
143
+ ## 配置文件格式
144
+
145
+ ### JavaScript 配置 (推荐)
146
+
147
+ ```javascript
148
+ // zhin.config.ts
149
+ import { defineConfig } from '@zhin.js/core';
150
+
151
+ export default defineConfig(async (env) => {
152
+ return {
153
+ bots: [
154
+ {
155
+ context: 'process',
156
+ name: `${process.pid}`,
157
+ }
158
+ ],
159
+ plugin_dirs: ['./src/plugins', 'node_modules'],
160
+ plugins: ['process', 'test-plugin'],
161
+ debug: env.DEBUG === 'true'
162
+ };
163
+ });
164
+ ```
165
+
166
+ ### TypeScript 配置
167
+
168
+ ```typescript
169
+ // zhin.config.ts
170
+ import { defineConfig } from '@zhin.js/core';
171
+ import type { AppConfig } from '@zhin.js/core';
172
+
173
+ export default defineConfig<AppConfig>(async (env) => {
174
+ return {
175
+ bots: [
176
+ {
177
+ context: 'onebot11',
178
+ name: 'main-bot',
179
+ url: env.BOT_URL || 'ws://localhost:8080',
180
+ }
181
+ ],
182
+ plugin_dirs: ['./src/plugins'],
183
+ debug: process.env.NODE_ENV === 'development'
184
+ };
185
+ });
186
+ ```
187
+
188
+ ## 后续步骤
189
+
190
+ 项目创建完成后,可以执行以下操作:
191
+
192
+ ### 1. 进入项目目录
193
+
194
+ ```bash
195
+ cd my-awesome-bot
196
+ ```
197
+
198
+ ### 2. 安装依赖(如果还没安装)
199
+
200
+ ```bash
201
+ # 根据选择的包管理器
202
+ npm install
203
+ # 或
204
+ yarn install
205
+ # 或
206
+ pnpm install
207
+ ```
208
+
209
+ ### 3. 开发模式启动
210
+
211
+ ```bash
212
+ npm run dev
213
+ # 或
214
+ yarn dev
215
+ # 或
216
+ pnpm dev
217
+ ```
218
+
219
+ ### 4. 生产环境部署
220
+
221
+ ```bash
222
+ # 构建项目
223
+ npm run build
224
+
225
+ # 生产启动
226
+ npm run start
227
+
228
+ # 后台运行
229
+ npm run daemon
230
+ ```
231
+
232
+ ## 错误处理
233
+
234
+ ### 常见错误及解决方案
235
+
236
+ 1. **网络连接问题**
237
+ ```bash
238
+ # 使用国内镜像
239
+ npm config set registry https://registry.npmmirror.com
240
+ npm create zhin-app my-bot
241
+ ```
242
+
243
+ 2. **权限问题**
244
+ ```bash
245
+ # macOS/Linux
246
+ sudo chown -R $USER ~/.npm
247
+
248
+ # Windows (以管理员身份运行)
249
+ npm create zhin-app my-bot
250
+ ```
251
+
252
+ 3. **Node.js 版本问题**
253
+ ```bash
254
+ # 检查 Node.js 版本(需要 >= 18.0.0)
255
+ node --version
256
+
257
+ # 升级 Node.js
258
+ # 使用 nvm 或从官网下载最新版本
259
+ ```
260
+
261
+ ## 环境要求
262
+
263
+ - **Node.js**: >= 18.0.0
264
+ - **npm**: >= 8.0.0 (或对应版本的 yarn/pnpm)
265
+ - **操作系统**: Windows 10+, macOS 10.15+, Linux (现代发行版)
266
+
267
+ ## 与其他工具对比
268
+
269
+ | 特性 | create-zhin-app | create-react-app | create-vue |
270
+ |------|-------------|------------------|------------|
271
+ | 零配置创建 | ✅ | ✅ | ✅ |
272
+ | 多配置格式 | ✅ | ❌ | ✅ |
273
+ | 多运行时支持 | ✅ | ❌ | ❌ |
274
+ | 机器人框架 | ✅ | ❌ | ❌ |
275
+ | 热重载开发 | ✅ | ✅ | ✅ |
276
+
277
+ ## 高级用法
278
+
279
+ ### 自定义模板
280
+
281
+ 虽然 `create-zhin-app` 主要调用 CLI 工具,但你可以通过环境变量自定义行为:
282
+
283
+ ```bash
284
+ # 设置自定义模板路径
285
+ ZHIN_TEMPLATE_DIR=/path/to/custom/template npm create zhin-app my-bot
286
+ ```
287
+
288
+ ### 批量创建
289
+
290
+ ```bash
291
+ #!/bin/bash
292
+ # 批量创建多个项目
293
+ for name in bot1 bot2 bot3; do
294
+ npm create zhin-app $name -- -y
295
+ done
296
+ ```
297
+
298
+ ### CI/CD 集成
299
+
300
+ ```yaml
301
+ # GitHub Actions 示例
302
+ - name: create zhin-app Bot Project
303
+ run: |
304
+ npm create zhin-app test-bot -- --yes
305
+ cd test-bot
306
+ npm run build
307
+ npm run test
308
+ ```
309
+
310
+ ## 故障排查
311
+
312
+ ### 调试模式
313
+
314
+ ```bash
315
+ # 启用详细日志
316
+ DEBUG=create-zhin-app npm create zhin-app my-bot
317
+
318
+ # 检查参数传递
319
+ npm create zhin-app my-bot -- --help
320
+ ```
321
+
322
+ ### 清理缓存
323
+
324
+ ```bash
325
+ # 清理 npm 缓存
326
+ npm cache clean --force
327
+
328
+ # 删除 node_modules 重新安装
329
+ rm -rf node_modules package-lock.json
330
+ npm install
331
+ ```
332
+
333
+ ## 贡献指南
334
+
335
+ `create-zhin-app` 是开源项目,欢迎贡献:
336
+
337
+ 1. Fork 项目
338
+ 2. 创建特性分支
339
+ 3. 提交更改
340
+ 4. 创建 Pull Request
341
+
342
+ ## 许可证
343
+
344
+ MIT License
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/lib/index.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { dirname, join } from 'node:path';
5
+ // 获取当前文件目录
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+ // 计算CLI的绝对路径
9
+ const cliPath = join(__dirname, '../../cli/lib/cli.js');
10
+ // 直接调用 CLI 的 init 命令
11
+ const args = process.argv.slice(2);
12
+ const initArgs = ['init', ...args];
13
+ const child = spawn('node', [cliPath, ...initArgs], {
14
+ stdio: 'inherit',
15
+ cwd: process.cwd()
16
+ });
17
+ child.on('close', (code) => {
18
+ process.exit(code || 0);
19
+ });
20
+ child.on('error', (error) => {
21
+ // console.error 已替换为注释
22
+ process.exit(1);
23
+ });
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,WAAW;AACX,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,aAAa;AACb,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;AAExD,qBAAqB;AACrB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AAEnC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE;IAClD,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;CACnB,CAAC,CAAC;AAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;IACzB,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;IAC1B,uBAAuB;IACvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "create-zhin-app",
3
+ "version": "1.0.1",
4
+ "description": "Create a new zhin bot project",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-zhin": "./lib/index.js"
8
+ },
9
+ "files": [
10
+ "lib"
11
+ ],
12
+ "dependencies": {
13
+ "@zhin.js/cli": "1.0.1"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^24.3.0",
17
+ "typescript": "^5.3.0",
18
+ "@zhin.js/types": "1.0.1"
19
+ },
20
+ "engines": {
21
+ "node": ">=18.0.0"
22
+ },
23
+ "keywords": [
24
+ "zhin",
25
+ "bot",
26
+ "create",
27
+ "scaffold",
28
+ "template"
29
+ ],
30
+ "author": "zhin team",
31
+ "license": "MIT",
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "dev": "tsc --watch",
35
+ "clean": "rm -rf lib"
36
+ }
37
+ }