gz-cli-front 0.0.0-stage → 1.0.1-beta.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 +188 -3
- package/bin/gz-cli-front.js +2 -0
- package/dist/config/gz-cli-front.config.json +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1472 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -6
package/README.md
CHANGED
|
@@ -1,3 +1,188 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# gz-cli-front
|
|
2
|
+
|
|
3
|
+
一个轻量级的现代前端脚手架工具,通过远程模板创建项目。
|
|
4
|
+
|
|
5
|
+
npm 包名为 `gz-cli-front`,安装后使用 `gz-cli` 命令。
|
|
6
|
+
|
|
7
|
+
版本变化见 [更新日志](CHANGELOG.md)。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g gz-cli-front
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
gz-cli init [project-name]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
也可以不全局安装,直接运行:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx gz-cli-front init demo-app
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`create` 命令仍可使用,例如 `gz-cli create demo-app`。
|
|
28
|
+
同时保留 `gz-cli-front` 作为兼容命令,两者执行相同逻辑;新包不注册旧的 `gg-cli` 命令。
|
|
29
|
+
|
|
30
|
+
从旧包迁移时可执行:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm uninstall -g @chenhui996/gg-cli
|
|
34
|
+
npm install -g gz-cli-front
|
|
35
|
+
gz-cli --version
|
|
36
|
+
gz-cli init demo-app
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
切换 CLI 后,新建项目会使用当前远程模板;已有业务项目不会自动迁移。
|
|
40
|
+
|
|
41
|
+
可通过 `--pm` 指定本次初始化使用的包管理器:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
gz-cli init demo-app --pm npm
|
|
45
|
+
gz-cli init demo-app --pm pnpm
|
|
46
|
+
gz-cli init demo-app --pm yarn
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
未指定时,CLI 会按 `pnpm`、`yarn`、`npm` 的顺序检测当前环境;都未检测到时默认使用 `npm`。模板注册表不包含包管理器配置。
|
|
50
|
+
|
|
51
|
+
### 网络代理
|
|
52
|
+
|
|
53
|
+
CLI 会自动读取当前系统代理,不绑定具体代理工具、地址或端口。代理优先级如下:
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
--no-proxy 强制直连
|
|
57
|
+
--proxy 参数
|
|
58
|
+
HTTP_PROXY / HTTPS_PROXY / NO_PROXY
|
|
59
|
+
操作系统代理
|
|
60
|
+
无代理直连
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
临时指定代理或强制直连:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
gz-cli init demo-app --proxy http://proxy-host:port
|
|
67
|
+
gz-cli init demo-app --no-proxy
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
系统代理检测支持 Windows、macOS 和 Linux。代理相关日志只显示网络路径,不输出代理地址、账号或密码。
|
|
71
|
+
|
|
72
|
+
### 模板缓存
|
|
73
|
+
|
|
74
|
+
模板注册仓库和模板仓库会浅克隆并缓存到 `~/.gz-cli-front/cache`,减少重复创建项目时的网络等待。需要忽略缓存并获取最新内容时执行:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
gz-cli init demo-app --refresh
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
注册表缓存有效期为 5 分钟,`latest` 模板缓存有效期为 10 分钟;指定版本的模板缓存可以长期复用。远程暂时不可用时,未指定 `--refresh` 会回退到已有缓存。
|
|
81
|
+
|
|
82
|
+
模板注册仓库和模板仓库均为公共仓库,默认通过配置中的 HTTPS 地址直接下载,无需配置 GitHub Token 或 SSH Key。Git 操作设有超时并支持网络代理;如显式配置 SSH clone URL,仍会使用本机 SSH Agent。
|
|
83
|
+
|
|
84
|
+
可通过 `GZ_CLI_FRONT_CACHE_DIR` 指定缓存目录,通过 `GZ_CLI_FRONT_DEBUG=1` 开启网络和模板调试日志。新包不读取旧的 `GG_CLI_*` 环境变量,也不复用旧包的默认缓存目录。
|
|
85
|
+
|
|
86
|
+
模板注册仓库由 `config/gz-cli-front.config.json` 管理,现有远程仓库地址保持不变:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"templateRegistry": {
|
|
91
|
+
"source": "git",
|
|
92
|
+
"url": "https://github.com/gz-fronted/gg-cli-template-register.git",
|
|
93
|
+
"file": "templates.json"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
注册表中的每个模板使用独立仓库,例如:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
[
|
|
102
|
+
{
|
|
103
|
+
"name": "main-app",
|
|
104
|
+
"label": "主应用模板",
|
|
105
|
+
"description": "Garfish 主应用模板",
|
|
106
|
+
"type": "main",
|
|
107
|
+
"source": "git",
|
|
108
|
+
"url": "https://github.com/your-org/gg-cli-template-main-app.git",
|
|
109
|
+
"version": "latest"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "micro-app",
|
|
113
|
+
"label": "微应用模板",
|
|
114
|
+
"description": "Garfish 微应用模板",
|
|
115
|
+
"type": "micro",
|
|
116
|
+
"source": "git",
|
|
117
|
+
"url": "https://github.com/your-org/gg-cli-template-micro-app.git",
|
|
118
|
+
"version": "latest"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
公共仓库建议使用 `source: "git"` 和 HTTPS clone URL,避免要求使用者配置 SSH Key。CLI 会按配置的协议执行浅克隆;`source` 仍兼容 `github`、`gitlab` 和 `git`,旧的 GitHub `repo` 配置也可继续使用。
|
|
124
|
+
|
|
125
|
+
### Git 仓库访问测试
|
|
126
|
+
|
|
127
|
+
发版前可以在本机验证 Git 仓库访问失败时的错误提示,不会修改全局 Git 配置:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm run test:auth-error
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
该脚本使用独立缓存和模拟失败的 Git 命令运行构建后的 CLI,要求在超时前返回明确错误。正常访问链路仍使用以下命令验证:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm run build
|
|
137
|
+
node dist/index.js init --refresh
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
发版前统一执行:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm run test:release
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
该命令会依次验证构建、命令入口及参数、HTTPS Git 兼容性、公共注册仓库访问、失败错误提示和 npm 发布包内容。
|
|
147
|
+
|
|
148
|
+
如果已经手动执行过 `npm run build`,可以只验证构建产物和 Git 场景:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm run test:smoke
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 发布到 npm
|
|
155
|
+
|
|
156
|
+
本包以 `gz-cli-front` 为独立包名,初始版本为 `1.0.0`,不会覆盖或更新旧的 `@chenhui996/gg-cli` 包。
|
|
157
|
+
|
|
158
|
+
首次发布前,确认包名尚未被占用,并登录有发布权限的 npm 账号:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npm view gz-cli-front --registry=https://registry.npmjs.org/
|
|
162
|
+
npm login --registry=https://registry.npmjs.org/
|
|
163
|
+
npm whoami --registry=https://registry.npmjs.org/
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
查询返回 E404 表示未找到该包;网络或认证错误不能作为包名可用的判断依据。最终能否发布以 npm 的校验结果为准。
|
|
167
|
+
|
|
168
|
+
安装依赖并验证:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npm ci
|
|
172
|
+
npm run test:release
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
确认通过后发布:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npm publish --registry=https://registry.npmjs.org/
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
发布时会自动通过 `prepublishOnly` 再运行一次发布验证。发布内容包括 `bin`、构建后的 `dist`、包信息和 README,不包含 `src/template` 中的本地模板。
|
|
182
|
+
|
|
183
|
+
发布后可验证:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npm view gz-cli-front version --registry=https://registry.npmjs.org/
|
|
187
|
+
npx --registry=https://registry.npmjs.org/ gz-cli-front@1.0.0 --version
|
|
188
|
+
```
|
package/dist/index.d.ts
ADDED