@fastcar/cli 0.0.7 → 0.0.8

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,221 @@
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
+ - 🔄 数据库表逆向生成
8
13
 
9
- npm install -g fastcar-cli
14
+ ## 安装
10
15
 
11
- ## 常用命令
16
+ ### 全局安装(推荐)
12
17
 
13
- fastcar-cli -v //显示版本 fastcar-cli version 1.0.0
18
+ ```bash
19
+ npm install -g @fastcar/cli
20
+ ```
14
21
 
15
- fastcar-cli -help //显示所有命令
22
+ ### 使用 npx(无需安装)
16
23
 
17
- fastcar-cli init web //初始化web模板
24
+ ```bash
25
+ npx @fastcar/cli init
26
+ ```
18
27
 
19
- fastcar-cli init rpc //初始化rpc模板
28
+ ## 使用命令
20
29
 
21
- fastcar-cli clean node_modules //清除多余依赖库(一般使用不到)
30
+ ### 查看版本
22
31
 
23
- fastcar-cli compress node_modules //压缩依赖库(一般使用不到)
32
+ ```bash
33
+ fastcar-cli -v
34
+ # 或
35
+ fastcar-cli --version
36
+ ```
24
37
 
25
- ## web框架快速示例
38
+ ### 查看帮助
26
39
 
27
- * 安装环境 全局安装 typescript ts-node (确保ts和调试正常)
40
+ ```bash
41
+ fastcar-cli --help
42
+ ```
28
43
 
29
- * 创建文件夹 mkdir demo
44
+ ### 初始化项目
30
45
 
31
- * 切换至该目录下 cd demo/
46
+ ```bash
47
+ # 交互式选择模板
48
+ fastcar-cli init
32
49
 
33
- * 执行初始化流程 fastcar-cli init web
50
+ # 直接指定模板
51
+ fastcar-cli init web
52
+ fastcar-cli init rpc
53
+ fastcar-cli init cos
54
+ fastcar-cli init micro
55
+ fastcar-cli init static
56
+ ```
34
57
 
35
- * 安装项目依赖 yarn install 或者 npm install
58
+ ### 项目打包
36
59
 
37
- * 项目启动 npm run debug
60
+ 将项目打包成 zip 文件,自动排除 `devDependencies`、`node_modules`、`dist`、`logs` 和 `*.log` 文件。
38
61
 
39
- * 访问根目录 <http://localhost:1234/>
62
+ ```bash
63
+ # 自动检测包管理器(根据 lock 文件)
64
+ fastcar-cli pack
40
65
 
41
- * 查看api文档 <http://localhost:1234/api.docs>
66
+ # 指定包管理器
67
+ fastcar-cli pack npm
68
+ fastcar-cli pack yarn
69
+ fastcar-cli pack pnpm
70
+ ```
71
+
72
+ 打包后的文件位于 `dist/{name}-{version}.zip`,解压后目录名为当前项目文件夹名。
73
+
74
+ ### 数据库逆向生成
75
+
76
+ 根据数据库表结构生成 Model 和 Mapper 文件。
77
+
78
+ ```bash
79
+ # 生成配置文件
80
+ fastcar-cli reverse:init
81
+
82
+ # 执行逆向生成
83
+ fastcar-cli reverse
84
+ ```
85
+
86
+ 配置文件 `reverse.config.json` 示例:
87
+
88
+ ```json
89
+ {
90
+ "tables": ["test"],
91
+ "modelDir": "/path/to/models",
92
+ "mapperDir": "/path/to/mappers",
93
+ "dbConfig": {
94
+ "host": "localhost",
95
+ "port": 3306,
96
+ "user": "root",
97
+ "password": "password",
98
+ "database": "test_db"
99
+ },
100
+ "style": {
101
+ "tabWidth": 4,
102
+ "printWidth": 200,
103
+ "trailingComma": "es5",
104
+ "useTabs": true,
105
+ "parser": "typescript",
106
+ "endOfLine": "crlf"
107
+ },
108
+ "ignoreCamelcase": false
109
+ }
110
+ ```
111
+
112
+ ### 其他命令
113
+
114
+ ```bash
115
+ # 清除多余依赖库
116
+ fastcar-cli clean node_modules
117
+
118
+ # 压缩依赖库
119
+ fastcar-cli compress node_modules
120
+ ```
121
+
122
+ ## 快速开始
123
+
124
+ ### 创建 Web 项目示例
125
+
126
+ ```bash
127
+ # 创建项目目录
128
+ mkdir my-project
129
+ cd my-project
130
+
131
+ # 初始化项目(交互式选择模板)
132
+ fastcar-cli init
133
+
134
+ # 或者直接指定 web 模板
135
+ fastcar-cli init web
136
+
137
+ # 安装依赖
138
+ npm install
139
+
140
+ # 启动项目
141
+ npm run dev
142
+ ```
143
+
144
+ ### 打包项目示例
145
+
146
+ ```bash
147
+ # 进入项目目录
148
+ cd my-project
149
+
150
+ # 打包项目(自动检测包管理器)
151
+ fastcar-cli pack
152
+
153
+ # 使用 yarn 打包
154
+ fastcar-cli pack yarn
155
+
156
+ # 输出: dist/my-project-1.0.0.zip
157
+ ```
158
+
159
+ ## 可用模板
160
+
161
+ | 模板名称 | 包名 | 说明 |
162
+ |---------|------|------|
163
+ | web | @fastcar/template-web | Web 应用模板 |
164
+ | rpc | @fastcar/template-rpc | RPC 服务模板 |
165
+ | cos | @fastcar/template-cos | COS 存储模板 |
166
+ | micro | @fastcar/template-microservices | 微服务模板 |
167
+ | static | @fastcar/template-static | 静态资源模板 |
168
+
169
+ ## 自定义模板
170
+
171
+ ### 创建模板包
172
+
173
+ 1. 初始化 npm 项目
174
+
175
+ ```bash
176
+ mkdir template-mytemplate
177
+ cd template-mytemplate
178
+ npm init
179
+ ```
180
+
181
+ 2. 创建 `template/` 目录并放入项目文件
182
+
183
+ 3. 发布到 npm
184
+
185
+ ```bash
186
+ npm publish --access public
187
+ ```
188
+
189
+ 详细说明请参考 [template-example/README.md](./template-example/README.md)
190
+
191
+ ### 注册模板
192
+
193
+ 在 `src/templates.json` 中添加模板配置:
194
+
195
+ ```json
196
+ {
197
+ "mytemplate": {
198
+ "name": "mytemplate",
199
+ "description": "我的自定义模板",
200
+ "package": "@fastcar/template-mytemplate",
201
+ "tags": ["custom"]
202
+ }
203
+ }
204
+ ```
205
+
206
+ ## 模板包规范
207
+
208
+ 模板包必须遵循以下结构:
209
+
210
+ ```
211
+ template-xxx/
212
+ ├── package.json # 模板包的 package.json
213
+ ├── README.md # 模板说明文档
214
+ └── template/ # 模板文件目录(必需)
215
+ ├── package.json # 项目模板中的 package.json
216
+ └── ... # 其他项目文件
217
+ ```
218
+
219
+ ## 许可证
220
+
221
+ MIT
package/bin/cli.js CHANGED
@@ -1,53 +1,138 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
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");
5
7
  const packageINFO = require("../package.json");
8
+ const templates = require("../src/templates.json");
6
9
 
7
- function run(argv) {
10
+ function showHelp() {
11
+ console.log(`
12
+ Usage: fastcar-cli [command] [options]
8
13
 
9
- //命令入口
10
- if (!argv || argv.length == 0 || argv[0] === '-v' || argv[0] === '--version') {
11
- console.log(`fastcar-cli version ${packageINFO.version}`);
12
- return;
13
- }
14
+ Commands:
15
+ init [template] [name] 初始化项目
16
+ template: 模板名称 (${Object.keys(templates).join(", ")})
17
+ name: 项目名称(可选,默认使用当前目录名)
18
+
19
+ clean node_modules 删除冗余的 node_modules 目录
20
+ compress node_modules 压缩 node_modules 目录
21
+ reverse 数据库表逆向生成
22
+ reverse:init 生成 reverse.config.json 配置文件
23
+ pack [pm] 打包项目(排除 devDependencies)
24
+ pm: 包管理器 (npm/yarn/pnpm),可选,默认自动检测
25
+
26
+ Options:
27
+ -v, --version 显示版本号
28
+ -h, --help 显示帮助信息
14
29
 
15
- let head = argv[0];
16
- let body = argv.slice(1);
30
+ Examples:
31
+ $ fastcar-cli init # 交互式选择模板
32
+ $ fastcar-cli init web # 使用 web 模板
33
+ $ fastcar-cli init rpc # 使用 rpc 模板
34
+ $ fastcar-cli init micro # 使用 microservices 模板
35
+ $ fastcar-cli init cos # 使用 cos 模板
36
+ $ fastcar-cli init static # 使用 static 模板
37
+ $ fastcar-cli init my-project # 创建 my-project 目录
38
+ $ fastcar-cli init web my-project # 使用 web 模板创建 my-project
39
+ $ fastcar-cli clean node_modules
40
+ $ fastcar-cli reverse # 数据库表逆向生成
41
+ $ fastcar-cli reverse:init # 生成默认配置文件
42
+ $ fastcar-cli pack # 打包项目(自动检测包管理器)
43
+ $ fastcar-cli pack yarn # 使用 yarn 安装依赖
44
+ $ fastcar-cli pack pnpm # 使用 pnpm 安装依赖
17
45
 
18
- switch (head) {
46
+ Reverse 命令参数说明:
47
+ 通过配置文件传入参数,在项目根目录创建 reverse.config.json:
19
48
 
20
- case "init": {
21
- init(body);
22
- break;
23
- }
24
- case "clean":
25
- case "compress": {
49
+ {
50
+ "tables": ["test"], // 要逆向生成的表名数组(必填)
51
+ "modelDir": "/path/to/models", // Model 文件输出目录绝对路径(必填)
52
+ "mapperDir": "/path/to/mappers", // Mapper 文件输出目录绝对路径(必填)
53
+ "dbConfig": { // MySQL 数据库配置(必填)
54
+ "host": "localhost",
55
+ "port": 3306,
56
+ "user": "root",
57
+ "password": "password",
58
+ "database": "test_db"
59
+ },
60
+ "style": { // Prettier 格式化配置(可选)
61
+ "tabWidth": 4,
62
+ "printWidth": 200,
63
+ "trailingComma": "es5",
64
+ "useTabs": true,
65
+ "parser": "typescript",
66
+ "endOfLine": "crlf"
67
+ },
68
+ "ignoreCamelcase": false // 是否忽略驼峰命名转换(可选,默认 false)
69
+ }
26
70
 
27
- if (!body[0]) {
71
+ 也可以使用 reverse:init 命令生成默认配置文件:
72
+ $ fastcar-cli reverse:init
73
+ `);
74
+ }
28
75
 
29
- body[0] = "node_modules";
30
- }
76
+ function showVersion() {
77
+ console.log(`fastcar-cli version ${packageINFO.version}`);
78
+ }
31
79
 
32
- if (body[0] == "node_modules") {
80
+ function run(argv) {
81
+ // 命令入口
82
+ if (!argv || argv.length === 0) {
83
+ showHelp();
84
+ return;
85
+ }
33
86
 
34
- setModules(body[0], head == "compress");
35
- } else {
87
+ const head = argv[0];
88
+ const body = argv.slice(1);
36
89
 
37
- console.log("Missing file path");
38
- }
39
- break;
40
- }
41
- 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');
49
- }
90
+ switch (head) {
91
+ case "-v":
92
+ case "--version": {
93
+ showVersion();
94
+ break;
95
+ }
96
+ case "-h":
97
+ case "--help": {
98
+ showHelp();
99
+ break;
100
+ }
101
+ case "init": {
102
+ init(body);
103
+ break;
104
+ }
105
+ case "clean":
106
+ case "compress": {
107
+ if (!body[0]) {
108
+ body[0] = "node_modules";
109
+ }
110
+
111
+ if (body[0] === "node_modules") {
112
+ setModules(body[0], head === "compress");
113
+ } else {
114
+ console.log("❌ 缺少文件路径");
115
+ }
116
+ break;
117
+ }
118
+ case "reverse": {
119
+ reverseGenerate(body);
120
+ break;
121
+ }
122
+ case "reverse:init": {
123
+ initReverseConfig();
124
+ break;
125
+ }
126
+ case "pack": {
127
+ const pm = body[0]; // 可选的包管理器参数
128
+ packProject(null, null, pm);
129
+ break;
130
+ }
131
+ default: {
132
+ console.log(`❌ 未知命令: ${head}\n`);
133
+ showHelp();
50
134
  }
135
+ }
51
136
  }
52
137
 
53
- run(process.argv.slice(2));
138
+ 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.0.8",
4
4
  "homepage": "https://william_zhong.coding.net/public/fast-car/fastcar-cli/git/files",
5
5
  "description": "fastcar-cli 脚手架快速搭建",
6
6
  "bin": {
@@ -8,8 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "bin",
11
- "src",
12
- "node_modules"
11
+ "src"
13
12
  ],
14
13
  "keywords": [
15
14
  "node",
@@ -28,6 +27,6 @@
28
27
  },
29
28
  "repository": {
30
29
  "type": "git",
31
- "url": "https://e.coding.net/william_zhong/fast-car/fastcar-cli.git"
30
+ "url": "https://github.com/williamDazhangyu/fastcar-cli.git"
32
31
  }
33
32
  }