@mznjs/mbump 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 白鸢
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @vill-v/bumpp
2
+
3
+ 遵循 semver 规范进行 release 的工具包(暂时只针对个人使用,并没有开放过多的配置项)
4
+
5
+ 本包为
6
+ [bumpp](https://github.com/antfu/bumpp)
7
+
8
+ [changelogen](https://github.com/unjs/changelogen)
9
+ 的组合
10
+
11
+ 解决
12
+ - 使用 [bumpp](https://github.com/antfu/bumpp) 无法生成 CHANGELOG.md
13
+ - 使用 [changelogen](https://github.com/unjs/changelogen) 对 monorepo项目 无法进行有效的release
14
+
15
+ ## 简单使用
16
+
17
+ ```shell
18
+ vbumpp
19
+ ```
20
+ ## monorepo项目
21
+
22
+ ```shell
23
+ vbumpp -r
24
+ ```
25
+
26
+ ## 自定义bump文件
27
+
28
+ ```shell
29
+ vbumpp package.json packages/*/package.json
30
+ ```
31
+
32
+ ## ❤️ 鸣谢
33
+
34
+ [bumpp](https://github.com/antfu/bumpp)
35
+
36
+ [changelogen](https://github.com/unjs/changelogen)
37
+
38
+
39
+ ## License
40
+
41
+ [MIT](https://gitee.com/vill-v/bump/blob/main/LICENSE)
package/bin/index.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { createCli } from '../dist/cli.js'
3
+
4
+ createCli()
@@ -0,0 +1,196 @@
1
+ import { ProgressEvent, loadBumpConfig, versionBump, versionBumpInfo } from "bumpp";
2
+ import { consola } from "consola";
3
+ import { oraPromise } from "ora";
4
+ import { existsSync } from "node:fs";
5
+ import { readFile, writeFile } from "node:fs/promises";
6
+ import { generateMarkDown, getGitDiff, getLastGitTag, loadChangelogConfig, parseCommits } from "changelogen";
7
+ import { x } from "tinyexec";
8
+ import { defu } from "defu";
9
+ import { loadConfig, presetMini } from "esconf";
10
+ import { glob } from "tinyglobby";
11
+
12
+ //#region src/changelog.ts
13
+ /**
14
+ * 获取远程仓库的最新tag
15
+ * @returns
16
+ */
17
+ async function getTag() {
18
+ try {
19
+ return await getLastGitTag();
20
+ } catch (_e) {
21
+ return "";
22
+ }
23
+ }
24
+ /**
25
+ * 生成changelog
26
+ * @param rawConfig
27
+ */
28
+ async function changelog(rawConfig) {
29
+ const config = {
30
+ ...rawConfig,
31
+ newVersion: rawConfig.to,
32
+ to: `v${rawConfig.to}`,
33
+ from: `v${rawConfig.from}`
34
+ };
35
+ const rawCommits = await getGitDiff(config.from);
36
+ const commits = parseCommits(rawCommits, config).filter((c) => config.types[c.type] && !(c.type === "chore" && c.scope === "deps" && !c.isBreaking));
37
+ let markdown = await generateMarkDown(commits, config);
38
+ markdown = markdown.replace("#### ⚠️ Breaking Changes", `#### ${config.types.BreakingChange.title}`).replace("### ❤️ Contributors", "### ❤️ 贡献者");
39
+ let changelogMD;
40
+ if (existsSync(config.output)) changelogMD = await readFile(config.output, "utf8");
41
+ else changelogMD = "# Changelog\n\n";
42
+ const lastEntry = changelogMD.match(/^###?\s+.*$/m);
43
+ if (lastEntry) changelogMD = `${changelogMD.slice(0, lastEntry.index) + markdown}\n\n${changelogMD.slice(lastEntry.index)}`;
44
+ else changelogMD += `\n${markdown}\n\n`;
45
+ await writeFile(config.output, changelogMD);
46
+ await x("git", [
47
+ "add",
48
+ config.output,
49
+ "package.json"
50
+ ]);
51
+ await x("git", [
52
+ "commit",
53
+ "-m",
54
+ `chore: update ${config.output}`
55
+ ]);
56
+ return {
57
+ markdown,
58
+ changelogMD
59
+ };
60
+ }
61
+
62
+ //#endregion
63
+ //#region src/config.ts
64
+ function getDefaultsChangeLogConfig() {
65
+ return { types: {
66
+ feat: { title: "🚀 特性" },
67
+ perf: { title: "🔥 性能优化" },
68
+ fix: { title: "🩹 修复" },
69
+ refactor: { title: "💅 重构" },
70
+ examples: { title: "🏀 示例" },
71
+ docs: { title: "📖 文档" },
72
+ chore: { title: "🏡 框架" },
73
+ build: { title: "📦 打包" },
74
+ test: { title: "✅ 测试" },
75
+ BreakingChange: { title: "🚨 破坏性改动" },
76
+ style: { title: "🎨 样式" }
77
+ } };
78
+ }
79
+ /**
80
+ * 合并配置项
81
+ * @param rawConfig
82
+ */
83
+ async function resolveConfig(rawConfig) {
84
+ const cwd = process.cwd();
85
+ const changelog$1 = await loadChangelogConfig(cwd, getDefaultsChangeLogConfig());
86
+ const bumpp = await loadBumpConfig({
87
+ cwd,
88
+ files: ["package.json", "package-lock.json"],
89
+ commit: true,
90
+ tag: true,
91
+ push: true,
92
+ confirm: false,
93
+ ignoreScripts: false,
94
+ noVerify: false
95
+ });
96
+ const { config } = await loadConfig({ presets: [presetMini({
97
+ name: "mbump",
98
+ configName: "config",
99
+ rcFile: true,
100
+ globalRc: true
101
+ })] });
102
+ const _resolveConfig = defu(rawConfig, config, {
103
+ changelog: changelog$1,
104
+ bumpp,
105
+ accesstoken: {}
106
+ });
107
+ if (rawConfig.bumpp?.recursive) {
108
+ const files = await glob("**/package.json", {
109
+ ignore: ["**/node_modules/**"],
110
+ cwd,
111
+ onlyFiles: true
112
+ });
113
+ files.forEach((item) => {
114
+ _resolveConfig.bumpp.files.push(item);
115
+ });
116
+ }
117
+ _resolveConfig.bumpp.recursive = false;
118
+ _resolveConfig.bumpp.files = [...new Set(_resolveConfig.bumpp.files)];
119
+ return _resolveConfig;
120
+ }
121
+ const defineConfig = (config) => config;
122
+
123
+ //#endregion
124
+ //#region src/bump.ts
125
+ /**
126
+ * antfu/bumpp progress
127
+ */
128
+ function progress({ event, script, updatedFiles, skippedFiles, newVersion }) {
129
+ switch (event) {
130
+ case ProgressEvent.FileUpdated:
131
+ consola.success(`Updated ${updatedFiles.pop()} to ${newVersion}`);
132
+ break;
133
+ case ProgressEvent.FileSkipped:
134
+ consola.info(`${skippedFiles.pop()} did not need to be updated`);
135
+ break;
136
+ case ProgressEvent.GitCommit:
137
+ consola.info("Git commit");
138
+ break;
139
+ case ProgressEvent.GitTag:
140
+ consola.info("Git tag");
141
+ break;
142
+ case ProgressEvent.GitPush:
143
+ consola.success("Git push");
144
+ break;
145
+ case ProgressEvent.NpmScript:
146
+ consola.success(`Npm run ${script}`);
147
+ break;
148
+ }
149
+ }
150
+ /**
151
+ * 更新版本
152
+ * @param option
153
+ */
154
+ async function bumpVersion(option = {}) {
155
+ const config = await resolveConfig(option);
156
+ const currentTag = await getTag();
157
+ const { state } = await versionBumpInfo();
158
+ const res = { config };
159
+ res.bumpp = state;
160
+ if (currentTag) res.changelog = await oraPromise(changelog({
161
+ ...config.changelog,
162
+ to: state.newVersion,
163
+ from: state.currentVersion
164
+ }), {
165
+ text: "changelog",
166
+ successText: `Update ${config.changelog.output} success`,
167
+ failText: `Update ${config.changelog.output} success`
168
+ });
169
+ await versionBump({
170
+ ...config.bumpp,
171
+ progress,
172
+ release: state.newVersion
173
+ });
174
+ return res;
175
+ }
176
+ /**
177
+ * 更新版本伴随基础 release 基础等待动画
178
+ * @param option 更新版本配置
179
+ * @param addRelease release脚本
180
+ * @param provider git 远程储存提供商
181
+ */
182
+ async function bumpVersionWithBaseRelease(option = {}, addRelease, provider) {
183
+ const { bumpp, changelog: changelog$1, config } = await bumpVersion(option);
184
+ await oraPromise(addRelease({
185
+ bumpp,
186
+ changelog: changelog$1,
187
+ config
188
+ }), {
189
+ text: `${provider} Release`,
190
+ successText: ` [${provider}] add release v${bumpp.newVersion} success`,
191
+ failText: `[${provider}] add release v${bumpp.newVersion} fail`
192
+ });
193
+ }
194
+
195
+ //#endregion
196
+ export { bumpVersion, bumpVersionWithBaseRelease, defineConfig };
@@ -0,0 +1 @@
1
+ export * from "changelogen"
@@ -0,0 +1 @@
1
+ export * from "changelogen"
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Config } from "./types.d-B0g2i1Ge.js";
2
+
3
+ //#region src/cli.d.ts
4
+ declare function createBaseCli(bumpVersion: (config?: Config) => Promise<any>, version?: string): void;
5
+ declare const createCli: () => void;
6
+
7
+ //#endregion
8
+ export { createBaseCli, createCli };
package/dist/cli.js ADDED
@@ -0,0 +1,23 @@
1
+ import { bumpVersion } from "./bump-CtknNhb9.js";
2
+ import { cac } from "cac";
3
+
4
+ //#region src/cli.ts
5
+ function createBaseCli(bumpVersion$1, version) {
6
+ const $cac = cac("mbump");
7
+ $cac.command("[...files]").option("-o,--output [output]", "CHANGELOG.md 生成位置", { default: "CHANGELOG.md" }).option("-r,--recursive", "recursively", { default: false }).action(async (files, options) => {
8
+ await bumpVersion$1({
9
+ bumpp: {
10
+ files,
11
+ recursive: options.recursive
12
+ },
13
+ changelog: { output: options.output }
14
+ });
15
+ });
16
+ $cac.version(version || "1.0.1");
17
+ $cac.help();
18
+ $cac.parse();
19
+ }
20
+ const createCli = () => createBaseCli(bumpVersion);
21
+
22
+ //#endregion
23
+ export { createBaseCli, createCli };
@@ -0,0 +1,22 @@
1
+ import { Accesstokens, BumpVersion, BumppResult, ChangelogOptions, ChangelogResult, Config, ResolveConfig } from "./types.d-B0g2i1Ge.js";
2
+
3
+ //#region src/bump.d.ts
4
+ /**
5
+ * 更新版本
6
+ * @param option
7
+ */
8
+ declare function bumpVersion(option?: Config): Promise<BumpVersion>;
9
+ /**
10
+ * 更新版本伴随基础 release 基础等待动画
11
+ * @param option 更新版本配置
12
+ * @param addRelease release脚本
13
+ * @param provider git 远程储存提供商
14
+ */
15
+ declare function bumpVersionWithBaseRelease(option: Config | undefined, addRelease: (res: BumpVersion) => Promise<any>, provider: string): Promise<void>;
16
+
17
+ //#endregion
18
+ //#region src/config.d.ts
19
+ declare const defineConfig: (config: Config) => Config;
20
+
21
+ //#endregion
22
+ export { Accesstokens, BumpVersion, BumppResult, ChangelogOptions, ChangelogResult, Config, ResolveConfig, bumpVersion, bumpVersionWithBaseRelease, defineConfig };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { bumpVersion, bumpVersionWithBaseRelease, defineConfig } from "./bump-CtknNhb9.js";
2
+
3
+ export { bumpVersion, bumpVersionWithBaseRelease, defineConfig };
@@ -0,0 +1,76 @@
1
+ import { VersionBumpOptions, versionBumpInfo } from "bumpp";
2
+ import { ChangelogConfig, ResolvedChangelogConfig } from "changelogen";
3
+
4
+ //#region src/changelog.d.ts
5
+ /**
6
+ * 生成changelog
7
+ * @param rawConfig
8
+ */
9
+ declare function changelog(rawConfig: ResolvedChangelogConfig): Promise<{
10
+ markdown: string;
11
+ changelogMD: string;
12
+ }>;
13
+
14
+ //#endregion
15
+ //#region src/types.d.ts
16
+ /**
17
+ * changelog 生成配置信息
18
+ */
19
+ interface ChangelogOptions extends Omit<Partial<ChangelogConfig>, 'cwd' | 'tokens' | 'newVersion' | 'to' | 'from' | 'publish'> {
20
+ }
21
+ interface Accesstokens {
22
+ [key: string]: string;
23
+ }
24
+ /**
25
+ * 用户配置信息
26
+ */
27
+ interface Config {
28
+ /**
29
+ * changelog 生成配置信息
30
+ */
31
+ changelog?: ChangelogOptions;
32
+ /**
33
+ * bumpp 配置信息
34
+ */
35
+ bumpp?: Omit<VersionBumpOptions, 'progress' | 'cwd'>;
36
+ accesstoken?: Accesstokens;
37
+ }
38
+ /**
39
+ * 合并后的配置信息
40
+ */
41
+ interface ResolveConfig {
42
+ /**
43
+ * changelog 生成配置信息
44
+ */
45
+ changelog: ResolvedChangelogConfig;
46
+ /**
47
+ * bumpp 配置信息
48
+ */
49
+ bumpp: Omit<VersionBumpOptions, 'progress'>;
50
+ accesstoken: Accesstokens;
51
+ }
52
+ /**
53
+ * bumpp 生成结果
54
+ */
55
+ type BumppResult = Awaited<ReturnType<typeof versionBumpInfo>>;
56
+ /**
57
+ * changelog 生成结果
58
+ */
59
+ type ChangelogResult = Awaited<ReturnType<typeof changelog>>;
60
+ /**
61
+ * bumppVersion 方法返回结果
62
+ */
63
+ interface BumpVersion {
64
+ /**
65
+ * bumpp 生成结果
66
+ */
67
+ bumpp: BumppResult['state'];
68
+ /**
69
+ * changelog 生成结果
70
+ */
71
+ changelog: ChangelogResult;
72
+ config: ResolveConfig;
73
+ }
74
+
75
+ //#endregion
76
+ export { Accesstokens, BumpVersion, BumppResult, ChangelogOptions, ChangelogResult, Config, ResolveConfig };
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@mznjs/mbump",
3
+ "version": "1.0.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "bin": {
7
+ "mbump": "bin/index.js"
8
+ },
9
+ "engines": {
10
+ "node": ">=18"
11
+ },
12
+ "author": {
13
+ "name": "whitekite",
14
+ "email": "1075790909@qq.com"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://gitee.com/vill-v/bump",
19
+ "directory": "packages/bump"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "bin"
24
+ ],
25
+ "main": "dist/index.js",
26
+ "module": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "import": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ }
34
+ },
35
+ "./changelogen": {
36
+ "import": {
37
+ "types": "./dist/changelogens.d.ts",
38
+ "default": "./dist/changelogens.js"
39
+ }
40
+ },
41
+ "./cli": {
42
+ "import": {
43
+ "types": "./dist/cli.d.ts",
44
+ "default": "./dist/cli.js"
45
+ }
46
+ }
47
+ },
48
+ "dependencies": {
49
+ "bumpp": "^10.1.0",
50
+ "cac": "^6.7.14",
51
+ "changelogen": "^0.6.1",
52
+ "consola": "^3.4.2",
53
+ "defu": "^6.1.4",
54
+ "esconf": "~0.5.1",
55
+ "ora": "^8.2.0",
56
+ "tinyexec": "^1.0.1",
57
+ "tinyglobby": "^0.2.13"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "scripts": {
63
+ "build": "tsdown",
64
+ "release": "pnpm publish --access public"
65
+ }
66
+ }