@soybeanjs/cli 1.8.1 → 1.8.3

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.
@@ -0,0 +1,207 @@
1
+ # @soybeanjs/cli
2
+
3
+ <p align="center">
4
+ <img src="https://r2.soybeanjs.tech/soybeanjs/logo-soybeanjs.svg" alt="SoybeanJS" width="96" />
5
+ </p>
6
+
7
+ [简体中文](./README.md) | English
8
+
9
+ The SoybeanJS command-line toolkit for consistent Git commits, dependency upgrades, changelog generation, releases, and project cleanup.
10
+
11
+ ## Contents
12
+
13
+ - [Install](#install)
14
+ - [Common workflows](#common-workflows)
15
+ - [Command reference](#command-reference)
16
+ - [Configuration](#configuration)
17
+ - [AI Skill](#ai-skill)
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pnpm add -D @soybeanjs/cli
23
+ # or
24
+ npm i -D @soybeanjs/cli
25
+ # or
26
+ yarn add -D @soybeanjs/cli
27
+ ```
28
+
29
+ After installation, we recommend running commands as `pnpm soy <command>`. `npx soy <command>` is also supported.
30
+
31
+ ## Common Workflows
32
+
33
+ ### Commit code
34
+
35
+ ```bash
36
+ pnpm soy git-commit
37
+ ```
38
+
39
+ Choose a commit type and scope, then provide a description to create a Conventional Commit. Start the description with `!` to mark a breaking change.
40
+
41
+ ### Upgrade dependencies
42
+
43
+ ```bash
44
+ pnpm soy ncu
45
+ pnpm install
46
+ ```
47
+
48
+ `ncu` uses npm-check-updates to update versions in `package.json`. It automatically enables workspace mode in workspace projects. Reinstall dependencies afterward, then run the project's build and test commands to validate the update.
49
+
50
+ ### Generate a changelog
51
+
52
+ ```bash
53
+ # Generate from the most recent tag
54
+ pnpm soy changelog
55
+
56
+ # Rebuild from all tags
57
+ pnpm soy changelog --total
58
+ ```
59
+
60
+ ### Release a version
61
+
62
+ ```bash
63
+ pnpm soy release
64
+ ```
65
+
66
+ The release flow interactively bumps the version, runs `pnpm soy changelog`, creates a `chore(projects): release v<version>` commit and Git tag, then pushes them to the remote. Ensure the working tree is clean and all release changes have already been committed.
67
+
68
+ > [!WARNING]
69
+ > The current `release` command pushes the commit and tag by default. Confirm the branch, remote, and release contents before running it.
70
+
71
+ ### Clean project artifacts
72
+
73
+ ```bash
74
+ pnpm soy cleanup
75
+ ```
76
+
77
+ Default cleanup patterns include `dist`, `node_modules`, and npm, Yarn, and pnpm lockfiles. To clean only selected paths, pass comma-separated globs with `--cleanupDir`:
78
+
79
+ ```bash
80
+ pnpm soy cleanup --cleanupDir "**/dist,**/coverage"
81
+ ```
82
+
83
+ ## Command Reference
84
+
85
+ ### Commands
86
+
87
+ | Command | Description |
88
+ | ------------------------- | -------------------------------------------------------------------------------------------------- |
89
+ | `cleanup` | Removes files and directories by glob. Defaults include build output, dependencies, and lockfiles. |
90
+ | `ncu` | Upgrades dependencies through npm-check-updates; workspace projects automatically receive `-w`. |
91
+ | `git-commit` | Interactively creates a Conventional Commit. |
92
+ | `git-commit-verify` | Validates `.git/COMMIT_EDITMSG`; suitable for a `commit-msg` hook. |
93
+ | `changelog` | Generates `CHANGELOG.md` from Git tags and commit history. |
94
+ | `release` | Interactively bumps the version, generates the changelog, creates a commit and tag, then pushes. |
95
+ | `config <set\|get\|path>` | Sets, reads, or locates global configuration. |
96
+ | `update-pkg` | Deprecated. Use `ncu` instead. |
97
+
98
+ ### Options
99
+
100
+ | Option | Applies to | Description |
101
+ | ------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------ |
102
+ | `-e, --execute [command]` | `release` | Runs a command after the version bump and before the release commit. Defaults to `pnpm soy changelog`. |
103
+ | `-t, --total` | `changelog` | Generates the changelog from all Git tags. |
104
+ | `-c, --cleanupDir <dir>` | `cleanup` | Overrides cleanup globs for this run. Separate multiple values with commas. |
105
+ | `-l, --lang <lang>` | `git-commit`, `git-commit-verify` | Sets output language for this invocation to `zh-cn` or `en-us`. |
106
+ | `-v, --version` | Global | Displays the version. |
107
+ | `-h, --help` | Global | Displays help. |
108
+
109
+ ### Commit message format
110
+
111
+ `git-commit` produces the following format. The `scope` is optional. When the description starts with `!`, the marker is kept before the colon to identify a breaking change.
112
+
113
+ ```text
114
+ <type>(<scope>)<!>: <description>
115
+ ```
116
+
117
+ ```bash
118
+ feat(components): add new Button component
119
+ fix(utils)!: change API signature
120
+ ```
121
+
122
+ Default types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `optimize`, `test`, `build`, `ci`, `chore`, `revert`.
123
+
124
+ Default scopes: `projects`, `packages`, `components`, `hooks`, `utils`, `types`, `styles`, `deps`, `release`, `other`.
125
+
126
+ ### Global configuration commands
127
+
128
+ | Command | Description |
129
+ | ----------------------------------------------- | ---------------------------------------------- |
130
+ | `pnpm soy config set --set-lang <zh-cn\|en-us>` | Writes the default language to `~/.soybeanrc`. |
131
+ | `pnpm soy config get` | Prints the current merged configuration. |
132
+ | `pnpm soy config path` | Prints the global configuration file path. |
133
+
134
+ ## Configuration
135
+
136
+ Configuration is merged in this order: command-line arguments, project configuration, global configuration, then built-in defaults. Project configuration can use the following names; TypeScript is recommended:
137
+
138
+ - `soybean.config.ts`
139
+ - `soybean.config.js`
140
+ - `soybean.config.mjs`
141
+ - `soybean.config.json`
142
+ - the `soybean` field in `package.json`
143
+
144
+ Use `defineConfig` for type hints:
145
+
146
+ ```ts
147
+ // soybean.config.ts
148
+ import { defineConfig } from '@soybeanjs/cli';
149
+
150
+ export default defineConfig({
151
+ lang: 'zh-cn',
152
+ cleanupDirs: ['**/dist', '**/.cache', '**/coverage', '**/node_modules', '!node_modules/**'],
153
+ gitCommit: {
154
+ types: [['wip', 'Work in progress']],
155
+ scopes: [
156
+ ['ui', 'UI components'],
157
+ ['api', 'API integration']
158
+ ]
159
+ }
160
+ });
161
+ ```
162
+
163
+ ### Options
164
+
165
+ | Option | Type | Description |
166
+ | ------------------------ | -------------------------- | -------------------------------------------------------------------------------------------- |
167
+ | `cwd` | `string` | Project root. Defaults to `process.cwd()`. |
168
+ | `lang` | `'zh-cn' \| 'en-us'` | Default CLI output language. |
169
+ | `cleanupDirs` | `string[]` | Glob patterns used by `cleanup`. |
170
+ | `ncuCommandArgs` | `string[]` | Arguments passed to npm-check-updates. When set, it replaces automatically derived defaults. |
171
+ | `changelogOptions` | `Partial<ChangelogOption>` | Options passed to the changelog generator. |
172
+ | `gitCommitVerifyIgnores` | `RegExp[]` | Commit-message validation patterns appended to the built-in ignore list. |
173
+ | `gitCommit.types` | `[string, string][]` | Custom commit types. Appended to built-in types by default. |
174
+ | `gitCommit.typesAppend` | `boolean` | Set to `false` to replace built-in commit types. |
175
+ | `gitCommit.scopes` | `[string, string][]` | Custom commit scopes. Appended to built-in scopes by default. |
176
+ | `gitCommit.scopesAppend` | `boolean` | Set to `false` to replace built-in commit scopes. |
177
+
178
+ ### Recommended scripts
179
+
180
+ ```json
181
+ {
182
+ "scripts": {
183
+ "commit": "soy git-commit",
184
+ "commit:zh": "soy git-commit -l=zh-cn",
185
+ "cleanup": "soy cleanup",
186
+ "ncu": "soy ncu",
187
+ "changelog": "soy changelog",
188
+ "release": "soy release"
189
+ }
190
+ }
191
+ ```
192
+
193
+ ## AI Skill
194
+
195
+ This repository includes the `soybean-cli` skill, which helps AI coding assistants use `soy` correctly for commits, releases, changelog generation, dependency upgrades, and cleanup in SoybeanJS projects.
196
+
197
+ After the repository is published on GitHub, install it with:
198
+
199
+ ```bash
200
+ npx skills add soybeanjs/cli
201
+ ```
202
+
203
+ Select `soybean-cli` during installation. The skill source is in [skills/soybean-cli](./skills/soybean-cli).
204
+
205
+ ## License
206
+
207
+ [MIT](./LICENSE)
package/README.md CHANGED
@@ -1,17 +1,20 @@
1
1
  # @soybeanjs/cli
2
2
 
3
- SoybeanJS 的命令行工具集,提供 Git 提交规范、依赖更新、Changelog 生成、版本发布等便捷功能。
3
+ <p align="center">
4
+ <img src="https://r2.soybeanjs.tech/soybeanjs/logo-soybeanjs.svg" alt="SoybeanJS" width="96" />
5
+ </p>
4
6
 
5
- ## 特性
7
+ 简体中文 | [English](./README.en-US.md)
6
8
 
7
- - 📝 **符合 Conventional Commits 规范的 Git 提交** - 交互式选择提交类型和范围
8
- - ✅ **提交信息校验** - 自动校验 commit message 是否符合规范
9
- - 🧹 **清理功能** - 一键清理 node_modules、dist 等目录
10
- - 📦 **依赖更新** - 基于 npm-check-updates 快速升级依赖
11
- - 📋 **Changelog 生成** - 根据 Git tags 自动生成变更日志
12
- - 🚀 **版本发布** - 一键完成版本更新、Changelog 生成、代码提交和推送
13
- - 🌍 **多语言支持** - 支持中文和英文,可持久化设置默认语言
14
- - ⚙️ **灵活配置** - 支持项目级和全局配置,可自定义提交类型和范围
9
+ SoybeanJS 的命令行工具集,用于统一 Git 提交、依赖升级、Changelog 生成、版本发布和项目清理等日常工作流。
10
+
11
+ ## 目录
12
+
13
+ - [安装](#安装)
14
+ - [常用工作流](#常用工作流)
15
+ - [命令参考](#命令参考)
16
+ - [配置](#配置)
17
+ - [AI Skill](#ai-skill)
15
18
 
16
19
  ## 安装
17
20
 
@@ -23,241 +26,156 @@ npm i -D @soybeanjs/cli
23
26
  yarn add -D @soybeanjs/cli
24
27
  ```
25
28
 
26
- 安装后可通过 `pnpm soy` 或 `npx soy` 使用 CLI 命令。
29
+ 安装后,推荐通过 `pnpm soy <command>` 调用命令;也可使用 `npx soy <command>`。
27
30
 
28
- ## 快速开始
31
+ ## 常用工作流
29
32
 
30
- ```bash
31
- # 查看帮助
32
- pnpm soy -h
33
+ ### 提交代码
33
34
 
34
- # 交互式 Git 提交
35
+ ```bash
35
36
  pnpm soy git-commit
36
37
  ```
37
38
 
38
- ## 命令说明
39
+ 依次选择提交类型、提交范围并填写描述,即可生成符合 Conventional Commits 的提交信息。描述以 `!` 开头时会标记为破坏性变更。
39
40
 
40
- ### 全局选项
41
+ ### 升级依赖
41
42
 
42
- | 选项 | 说明 | 默认值 |
43
- | ------------------------- | --------------------------------------------- | --------------------------------------- |
44
- | `-v, --version` | 显示版本号 | - |
45
- | `-e, --execute [command]` | 版本发布时在 bump 之后、commit 之前执行的命令 | `pnpm soy changelog` |
46
- | `-p, --push` | 发布时是否推送 Git 提交和标签 | - |
47
- | `-t, --total` | 生成 Changelog 时基于所有标签 | - |
48
- | `-c, --cleanupDir <dir>` | 指定清理目录,多个目录用逗号分隔 | 见配置 |
49
- | `-l, --lang <lang>` | CLI 显示语言 (`zh-cn` / `en-us`) | `en-us`(可通过 config 命令持久化修改) |
50
- | `-h, --help` | 显示帮助信息 | - |
43
+ ```bash
44
+ pnpm soy ncu
45
+ pnpm install
46
+ ```
51
47
 
52
- ### 命令列表
48
+ `ncu` 使用 npm-check-updates 更新 `package.json` 中的依赖版本;在 workspace 项目中会自动启用 workspace 模式。完成后重新安装依赖,并运行项目的构建和测试命令验证变更。
53
49
 
54
- | 命令 | 说明 |
55
- | ------------------- | ---------------------------------------------------------------- |
56
- | `cleanup` | 清理目录(node_modules、dist、lock 文件等) |
57
- | `ncu` | 升级 package.json 中的依赖到最新版本 |
58
- | `update-pkg` | [已废弃] 请使用 `ncu` 代替 |
59
- | `git-commit` | 交互式生成符合 Conventional Commits 规范的 Git 提交信息 |
60
- | `git-commit-verify` | 校验 Git 提交信息是否符合规范(通常配合 Git hooks 使用) |
61
- | `changelog` | 根据 Git tags 生成 Changelog |
62
- | `release` | 一键发布:更新版本号 → 生成 Changelog → 提交代码 → 打标签 → 推送 |
63
- | `config <cmd>` | 管理 CLI 配置 |
50
+ ### 生成 Changelog
64
51
 
65
- ### config 子命令
52
+ ```bash
53
+ # 根据最近的 tag 生成变更日志
54
+ pnpm soy changelog
66
55
 
67
- | 命令 | 说明 |
68
- | ------------------------------ | -------------------------------------------------------------- |
69
- | `config set --set-lang <lang>` | 设置默认语言(`zh-cn` 或 `en-us`),配置会持久化到全局配置文件 |
70
- | `config get` | 查看当前配置信息 |
71
- | `config path` | 显示全局配置文件路径 |
56
+ # 基于所有 tag 重建变更日志
57
+ pnpm soy changelog --total
58
+ ```
72
59
 
73
- #### 使用示例
60
+ ### 发布版本
74
61
 
75
62
  ```bash
76
- # 设置默认语言为中文
77
- pnpm soy config set --set-lang zh-cn
63
+ pnpm soy release
64
+ ```
78
65
 
79
- # 设置默认语言为英文
80
- pnpm soy config set --set-lang en-us
66
+ 发布流程会交互式更新版本号、执行 `pnpm soy changelog`、创建 `chore(projects): release v<version>` 提交和 Git tag,并推送到远端。执行前确保工作区干净且待发布的改动均已提交。
81
67
 
82
- # 查看当前配置
83
- pnpm soy config get
68
+ > [!WARNING]
69
+ > 当前 `release` 命令默认推送提交和 tag。请在执行前确认分支、远端和发布内容均正确。
84
70
 
85
- # 查看全局配置文件位置
86
- pnpm soy config path
71
+ ### 清理项目产物
72
+
73
+ ```bash
74
+ pnpm soy cleanup
87
75
  ```
88
76
 
89
- ### git-commit 命令详解
77
+ 默认清理规则包含 `dist`、`node_modules` 以及 npm、Yarn、pnpm 的 lock 文件。若只想清理指定目录,可通过 `--cleanupDir` 传入逗号分隔的 glob:
78
+
79
+ ```bash
80
+ pnpm soy cleanup --cleanupDir "**/dist,**/coverage"
81
+ ```
90
82
 
91
- 使用 `pnpm soy git-commit` 进行交互式提交:
83
+ ## 命令参考
92
84
 
93
- 1. **选择提交类型 (type)** - 如 feat、fix、docs、style 等
94
- 2. **选择提交范围 (scope)** - 如 projects、components、utils 等
95
- 3. **输入提交描述** - 在描述前加 `!` 表示破坏性变更(Breaking Change)
85
+ ### 命令
96
86
 
97
- 生成的提交信息格式:
87
+ | 命令 | 说明 |
88
+ | ------------------------- | ---------------------------------------------------------------- |
89
+ | `cleanup` | 按 glob 清理目录和文件。默认包含构建产物、依赖目录和 lock 文件。 |
90
+ | `ncu` | 使用 npm-check-updates 升级依赖;workspace 项目会自动传入 `-w`。 |
91
+ | `git-commit` | 交互式创建符合 Conventional Commits 的 Git 提交。 |
92
+ | `git-commit-verify` | 校验 `.git/COMMIT_EDITMSG`,适合配置在 `commit-msg` hook 中。 |
93
+ | `changelog` | 从 Git tag 和提交历史生成 `CHANGELOG.md`。 |
94
+ | `release` | 交互式更新版本、生成 Changelog、创建提交和 tag,并推送到远端。 |
95
+ | `config <set\|get\|path>` | 设置、查看或定位全局配置。 |
96
+ | `update-pkg` | 已废弃,请使用 `ncu`。 |
98
97
 
99
- ```
100
- <type>(<scope>)<!>: <description>
101
- ```
98
+ ### 选项
102
99
 
103
- 示例:
100
+ | 选项 | 适用命令 | 说明 |
101
+ | ------------------------- | --------------------------------- | ------------------------------------------------------------------- |
102
+ | `-e, --execute [command]` | `release` | 指定版本更新后、创建提交前执行的命令;默认是 `pnpm soy changelog`。 |
103
+ | `-t, --total` | `changelog` | 使用全部 Git tag 生成 Changelog。 |
104
+ | `-c, --cleanupDir <dir>` | `cleanup` | 覆盖本次执行的清理 glob;多个值用逗号分隔。 |
105
+ | `-l, --lang <lang>` | `git-commit`、`git-commit-verify` | 将本次 CLI 输出设为 `zh-cn` 或 `en-us`。 |
106
+ | `-v, --version` | 全局 | 显示版本号。 |
107
+ | `-h, --help` | 全局 | 显示帮助信息。 |
104
108
 
109
+ ### 提交信息格式
110
+
111
+ `git-commit` 生成的格式如下。`scope` 可以省略;若描述以 `!` 开头,则会在冒号前保留 `!` 以标记破坏性变更。
112
+
113
+ ```text
114
+ <type>(<scope>)<!>: <description>
105
115
  ```
116
+
117
+ ```bash
106
118
  feat(components): add new Button component
107
119
  fix(utils)!: change API signature
108
120
  ```
109
121
 
110
- ## 配置
122
+ 默认提交类型:`feat`、`fix`、`docs`、`style`、`refactor`、`perf`、`optimize`、`test`、`build`、`ci`、`chore`、`revert`。
111
123
 
112
- 支持两层配置:
124
+ 默认提交范围:`projects`、`packages`、`components`、`hooks`、`utils`、`types`、`styles`、`deps`、`release`、`other`。
113
125
 
114
- 1. **全局配置** - `~/.soybeanrc`(JSON 格式),通过 `config set` 命令管理
115
- 2. **项目配置** - 项目根目录下的配置文件(支持 TS/JS 等格式),优先级高于全局配置
126
+ ### 全局配置命令
116
127
 
117
- ### 配置文件
128
+ | 命令 | 说明 |
129
+ | ----------------------------------------------- | ----------------------------------- |
130
+ | `pnpm soy config set --set-lang <zh-cn\|en-us>` | 将默认显示语言写入 `~/.soybeanrc`。 |
131
+ | `pnpm soy config get` | 输出当前合并后的配置。 |
132
+ | `pnpm soy config path` | 输出全局配置文件路径。 |
133
+
134
+ ## 配置
118
135
 
119
- 在项目根目录创建配置文件(支持以下名称):
136
+ 配置按以下优先级合并:命令行参数、项目配置、全局配置、内置默认值。项目配置可使用以下文件名,推荐 TypeScript:
120
137
 
121
- - `soybean.config.ts`(推荐)
138
+ - `soybean.config.ts`
122
139
  - `soybean.config.js`
123
140
  - `soybean.config.mjs`
124
141
  - `soybean.config.json`
125
- - 在 `package.json` 的 `soybean` 字段中配置
142
+ - `package.json` 中的 `soybean` 字段
126
143
 
127
- 使用 TypeScript 配置时,使用 `defineConfig` 获得类型提示:
144
+ 使用 `defineConfig` 可获得类型提示:
128
145
 
129
146
  ```ts
130
147
  // soybean.config.ts
131
148
  import { defineConfig } from '@soybeanjs/cli';
132
149
 
133
150
  export default defineConfig({
134
- // 配置项
135
- });
136
- ```
137
-
138
- ### 配置项
139
-
140
- | 配置项 | 类型 | 说明 | 默认值 |
141
- | ------------------------ | -------------------------- | -------------------------------------- | ---------------------------------------------------------- |
142
- | `cwd` | `string` | 项目根目录 | `process.cwd()` |
143
- | `lang` | `'zh-cn' \| 'en-us'` | 默认显示语言 | `'en-us'` |
144
- | `cleanupDirs` | `string[]` | 需要清理的目录 glob 模式 | `['**/dist', '**/node_modules', '**/pnpm-lock.yaml', ...]` |
145
- | `ncuCommandArgs` | `string[]` | ncu 命令参数 | 自动解析 workspace |
146
- | `changelogOptions` | `Partial<ChangelogOption>` | Changelog 生成选项 | `{}` |
147
- | `gitCommitVerifyIgnores` | `RegExp[]` | 提交信息校验忽略规则(追加到默认规则) | 见源码 |
148
- | `gitCommit` | `GitCommitConfig` | Git 提交配置 | 见下方 |
149
-
150
- ### Git 提交配置 (gitCommit)
151
-
152
- 用于自定义 commit types 和 scopes:
153
-
154
- | 配置项 | 类型 | 说明 | 默认值 |
155
- | ------------------------ | -------------------- | --------------------------------------------------------- | ----------- |
156
- | `gitCommit.types` | `[string, string][]` | 自定义提交类型 | 默认 types |
157
- | `gitCommit.typesAppend` | `boolean` | 自定义 types 是否追加到默认 types(`false` 则完全覆盖) | `true` |
158
- | `gitCommit.scopes` | `[string, string][]` | 自定义提交范围 | 默认 scopes |
159
- | `gitCommit.scopesAppend` | `boolean` | 自定义 scopes 是否追加到默认 scopes(`false` 则完全覆盖) | `true` |
160
-
161
- **默认提交类型 (types):**
162
-
163
- | type | 说明 (中文) | 说明 (English) |
164
- | ---------- | ------------------------------------- | ------------------------------------------------------------- |
165
- | `feat` | 新功能 | A new feature |
166
- | `fix` | 修复 Bug | A bug fix |
167
- | `docs` | 文档更新 | Documentation only changes |
168
- | `style` | 代码风格修改(不影响代码含义) | Changes that do not affect the meaning of the code |
169
- | `refactor` | 代码重构(既不修复 bug 也不添加功能) | A code change that neither fixes a bug nor adds a feature |
170
- | `perf` | 性能优化 | A code change that improves performance |
171
- | `optimize` | 代码质量优化 | A code change that optimizes code quality |
172
- | `test` | 测试相关 | Adding missing tests or correcting existing tests |
173
- | `build` | 构建系统或外部依赖变更 | Changes that affect the build system or external dependencies |
174
- | `ci` | CI 配置变更 | Changes to CI configuration files and scripts |
175
- | `chore` | 其他不修改 src/测试文件的变更 | Other changes that don't modify src or test files |
176
- | `revert` | 还原先前的提交 | Reverts a previous commit |
177
-
178
- **默认提交范围 (scopes):**
179
-
180
- | scope | 说明 (中文) | 说明 (English) |
181
- | ------------ | -------------- | -------------------- |
182
- | `projects` | 项目 | project |
183
- | `packages` | 包 | packages |
184
- | `components` | 组件 | components |
185
- | `hooks` | 钩子函数 | hook functions |
186
- | `utils` | 工具函数 | utils functions |
187
- | `types` | TS 类型声明 | TS declaration |
188
- | `styles` | 代码风格 | style |
189
- | `deps` | 项目依赖 | project dependencies |
190
- | `release` | 发布项目新版本 | release project |
191
- | `other` | 其他变更 | other changes |
192
-
193
- ### 配置示例
194
-
195
- #### 1. 追加自定义提交类型和范围
196
-
197
- ```ts
198
- // soybean.config.ts
199
- import { defineConfig } from '@soybeanjs/cli';
200
-
201
- export default defineConfig({
202
- lang: 'zh-cn', // 项目默认使用中文
203
-
151
+ lang: 'zh-cn',
152
+ cleanupDirs: ['**/dist', '**/.cache', '**/coverage', '**/node_modules', '!node_modules/**'],
204
153
  gitCommit: {
205
- // 追加自定义 types(在默认 types 基础上添加)
206
- types: [
207
- ['wip', '工作进行中'],
208
- ['merge', '合并分支'],
209
- ['i18n', '国际化相关']
210
- ],
211
-
212
- // 追加自定义 scopes
154
+ types: [['wip', '工作进行中']],
213
155
  scopes: [
214
156
  ['ui', 'UI 组件'],
215
- ['store', '状态管理'],
216
157
  ['api', 'API 接口']
217
158
  ]
218
159
  }
219
160
  });
220
161
  ```
221
162
 
222
- #### 2. 完全覆盖默认提交类型和范围
223
-
224
- ```ts
225
- // soybean.config.ts
226
- import { defineConfig } from '@soybeanjs/cli';
227
-
228
- export default defineConfig({
229
- gitCommit: {
230
- // 完全覆盖默认 types
231
- types: [
232
- ['feat', '新功能'],
233
- ['fix', '修复'],
234
- ['docs', '文档']
235
- ],
236
- typesAppend: false, // 不追加,完全覆盖
237
-
238
- // 完全覆盖默认 scopes
239
- scopes: [
240
- ['frontend', '前端'],
241
- ['backend', '后端'],
242
- ['shared', '共享代码']
243
- ],
244
- scopesAppend: false
245
- }
246
- });
247
- ```
248
-
249
- #### 3. 修改默认清理目录
250
-
251
- ```ts
252
- // soybean.config.ts
253
- import { defineConfig } from '@soybeanjs/cli';
254
-
255
- export default defineConfig({
256
- cleanupDirs: ['**/dist', '**/.cache', '**/coverage', '**/node_modules', '!node_modules/**']
257
- });
258
- ```
163
+ ### 配置项
259
164
 
260
- ### package.json 脚本配置示例
165
+ | 配置项 | 类型 | 说明 |
166
+ | ------------------------ | -------------------------- | ----------------------------------------------------------------- |
167
+ | `cwd` | `string` | 项目根目录,默认为 `process.cwd()`。 |
168
+ | `lang` | `'zh-cn' \| 'en-us'` | CLI 默认显示语言。 |
169
+ | `cleanupDirs` | `string[]` | `cleanup` 使用的 glob 规则。 |
170
+ | `ncuCommandArgs` | `string[]` | 传递给 npm-check-updates 的参数;设置后会覆盖自动生成的默认参数。 |
171
+ | `changelogOptions` | `Partial<ChangelogOption>` | 传递给 Changelog 生成器的选项。 |
172
+ | `gitCommitVerifyIgnores` | `RegExp[]` | 追加到默认忽略列表的提交信息校验规则。 |
173
+ | `gitCommit.types` | `[string, string][]` | 自定义提交类型;默认追加到内置类型。 |
174
+ | `gitCommit.typesAppend` | `boolean` | 设为 `false` 时,完全替换内置提交类型。 |
175
+ | `gitCommit.scopes` | `[string, string][]` | 自定义提交范围;默认追加到内置范围。 |
176
+ | `gitCommit.scopesAppend` | `boolean` | 设为 `false` 时,完全替换内置提交范围。 |
177
+
178
+ ### 推荐脚本
261
179
 
262
180
  ```json
263
181
  {
@@ -272,6 +190,18 @@ export default defineConfig({
272
190
  }
273
191
  ```
274
192
 
193
+ ## AI Skill
194
+
195
+ 本仓库提供 `soybean-cli` skill,帮助 AI 编程助手在 SoybeanJS 项目中正确使用 `soy` 命令处理提交、发布、Changelog、依赖升级和清理等日常任务。
196
+
197
+ 发布到 GitHub 后,通过以下命令安装:
198
+
199
+ ```bash
200
+ npx skills add soybeanjs/cli
201
+ ```
202
+
203
+ 安装时选择 `soybean-cli`。Skill 源码位于 [skills/soybean-cli](./skills/soybean-cli)。
204
+
275
205
  ## License
276
206
 
277
207
  [MIT](./LICENSE)
package/dist/index.d.ts CHANGED
@@ -95,6 +95,6 @@ interface CliOption {
95
95
  }
96
96
  //#endregion
97
97
  //#region src/index.d.ts
98
- declare function defineConfig(config?: Partial<CliOption>): Partial<CliOption> | undefined;
98
+ export declare function defineConfig(config?: Partial<CliOption>): Partial<CliOption> | undefined;
99
99
  //#endregion
100
- export { type CliOption, defineConfig };
100
+ export type { CliOption };
package/dist/index.js CHANGED
@@ -4,16 +4,16 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import process$1 from "node:process";
5
5
  import { loadConfig } from "c12";
6
6
  import { bgRed, green, red, yellow } from "kolorist";
7
- import path from "node:path";
7
+ import path, { join } from "node:path";
8
8
  import enquirer from "enquirer";
9
9
  import { rimraf } from "rimraf";
10
10
  import { existsSync as existsSync$1 } from "fs";
11
- import { join } from "path";
11
+ import { join as join$1 } from "path";
12
12
  import { generateChangelog, generateTotalChangelog } from "@soybeanjs/changelog";
13
13
  import { versionBump } from "bumpp";
14
14
  import { consola } from "consola";
15
15
  //#region package.json
16
- var version = "1.8.1";
16
+ var version = "1.8.3";
17
17
  //#endregion
18
18
  //#region src/locales/index.ts
19
19
  const locales = {
@@ -154,8 +154,10 @@ function deepMerge(target, source) {
154
154
  for (const key of Object.keys(source)) {
155
155
  const sourceVal = source[key];
156
156
  const targetVal = result[key];
157
- if (sourceVal !== void 0) if (isPlainObject(sourceVal) && isPlainObject(targetVal)) result[key] = deepMerge(targetVal, sourceVal);
158
- else result[key] = sourceVal;
157
+ if (sourceVal !== void 0) {
158
+ if (isPlainObject(sourceVal) && isPlainObject(targetVal)) result[key] = deepMerge(targetVal, sourceVal);
159
+ else result[key] = sourceVal;
160
+ }
159
161
  }
160
162
  return result;
161
163
  }
@@ -239,7 +241,8 @@ async function gitCommit(options = {}) {
239
241
  /** Git commit message verify */
240
242
  async function gitCommitVerify(lang = "en-us", ignores = []) {
241
243
  const gitPath = await execCommand("git", ["rev-parse", "--show-toplevel"]);
242
- const commitMsg = readFileSync(path.join(gitPath, ".git", "COMMIT_EDITMSG"), "utf8").trim();
244
+ const gitMsgPath = path.join(gitPath, ".git", "COMMIT_EDITMSG");
245
+ const commitMsg = readFileSync(gitMsgPath, "utf8").trim();
243
246
  if (ignores.some((regExp) => regExp.test(commitMsg))) return;
244
247
  if (!/(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(commitMsg)) {
245
248
  const errorMsg = locales[lang].gitCommitVerify;
@@ -253,13 +256,37 @@ async function cleanup(paths) {
253
256
  }
254
257
  //#endregion
255
258
  //#region src/command/ncu.ts
256
- async function ncu(args = ["-u", "-w"]) {
257
- await execCommand("pnpm", ["npm-check-updates", ...args], { stdio: "inherit" });
259
+ async function ncu(args) {
260
+ await execCommand("pnpm", ["npm-check-updates", ...args && args.length > 0 ? args : hasWorkspaces() ? ["-u", "-w"] : ["-u"]], { stdio: "inherit" });
261
+ }
262
+ /**
263
+ * Detect whether the current project is a workspace/monorepo.
264
+ *
265
+ * npm-check-updates' `-w` flag recognizes workspaces from either:
266
+ * 1. the `workspaces` field in package.json (npm/yarn format), or
267
+ * 2. the `packages` field in pnpm-workspace.yaml (pnpm format, used as
268
+ * fallback when `workspaces` is absent from package.json).
269
+ *
270
+ * Applying `-w` to a non-workspace project causes ncu to fail with:
271
+ * "workspaces property missing from package.json".
272
+ */
273
+ function hasWorkspaces(cwd = process$1.cwd()) {
274
+ const pkgPath = join(cwd, "package.json");
275
+ if (existsSync(pkgPath)) try {
276
+ if (JSON.parse(readFileSync(pkgPath, "utf8")).workspaces) return true;
277
+ } catch {}
278
+ const wsPath = join(cwd, "pnpm-workspace.yaml");
279
+ if (existsSync(wsPath)) try {
280
+ const content = readFileSync(wsPath, "utf8");
281
+ if (/^packages\s*:/m.test(content)) return true;
282
+ } catch {}
283
+ return false;
258
284
  }
259
285
  //#endregion
260
286
  //#region src/command/changelog.ts
261
287
  async function genChangelog(options, total = false) {
262
- const hasChangelog = existsSync$1(join(process.cwd(), "CHANGELOG.md"));
288
+ const changelogPath = join$1(process.cwd(), "CHANGELOG.md");
289
+ const hasChangelog = existsSync$1(changelogPath);
263
290
  if (total) await generateTotalChangelog(options);
264
291
  else await generateChangelog(options);
265
292
  if (!hasChangelog) await execCommand("git", ["add", "CHANGELOG.md"]);
@@ -290,7 +317,8 @@ function readGlobalConfig() {
290
317
  }
291
318
  }
292
319
  function writeGlobalConfig(config) {
293
- writeFileSync(getGlobalConfigPath(), JSON.stringify(config, null, 2), "utf8");
320
+ const filePath = getGlobalConfigPath();
321
+ writeFileSync(filePath, JSON.stringify(config, null, 2), "utf8");
294
322
  }
295
323
  async function configSet(options) {
296
324
  const config = readGlobalConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soybeanjs/cli",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "SoybeanJS's command line tools",
5
5
  "homepage": "https://github.com/soybeanjs/cli",
6
6
  "bugs": {
@@ -38,30 +38,30 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@soybeanjs/changelog": "^0.5.2",
41
- "bumpp": "^12.0.0",
41
+ "bumpp": "^12.3.0",
42
42
  "c12": "^3.3.4",
43
43
  "cac": "^7.0.0",
44
44
  "consola": "^3.4.2",
45
45
  "enquirer": "^2.4.1",
46
- "execa": "^10.0.0",
46
+ "execa": "^10.0.1",
47
47
  "kolorist": "^1.8.0",
48
- "npm-check-updates": "^22.2.9",
48
+ "npm-check-updates": "^23.1.0",
49
49
  "rimraf": "^6.1.3",
50
50
  "tinyglobby": "^0.2.17"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@soybeanjs/cli": "link:",
54
- "@soybeanjs/oxc-config": "^0.2.3",
55
- "@types/node": "^26.1.1",
56
- "tsx": "^4.23.1",
54
+ "@soybeanjs/oxc-config": "^0.2.6",
55
+ "@types/node": "^26.5.1",
56
+ "tsx": "^4.23.13",
57
57
  "typescript": "^7.0.2",
58
- "vite-plus": "0.2.6"
58
+ "vite-plus": "latest"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "vp pack",
62
62
  "commit": "soy git-commit",
63
63
  "fmt": "vp fmt",
64
- "lint": "vp lint",
64
+ "lint": "vp lint --fix",
65
65
  "publish-pkg": "pnpm -r publish --access public",
66
66
  "release": "soy release",
67
67
  "typecheck": "tsc --noEmit --skipLibCheck",