@agile-team/jh4j-cloud-cli 0.3.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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ - 增加“项目类型 → 具体模板 → 标准能力”的分层交互。
6
+ - 后端与移动端分类在无模板时明确显示为暂未提供。
7
+ - 增加通用模板能力协议及 `--features`、`--no-standards` 参数。
8
+ - PC 模板接入完整 `@robot-admin/git-standards` 可选能力。
9
+ - 调整 Git 初始化顺序,确保依赖安装时 Husky 能正确激活。
10
+ - 发布版默认使用 GitHub/Gitee HTTPS 主备源拉取模板。
11
+ - npm 包迁移到 `@agile-team/jh4j-cloud-cli` 并配置为公开发布。
12
+
13
+ ## 0.2.0
14
+
15
+ - 增加外部模板 Catalog 合并与覆盖。
16
+ - 增加用户级配置文件和 `config` 命令。
17
+ - 增加 Git、HTTP/local tar 模板源与缓存管理。
18
+ - 创建过程改为 staging 事务和失败回滚。
19
+ - 增加 `--config`、`--no-cache` 和 JSON 输出。
20
+ - 增加缓存、Catalog、配置文件与事务故障测试。
21
+
22
+ ## 0.1.0
23
+
24
+ - 首次实现 `create`、`list`、`doctor`、`info` 和模板校验。
25
+ - 接入 `jh4j-ui-template@1.0.0`。
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # jh4j-cloud-cli
2
+
3
+ JH4J Cloud 企业内部标准化项目脚手架。CLI 与模板独立发布、独立版本化,不依赖也不修改社区版 `robot-cli`。
4
+
5
+ ## 运行环境
6
+
7
+ - Node.js 24(推荐)或 Node.js 22.12+
8
+ - pnpm 11.8+
9
+ - Git(使用 Git 模板源或初始化项目仓库时需要)
10
+
11
+ ## 安装与开发
12
+
13
+ ```bash
14
+ pnpm install
15
+ pnpm check
16
+ node bin/jh4j.js doctor
17
+ ```
18
+
19
+ 发布到内部 npm 后:
20
+
21
+ ```bash
22
+ npx @agile-team/jh4j-cloud-cli create my-app
23
+
24
+ # 或全局安装
25
+ pnpm add -g @agile-team/jh4j-cloud-cli
26
+ jh4j create my-app
27
+ ```
28
+
29
+ ## 创建项目
30
+
31
+ ```bash
32
+ # 交互模式
33
+ jh4j create my-app
34
+
35
+ # 依次选择项目类型、具体模板和模板提供的标准能力
36
+ # 当前后端、移动端会显示为“暂未提供”,加入 Catalog 后自动开放
37
+
38
+ # 非交互模式
39
+ jh4j create my-app \
40
+ --yes \
41
+ --category frontend \
42
+ --template web.jh4j-mf-remote \
43
+ --module my-app \
44
+ --title "My Application" \
45
+ --port 8001
46
+
47
+ # 从 JSON 文件读取项目参数
48
+ jh4j create my-app --yes --config ./project-input.json
49
+
50
+ # 预览,不写入项目目录
51
+ jh4j create my-app --yes --dry-run
52
+
53
+ # 生成源码但不安装依赖、不初始化 Git
54
+ jh4j create my-app --yes --skip-install --skip-git
55
+
56
+ # 使用模板但不安装完整 Git/代码标准化包
57
+ jh4j create my-app --yes --no-standards
58
+ ```
59
+
60
+ PC 模板默认启用完整的 `@robot-admin/git-standards`。也可以通过 `--features git-standards` 或 JSON 参数中的 `features` 明确指定;能力选择会写入生成项目元数据。
61
+
62
+ 创建过程先在当前目录的隐藏 staging 目录中完成模板初始化。只有模板脚本和项目元数据校验成功后才原子替换目标目录;即使使用 `--force`,初始化失败时原目录也会保留。
63
+
64
+ ### 创建参数文件
65
+
66
+ `--config` 接受与模板 `project.config.json` 相同的部分字段,命令行参数优先级更高:
67
+
68
+ ```json
69
+ {
70
+ "moduleName": "orders",
71
+ "title": "订单中心",
72
+ "devServerPort": 8123,
73
+ "features": ["git-standards"],
74
+ "localBackendUrl": "http://localhost:18080",
75
+ "environments": {
76
+ "sit": {
77
+ "webUrl": "https://sit.example.internal",
78
+ "apiPrefix": "sit-api"
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ ## 模板来源
85
+
86
+ 支持以下来源:
87
+
88
+ - 本地模板目录
89
+ - Git HTTP/SSH/file URL,可指定 branch 或 tag
90
+ - 本地 `.tgz`、`.tar.gz`、`.tar`
91
+ - HTTP(S) 模板压缩包
92
+
93
+ 来源优先级:
94
+
95
+ ```text
96
+ --source
97
+ → 模板专属环境变量
98
+ → 用户配置 templateSource
99
+ → Catalog defaultSource + sources(按顺序自动降级)
100
+ ```
101
+
102
+ ```bash
103
+ jh4j create my-app --source ../jh4j-ui-template
104
+ jh4j create my-app --source https://git.example/jh4j-ui-template.git --ref v1.0.0
105
+ jh4j create my-app --source ./jh4j-ui-template-1.0.0.tgz
106
+ ```
107
+
108
+ 内置 PC 模板在 CLI 开发期优先读取兄弟目录 `../jh4j-ui-template`;发布安装后依次尝试以下 HTTPS 源,主源不可用时自动降级:
109
+
110
+ ```text
111
+ https://github.com/ChenyCHENYU/jh4j-ui-template.git
112
+ → https://gitee.com/ycyplus163/jh4j-ui-template.git
113
+ ```
114
+
115
+ 也可设置单一强制源:
116
+
117
+ ```powershell
118
+ $env:JH4J_UI_TEMPLATE_SOURCE="https://git.example/jh4j-ui-template.git"
119
+ ```
120
+
121
+ ### 模板缓存
122
+
123
+ 远程 Git 和压缩包模板按 `source + ref` 缓存在 `$JH4J_HOME/cache/templates`,默认有效期 60 分钟。
124
+
125
+ ```bash
126
+ jh4j cache list
127
+ jh4j cache list --json
128
+ jh4j cache clear
129
+ jh4j create my-app --no-cache
130
+ ```
131
+
132
+ ## 用户配置
133
+
134
+ 默认保存在 `~/.jh4j/config.json`;可以通过 `JH4J_HOME` 修改根目录。
135
+
136
+ ```bash
137
+ jh4j config list
138
+ jh4j config get autoInstall
139
+ jh4j config set autoInstall false
140
+ jh4j config set templateRef v1.0.0
141
+ jh4j config set cacheTtlMinutes 120
142
+ jh4j config unset templateRef
143
+ jh4j config reset
144
+ ```
145
+
146
+ 支持的配置项:
147
+
148
+ | 配置 | 说明 |
149
+ | --- | --- |
150
+ | `catalogFile` | 外部 Catalog JSON 文件 |
151
+ | `templateSource` | 全局模板源覆盖 |
152
+ | `templateRef` | 默认 Git branch/tag |
153
+ | `npmRegistry` | npm registry;必须能提供企业定制的非 scope 包 |
154
+ | `jhlcRegistry` | `@jhlc` 私有 registry |
155
+ | `autoInstall` | 创建后是否安装依赖 |
156
+ | `autoGit` | 创建后是否初始化 Git |
157
+ | `cacheTtlMinutes` | 模板缓存有效期,0 表示每次刷新 |
158
+
159
+ ## 外部 Catalog
160
+
161
+ 通过 `JH4J_CATALOG_FILE` 或用户配置 `catalogFile` 加载。相同 ID 会覆盖内置定义,其他模板会追加:
162
+
163
+ ```json
164
+ {
165
+ "schemaVersion": 1,
166
+ "templates": [
167
+ {
168
+ "id": "web.jh4j-mf-remote",
169
+ "name": "JH4J PC 微前端业务模板",
170
+ "description": "企业 PC 业务子系统",
171
+ "category": "frontend",
172
+ "defaultSource": "https://git.example/jh4j-ui-template.git",
173
+ "sources": [
174
+ "https://git-backup.example/jh4j-ui-template.git"
175
+ ],
176
+ "sourceEnvironment": "JH4J_UI_TEMPLATE_SOURCE",
177
+ "defaultRef": "main",
178
+ "status": "stable",
179
+ "tags": ["vue", "vite", "module-federation"]
180
+ }
181
+ ]
182
+ }
183
+ ```
184
+
185
+ ## 命令
186
+
187
+ ```text
188
+ jh4j list [--json]
189
+ jh4j create [name]
190
+ jh4j doctor [--json]
191
+ jh4j info [path] [--json]
192
+ jh4j template validate [path]
193
+ jh4j config list|get|set|unset|reset
194
+ jh4j cache list|clear
195
+ ```
196
+
197
+ ## 后续边界
198
+
199
+ 当前版本专注“可靠创建标准项目”。以下能力将在模板发布流程稳定后继续实现:
200
+
201
+ - 项目 `upgrade` 与模板 migrations
202
+ - 更多模板专属 Recipes 与标准能力追加
203
+ - GitLab 自动建仓和权限初始化
204
+ - 后端与移动端模板 Catalog
package/bin/jh4j.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/index.js";
@@ -0,0 +1,43 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:jh4j:schema:template-catalog:1",
4
+ "title": "JH4J Template Catalog",
5
+ "type": "object",
6
+ "required": ["schemaVersion", "templates"],
7
+ "properties": {
8
+ "schemaVersion": { "const": 1 },
9
+ "templates": {
10
+ "type": "array",
11
+ "items": {
12
+ "type": "object",
13
+ "required": [
14
+ "id",
15
+ "name",
16
+ "description",
17
+ "category",
18
+ "defaultSource",
19
+ "defaultRef",
20
+ "status"
21
+ ],
22
+ "properties": {
23
+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9.-]+$" },
24
+ "name": { "type": "string", "minLength": 1 },
25
+ "description": { "type": "string" },
26
+ "category": { "enum": ["frontend", "backend", "mobile"] },
27
+ "defaultSource": { "type": "string", "minLength": 1 },
28
+ "sources": {
29
+ "type": "array",
30
+ "items": { "type": "string", "minLength": 1 },
31
+ "uniqueItems": true
32
+ },
33
+ "sourceEnvironment": { "type": "string" },
34
+ "defaultRef": { "type": "string", "minLength": 1 },
35
+ "status": { "enum": ["stable", "beta"] },
36
+ "tags": { "type": "array", "items": { "type": "string" } }
37
+ },
38
+ "additionalProperties": false
39
+ }
40
+ }
41
+ },
42
+ "additionalProperties": false
43
+ }