@fastcar/cli 0.0.7 → 0.1.0

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 CHANGED
@@ -1,41 +1,279 @@
1
- # fastcar 脚手架工具
1
+ # @fastcar/cli 脚手架工具
2
2
 
3
- ## 快速安装
3
+ Fastcar 脚手架工具,用于快速初始化项目模板。
4
4
 
5
- npm install fastcar-cli
5
+ ## 特性
6
6
 
7
- ## 全局安装
7
+ - 🚀 通过 npm 包管理模板,动态获取最新版本
8
+ - 📦 支持多种项目模板(web、rpc、cos、micro、static)
9
+ - 🎯 交互式模板选择
10
+ - ⚡ 自动合并依赖和配置
11
+ - 🗜️ 项目打包(自动排除 devDependencies、日志文件)
12
+ - 🔄 数据库表逆向生成
13
+ - 🤖 AI Agent Skill 管理(支持 Kimi、Claude、Cursor)
8
14
 
9
- npm install -g fastcar-cli
15
+ ## 安装
10
16
 
11
- ## 常用命令
17
+ ### 全局安装(推荐)
12
18
 
13
- fastcar-cli -v //显示版本 fastcar-cli version 1.0.0
19
+ ```bash
20
+ npm install -g @fastcar/cli
21
+ ```
14
22
 
15
- fastcar-cli -help //显示所有命令
23
+ ### 使用 npx(无需安装)
16
24
 
17
- fastcar-cli init web //初始化web模板
25
+ ```bash
26
+ npx @fastcar/cli init
27
+ ```
18
28
 
19
- fastcar-cli init rpc //初始化rpc模板
29
+ ## 使用命令
20
30
 
21
- fastcar-cli clean node_modules //清除多余依赖库(一般使用不到)
31
+ ### 查看版本
22
32
 
23
- fastcar-cli compress node_modules //压缩依赖库(一般使用不到)
33
+ ```bash
34
+ fastcar-cli -v
35
+ # 或
36
+ fastcar-cli --version
37
+ ```
24
38
 
25
- ## web框架快速示例
39
+ ### 查看帮助
26
40
 
27
- * 安装环境 全局安装 typescript ts-node (确保ts和调试正常)
41
+ ```bash
42
+ fastcar-cli --help
43
+ ```
28
44
 
29
- * 创建文件夹 mkdir demo
45
+ ### 初始化项目
30
46
 
31
- * 切换至该目录下 cd demo/
47
+ ```bash
48
+ # 交互式选择模板
49
+ fastcar-cli init
32
50
 
33
- * 执行初始化流程 fastcar-cli init web
51
+ # 直接指定模板
52
+ fastcar-cli init web
53
+ fastcar-cli init rpc
54
+ fastcar-cli init cos
55
+ fastcar-cli init micro
56
+ fastcar-cli init static
57
+ ```
34
58
 
35
- * 安装项目依赖 yarn install 或者 npm install
59
+ ### 项目打包
36
60
 
37
- * 项目启动 npm run debug
61
+ 将项目打包成 zip 文件,自动排除 `devDependencies`、`node_modules`、`dist`、`logs` 和 `*.log` 文件。
38
62
 
39
- * 访问根目录 <http://localhost:1234/>
63
+ ```bash
64
+ # 自动检测包管理器(根据 lock 文件)
65
+ fastcar-cli pack
40
66
 
41
- * 查看api文档 <http://localhost:1234/api.docs>
67
+ # 指定包管理器
68
+ fastcar-cli pack npm
69
+ fastcar-cli pack yarn
70
+ fastcar-cli pack pnpm
71
+ ```
72
+
73
+ 打包后的文件位于 `dist/{name}-{version}.zip`,解压后目录名为当前项目文件夹名。
74
+
75
+ ### 数据库逆向生成
76
+
77
+ 根据数据库表结构生成 Model 和 Mapper 文件。
78
+
79
+ ```bash
80
+ # 生成配置文件
81
+ fastcar-cli reverse:init
82
+
83
+ # 执行逆向生成
84
+ fastcar-cli reverse
85
+ ```
86
+
87
+ 配置文件 `reverse.config.json` 示例:
88
+
89
+ ```json
90
+ {
91
+ "tables": ["test"],
92
+ "modelDir": "/path/to/models",
93
+ "mapperDir": "/path/to/mappers",
94
+ "dbConfig": {
95
+ "host": "localhost",
96
+ "port": 3306,
97
+ "user": "root",
98
+ "password": "password",
99
+ "database": "test_db"
100
+ },
101
+ "style": {
102
+ "tabWidth": 4,
103
+ "printWidth": 200,
104
+ "trailingComma": "es5",
105
+ "useTabs": true,
106
+ "parser": "typescript",
107
+ "endOfLine": "crlf"
108
+ },
109
+ "ignoreCamelcase": false
110
+ }
111
+ ```
112
+
113
+ ### Skill 管理
114
+
115
+ 将 FastCar skill 安装到支持的 AI Agent 中,让 AI 在对话时掌握 FastCar 框架知识。
116
+
117
+ #### 列出可用的 skills
118
+
119
+ ```bash
120
+ fastcar-cli skill list
121
+ ```
122
+
123
+ #### 列出支持的 AI Agents
124
+
125
+ ```bash
126
+ fastcar-cli skill targets
127
+ ```
128
+
129
+ #### 安装 skill
130
+
131
+ ```bash
132
+ # 交互式选择安装位置(全局/本地)
133
+ fastcar-cli skill install fastcar-framework
134
+
135
+ # 全局安装(默认)
136
+ fastcar-cli skill install fastcar-framework --global
137
+ fastcar-cli skill install fastcar-framework -g
138
+
139
+ # 本地安装(仅当前项目可用)
140
+ fastcar-cli skill install fastcar-framework --local
141
+ fastcar-cli skill install fastcar-framework -l
142
+
143
+ # 指定目标 agent
144
+ fastcar-cli skill install fastcar-framework --target kimi
145
+ fastcar-cli skill install fastcar-framework -t claude
146
+ ```
147
+
148
+ #### 可用的 FastCar Skills
149
+
150
+ | Skill 名称 | 适用场景 | 安装命令 |
151
+ |-----------|---------|---------|
152
+ | fastcar-framework | IoC 核心、Koa Web、项目模板、基础配置 | `fastcar-cli skill install fastcar-framework` |
153
+ | fastcar-database | MySQL/PGSQL/MongoDB/Redis ORM、逆向生成 | `fastcar-cli skill install fastcar-database` |
154
+ | fastcar-rpc-microservices | RPC 通信、微服务架构、Socket/gRPC | `fastcar-cli skill install fastcar-rpc-microservices` |
155
+ | fastcar-serverless | 阿里云 FC / 腾讯云 SCF / AWS Lambda | `fastcar-cli skill install fastcar-serverless` |
156
+ | fastcar-toolkit | 缓存、定时任务、时间轮、工作线程池、COS SDK | `fastcar-cli skill install fastcar-toolkit` |
157
+
158
+ #### 卸载 skill
159
+
160
+ ```bash
161
+ fastcar-cli skill uninstall fastcar-framework
162
+ ```
163
+
164
+ #### 初始化项目级 agent 配置
165
+
166
+ ```bash
167
+ fastcar-cli skill init
168
+ ```
169
+
170
+ ### 其他命令
171
+
172
+ ```bash
173
+ # 清除多余依赖库
174
+ fastcar-cli clean node_modules
175
+
176
+ # 压缩依赖库
177
+ fastcar-cli compress node_modules
178
+ ```
179
+
180
+ ## 快速开始
181
+
182
+ ### 创建 Web 项目示例
183
+
184
+ ```bash
185
+ # 创建项目目录
186
+ mkdir my-project
187
+ cd my-project
188
+
189
+ # 初始化项目(交互式选择模板)
190
+ fastcar-cli init
191
+
192
+ # 或者直接指定 web 模板
193
+ fastcar-cli init web
194
+
195
+ # 安装依赖
196
+ npm install
197
+
198
+ # 启动项目
199
+ npm run dev
200
+ ```
201
+
202
+ ### 打包项目示例
203
+
204
+ ```bash
205
+ # 进入项目目录
206
+ cd my-project
207
+
208
+ # 打包项目(自动检测包管理器)
209
+ fastcar-cli pack
210
+
211
+ # 使用 yarn 打包
212
+ fastcar-cli pack yarn
213
+
214
+ # 输出: dist/my-project-1.0.0.zip
215
+ ```
216
+
217
+ ## 可用模板
218
+
219
+ | 模板名称 | 包名 | 说明 |
220
+ |---------|------|------|
221
+ | web | @fastcar/template-web | Web 应用模板 |
222
+ | rpc | @fastcar/template-rpc | RPC 服务模板 |
223
+ | cos | @fastcar/template-cos | COS 存储模板 |
224
+ | micro | @fastcar/template-microservices | 微服务模板 |
225
+ | static | @fastcar/template-static | 静态资源模板 |
226
+
227
+ ## 自定义模板
228
+
229
+ ### 创建模板包
230
+
231
+ 1. 初始化 npm 项目
232
+
233
+ ```bash
234
+ mkdir template-mytemplate
235
+ cd template-mytemplate
236
+ npm init
237
+ ```
238
+
239
+ 2. 创建 `template/` 目录并放入项目文件
240
+
241
+ 3. 发布到 npm
242
+
243
+ ```bash
244
+ npm publish --access public
245
+ ```
246
+
247
+ 详细说明请参考 [template-example/README.md](./template-example/README.md)
248
+
249
+ ### 注册模板
250
+
251
+ 在 `src/templates.json` 中添加模板配置:
252
+
253
+ ```json
254
+ {
255
+ "mytemplate": {
256
+ "name": "mytemplate",
257
+ "description": "我的自定义模板",
258
+ "package": "@fastcar/template-mytemplate",
259
+ "tags": ["custom"]
260
+ }
261
+ }
262
+ ```
263
+
264
+ ## 模板包规范
265
+
266
+ 模板包必须遵循以下结构:
267
+
268
+ ```
269
+ template-xxx/
270
+ ├── package.json # 模板包的 package.json
271
+ ├── README.md # 模板说明文档
272
+ └── template/ # 模板文件目录(必需)
273
+ ├── package.json # 项目模板中的 package.json
274
+ └── ... # 其他项目文件
275
+ ```
276
+
277
+ ## 许可证
278
+
279
+ MIT
package/bin/cli.js CHANGED
@@ -2,52 +2,222 @@
2
2
 
3
3
  const init = require("../src/init");
4
4
  const setModules = require("../src/setModules");
5
+ const { reverseGenerate, initReverseConfig } = require("../src/reverse");
6
+ const { packProject } = require("../src/pack");
7
+ const {
8
+ installSkill,
9
+ uninstallSkill,
10
+ listSkills,
11
+ listTargets,
12
+ initSkill,
13
+ } = require("../src/skill");
5
14
  const packageINFO = require("../package.json");
15
+ const templates = require("../src/templates.json");
6
16
 
7
- function run(argv) {
17
+ function showHelp() {
18
+ console.log(`
19
+ Usage: fastcar-cli [command] [options]
8
20
 
9
- //命令入口
10
- if (!argv || argv.length == 0 || argv[0] === '-v' || argv[0] === '--version') {
11
- console.log(`fastcar-cli version ${packageINFO.version}`);
12
- return;
13
- }
21
+ Commands:
22
+ init [template] [name] 初始化项目
23
+ template: 模板名称 (${Object.keys(templates).join(", ")})
24
+ name: 项目名称(可选,默认使用当前目录名)
14
25
 
15
- let head = argv[0];
16
- let body = argv.slice(1);
26
+ clean node_modules 删除冗余的 node_modules 目录
27
+ compress node_modules 压缩 node_modules 目录
28
+ reverse 数据库表逆向生成
29
+ reverse:init 生成 reverse.config.json 配置文件
30
+ pack [pm] 打包项目(排除 devDependencies)
31
+ pm: 包管理器 (npm/yarn/pnpm),可选,默认自动检测
17
32
 
18
- switch (head) {
33
+ skill install <name> 安装 FastCar skill 到本地 AI Agent
34
+ -g, --global 安装到全局(默认)
35
+ -l, --local 安装到项目级
36
+ -t, --target 目标 agent (kimi/claude/cursor)
37
+ skill uninstall <name> 卸载 FastCar skill
38
+ skill list 列出可用的 skills
39
+ skill targets 列出支持的 AI Agents
40
+ skill init 初始化项目级 agent 配置
19
41
 
20
- case "init": {
21
- init(body);
22
- break;
23
- }
24
- case "clean":
25
- case "compress": {
42
+ Options:
43
+ -v, --version 显示版本号
44
+ -h, --help 显示帮助信息
26
45
 
27
- if (!body[0]) {
46
+ Examples:
47
+ $ fastcar-cli init # 交互式选择模板
48
+ $ fastcar-cli init web # 使用 web 模板
49
+ $ fastcar-cli init rpc # 使用 rpc 模板
50
+ $ fastcar-cli init micro # 使用 microservices 模板
51
+ $ fastcar-cli init cos # 使用 cos 模板
52
+ $ fastcar-cli init static # 使用 static 模板
53
+ $ fastcar-cli init my-project # 创建 my-project 目录
54
+ $ fastcar-cli init web my-project # 使用 web 模板创建 my-project
55
+ $ fastcar-cli clean node_modules
56
+ $ fastcar-cli reverse # 数据库表逆向生成
57
+ $ fastcar-cli reverse:init # 生成默认配置文件
58
+ $ fastcar-cli pack # 打包项目(自动检测包管理器)
59
+ $ fastcar-cli pack yarn # 使用 yarn 安装依赖
60
+ $ fastcar-cli pack pnpm # 使用 pnpm 安装依赖
28
61
 
29
- body[0] = "node_modules";
30
- }
62
+ $ fastcar-cli skill install fastcar-framework # 交互式安装
63
+ $ fastcar-cli skill install fastcar-framework -g # 全局安装
64
+ $ fastcar-cli skill install fastcar-framework -l # 本地安装
65
+ $ fastcar-cli skill install fastcar-framework -t kimi # 安装到 Kimi
66
+ $ fastcar-cli skill list # 列出可用 skills
67
+ $ fastcar-cli skill targets # 列出支持的 agents
31
68
 
32
- if (body[0] == "node_modules") {
69
+ Reverse 命令参数说明:
70
+ 通过配置文件传入参数,在项目根目录创建 reverse.config.json:
33
71
 
34
- setModules(body[0], head == "compress");
35
- } else {
72
+ {
73
+ "tables": ["test"], // 要逆向生成的表名数组(必填)
74
+ "modelDir": "/path/to/models", // Model 文件输出目录绝对路径(必填)
75
+ "mapperDir": "/path/to/mappers", // Mapper 文件输出目录绝对路径(必填)
76
+ "dbConfig": { // MySQL 数据库配置(必填)
77
+ "host": "localhost",
78
+ "port": 3306,
79
+ "user": "root",
80
+ "password": "password",
81
+ "database": "test_db"
82
+ },
83
+ "style": { // Prettier 格式化配置(可选)
84
+ "tabWidth": 4,
85
+ "printWidth": 200,
86
+ "trailingComma": "es5",
87
+ "useTabs": true,
88
+ "parser": "typescript",
89
+ "endOfLine": "crlf"
90
+ },
91
+ "ignoreCamelcase": false // 是否忽略驼峰命名转换(可选,默认 false)
92
+ }
93
+
94
+ 也可以使用 reverse:init 命令生成默认配置文件:
95
+ $ fastcar-cli reverse:init
96
+ `);
97
+ }
98
+
99
+ function showVersion() {
100
+ console.log(`fastcar-cli version ${packageINFO.version}`);
101
+ }
102
+
103
+ function run(argv) {
104
+ // 命令入口
105
+ if (!argv || argv.length === 0) {
106
+ showHelp();
107
+ return;
108
+ }
109
+
110
+ const head = argv[0];
111
+ const body = argv.slice(1);
112
+
113
+ switch (head) {
114
+ case "-v":
115
+ case "--version": {
116
+ showVersion();
117
+ break;
118
+ }
119
+ case "-h":
120
+ case "--help": {
121
+ showHelp();
122
+ break;
123
+ }
124
+ case "init": {
125
+ init(body);
126
+ break;
127
+ }
128
+ case "clean":
129
+ case "compress": {
130
+ if (!body[0]) {
131
+ body[0] = "node_modules";
132
+ }
36
133
 
37
- console.log("Missing file path");
38
- }
39
- break;
134
+ if (body[0] === "node_modules") {
135
+ setModules(body[0], head === "compress");
136
+ } else {
137
+ console.log("❌ 缺少文件路径");
138
+ }
139
+ break;
140
+ }
141
+ case "reverse": {
142
+ reverseGenerate(body);
143
+ break;
144
+ }
145
+ case "reverse:init": {
146
+ initReverseConfig();
147
+ break;
148
+ }
149
+ case "pack": {
150
+ const pm = body[0]; // 可选的包管理器参数
151
+ packProject(null, null, pm);
152
+ break;
153
+ }
154
+ case "skill": {
155
+ const subCmd = body[0];
156
+ const args = body.slice(1);
157
+
158
+ // 解析参数
159
+ const options = {
160
+ global: args.includes("-g") || args.includes("--global"),
161
+ local: args.includes("-l") || args.includes("--local"),
162
+ target: null,
163
+ };
164
+
165
+ // 解析 --target 或 -t
166
+ const targetIdx = args.findIndex((a) => a === "-t" || a === "--target");
167
+ if (targetIdx !== -1 && args[targetIdx + 1]) {
168
+ options.target = args[targetIdx + 1];
169
+ }
170
+
171
+ // 移除参数,保留 skill name
172
+ const skillName = args.find((a) => !a.startsWith("-"));
173
+
174
+ switch (subCmd) {
175
+ case "install": {
176
+ if (!skillName) {
177
+ console.log("❌ 请指定 skill 名称");
178
+ console.log(
179
+ "用法: fastcar-cli skill install <skill-name> [options]",
180
+ );
181
+ return;
182
+ }
183
+ installSkill(skillName, options);
184
+ break;
185
+ }
186
+ case "uninstall": {
187
+ if (!skillName) {
188
+ console.log("❌ 请指定 skill 名称");
189
+ console.log(
190
+ "用法: fastcar-cli skill uninstall <skill-name> [options]",
191
+ );
192
+ return;
193
+ }
194
+ uninstallSkill(skillName, options);
195
+ break;
196
+ }
197
+ case "list": {
198
+ listSkills();
199
+ break;
200
+ }
201
+ case "targets": {
202
+ listTargets();
203
+ break;
204
+ }
205
+ case "init": {
206
+ initSkill(options);
207
+ break;
40
208
  }
41
209
  default: {
42
- //命令提示
43
- console.log(' usage:\n');
44
- console.log(' -v --version [show version]\n');
45
- console.log(' init web [init web template]\n');
46
- console.log(' init rpc [init rpc template]\n');
47
- console.log(' clean node_modules [Delete redundant modules]\n');
48
- console.log(' compress node_modules [compress modules]\n');
210
+ console.log("❌ 未知的 skill 命令");
211
+ console.log("可用的子命令: install, uninstall, list, targets, init");
49
212
  }
213
+ }
214
+ break;
215
+ }
216
+ default: {
217
+ console.log(`❌ 未知命令: ${head}\n`);
218
+ showHelp();
50
219
  }
220
+ }
51
221
  }
52
222
 
53
- run(process.argv.slice(2));
223
+ run(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/cli",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "homepage": "https://william_zhong.coding.net/public/fast-car/fastcar-cli/git/files",
5
5
  "description": "fastcar-cli 脚手架快速搭建",
6
6
  "bin": {
@@ -9,7 +9,7 @@
9
9
  "files": [
10
10
  "bin",
11
11
  "src",
12
- "node_modules"
12
+ "skills"
13
13
  ],
14
14
  "keywords": [
15
15
  "node",
@@ -28,6 +28,6 @@
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "https://e.coding.net/william_zhong/fast-car/fastcar-cli.git"
31
+ "url": "https://github.com/williamDazhangyu/fastcar-cli.git"
32
32
  }
33
33
  }