fork-version 4.1.10 → 5.0.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 +11 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +54 -193
- package/dist/commands/inspect.d.ts +9 -0
- package/dist/commands/inspect.js +41 -0
- package/dist/commands/main.d.ts +16 -0
- package/dist/commands/main.js +30 -0
- package/dist/commands/validate-config.d.ts +6 -0
- package/dist/commands/validate-config.js +11 -0
- package/dist/commit-parser/commit-parser.d.ts +114 -0
- package/dist/commit-parser/commit-parser.js +327 -0
- package/dist/commit-parser/filter-reverted-commits.d.ts +17 -0
- package/dist/commit-parser/filter-reverted-commits.js +34 -0
- package/dist/commit-parser/options.d.ts +74 -0
- package/dist/commit-parser/options.js +70 -0
- package/dist/commit-parser/parser-error.js +14 -0
- package/dist/commit-parser/types.d.ts +53 -0
- package/dist/config/changelog-preset-config.js +41 -0
- package/dist/config/cli-arguments.d.ts +109 -0
- package/dist/config/cli-arguments.js +141 -0
- package/dist/config/defaults.js +38 -0
- package/dist/config/define-config.d.ts +9 -0
- package/dist/config/define-config.js +9 -0
- package/dist/config/load-config.js +45 -0
- package/dist/config/merge-files.js +12 -0
- package/dist/config/schema.d.ts +50 -0
- package/dist/config/schema.js +61 -0
- package/dist/config/types.d.ts +279 -0
- package/dist/config/user-config.d.ts +6 -0
- package/dist/config/user-config.js +50 -0
- package/dist/detect-git-host/detect-git-host.js +35 -0
- package/dist/detect-git-host/host-azure-devops.js +28 -0
- package/dist/detect-git-host/host-bitbucket.js +28 -0
- package/dist/detect-git-host/host-github.js +32 -0
- package/dist/detect-git-host/host-gitlab.js +48 -0
- package/dist/files/arm-bicep.js +44 -0
- package/dist/files/file-manager.d.ts +47 -0
- package/dist/files/file-manager.js +65 -0
- package/dist/files/install-shield-ism.js +59 -0
- package/dist/files/json-package.js +68 -0
- package/dist/files/ms-build-project.js +59 -0
- package/dist/files/plain-text.js +35 -0
- package/dist/files/yaml-package.js +61 -0
- package/dist/index.d.ts +21 -655
- package/dist/index.js +19 -10
- package/dist/process/changelog.d.ts +7 -0
- package/dist/process/changelog.js +69 -0
- package/dist/process/commit.d.ts +9 -0
- package/dist/process/commit.js +22 -0
- package/dist/process/get-commits.d.ts +14 -0
- package/dist/process/get-commits.js +25 -0
- package/dist/process/get-current-version.d.ts +13 -0
- package/dist/process/get-current-version.js +35 -0
- package/dist/process/get-next-version.d.ts +21 -0
- package/dist/process/get-next-version.js +72 -0
- package/dist/process/tag.d.ts +8 -0
- package/dist/process/tag.js +15 -0
- package/dist/services/git.d.ts +141 -0
- package/dist/services/git.js +236 -0
- package/dist/services/logger.d.ts +18 -0
- package/dist/services/logger.js +35 -0
- package/dist/utils/clean-tag.js +21 -0
- package/dist/utils/escape-regex.js +17 -0
- package/dist/utils/file-state.js +19 -0
- package/dist/utils/format-commit-message.js +13 -0
- package/dist/utils/parse-regexp-string.js +31 -0
- package/dist/utils/release-type.js +47 -0
- package/dist/utils/trim-string-array.js +20 -0
- package/package.json +11 -29
- package/dist/chunk-33WIJWQZ.cjs +0 -2306
- package/dist/chunk-33WIJWQZ.cjs.map +0 -1
- package/dist/chunk-L5UDUEHE.js +0 -2262
- package/dist/chunk-L5UDUEHE.js.map +0 -1
- package/dist/cli.cjs +0 -205
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/index.cjs +0 -80
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -655
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { escapeRegex } from "../utils/escape-regex.js";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
//#region src/services/git.ts
|
|
5
|
+
var Git = class {
|
|
6
|
+
#path;
|
|
7
|
+
#dryRun;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.#path = config.path;
|
|
10
|
+
this.#dryRun = config.dryRun ?? false;
|
|
11
|
+
this.add = this.add.bind(this);
|
|
12
|
+
this.commit = this.commit.bind(this);
|
|
13
|
+
this.tag = this.tag.bind(this);
|
|
14
|
+
this.log = this.log.bind(this);
|
|
15
|
+
this.isIgnored = this.isIgnored.bind(this);
|
|
16
|
+
this.getBranchName = this.getBranchName.bind(this);
|
|
17
|
+
this.getRemoteUrl = this.getRemoteUrl.bind(this);
|
|
18
|
+
this.getTags = this.getTags.bind(this);
|
|
19
|
+
this.getMostRecentTag = this.getMostRecentTag.bind(this);
|
|
20
|
+
this.getCommits = this.getCommits.bind(this);
|
|
21
|
+
}
|
|
22
|
+
async #execGit(command, args) {
|
|
23
|
+
return new Promise((onResolve, onReject) => {
|
|
24
|
+
execFile("git", [command, ...args], {
|
|
25
|
+
cwd: this.#path,
|
|
26
|
+
maxBuffer: Infinity
|
|
27
|
+
}, (error, stdout, stderr) => {
|
|
28
|
+
if (error) onReject(error);
|
|
29
|
+
else onResolve(stdout ? stdout : stderr);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Add file contents to the index
|
|
35
|
+
*
|
|
36
|
+
* [git-add Documentation](https://git-scm.com/docs/git-add)
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* await git.add("CHANGELOG.md");
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async add(...args) {
|
|
44
|
+
if (this.#dryRun) return "";
|
|
45
|
+
return this.#execGit("add", args.filter(Boolean));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Record changes to the repository
|
|
49
|
+
*
|
|
50
|
+
* [git-commit Documentation](https://git-scm.com/docs/git-commit)
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* await git.commit("--message", "chore(release): 1.2.3");
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async commit(...args) {
|
|
58
|
+
if (this.#dryRun) return "";
|
|
59
|
+
return this.#execGit("commit", args.filter(Boolean));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create, list, delete or verify a tag object
|
|
63
|
+
*
|
|
64
|
+
* [git-tag Documentation](https://git-scm.com/docs/git-tag)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* await git.tag("--annotate", "v1.2.3", "--message", "chore(release): 1.2.3");
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
async tag(...args) {
|
|
72
|
+
if (this.#dryRun) return "";
|
|
73
|
+
return this.#execGit("tag", args.filter(Boolean));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Show commit logs
|
|
77
|
+
*
|
|
78
|
+
* - [git-log Documentation](https://git-scm.com/docs/git-log)
|
|
79
|
+
* - [pretty-formats Documentation](https://git-scm.com/docs/pretty-formats)
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* await git.log("--oneline");
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async log(...args) {
|
|
87
|
+
try {
|
|
88
|
+
return await this.#execGit("log", args.filter(Boolean));
|
|
89
|
+
} catch {
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if a file is ignored by git
|
|
95
|
+
*
|
|
96
|
+
* [git-check-ignore Documentation](https://git-scm.com/docs/git-check-ignore)
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* await git.isIgnored("src/my-file.txt");
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
async isIgnored(file) {
|
|
104
|
+
try {
|
|
105
|
+
await this.#execGit("check-ignore", ["--no-index", file]);
|
|
106
|
+
return true;
|
|
107
|
+
} catch (_error) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the name of the current branch
|
|
113
|
+
*
|
|
114
|
+
* [git-rev-parse Documentation](https://git-scm.com/docs/git-rev-parse)
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* await git.getBranchName(); // "main"
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
async getBranchName() {
|
|
122
|
+
try {
|
|
123
|
+
return (await this.#execGit("rev-parse", ["--abbrev-ref", "HEAD"])).trim();
|
|
124
|
+
} catch {
|
|
125
|
+
return "";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the URL of the remote repository
|
|
130
|
+
*
|
|
131
|
+
* [git-config Documentation](https://git-scm.com/docs/git-config)
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* await git.getRemoteUrl(); // "https://github.com/eglavin/fork-version"
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async getRemoteUrl() {
|
|
139
|
+
try {
|
|
140
|
+
return (await this.#execGit("config", ["--get", "remote.origin.url"])).trim();
|
|
141
|
+
} catch (_error) {
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* `getTags` returns valid semver version tags in order of the commit history
|
|
147
|
+
*
|
|
148
|
+
* Using `git log` to get the commit history, we then parse the tags from the
|
|
149
|
+
* commit details which is expected to be in the following format:
|
|
150
|
+
* ```txt
|
|
151
|
+
* commit 3841b1d05750d42197fe958e3d8e06df378a842d (HEAD -> main, tag: v1.0.2, tag: v1.0.1, tag: v1.0.0)
|
|
152
|
+
* Author: Username <username@example.com>
|
|
153
|
+
* Date: Sat Nov 9 15:00:00 2024 +0000
|
|
154
|
+
*
|
|
155
|
+
* chore(release): v1.0.0
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* - [Functionality extracted from the conventional-changelog - git-semver-tags project](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/index.js)
|
|
159
|
+
* - [conventional-changelog git-semver-tags MIT Licence](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/LICENSE.md)
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* await git.getTags("v"); // ["v1.0.2", "v1.0.1", "v1.0.0"]
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
async getTags(tagPrefix) {
|
|
167
|
+
const logOutput = await this.log("--decorate", "--no-color", "--date-order");
|
|
168
|
+
/**
|
|
169
|
+
* Search for tags in the following formats:
|
|
170
|
+
* @example "tag: 1.2.3," or "tag: 1.2.3)"
|
|
171
|
+
*/
|
|
172
|
+
const TAG_REGEX = /tag:\s*(?<tag>.+?)[,)]/gi;
|
|
173
|
+
const tags = [];
|
|
174
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
175
|
+
let tagMatch = null;
|
|
176
|
+
while (tagMatch = TAG_REGEX.exec(logOutput)) {
|
|
177
|
+
const { tag = "" } = tagMatch.groups ?? {};
|
|
178
|
+
if (tagPrefix) {
|
|
179
|
+
if (tag.startsWith(tagPrefix)) {
|
|
180
|
+
const tagWithoutPrefix = tag.replace(new RegExp(`^${escapedTagPrefix}`), "");
|
|
181
|
+
if (semver.valid(tagWithoutPrefix)) tags.push(tag);
|
|
182
|
+
}
|
|
183
|
+
} else if (/^\d/.test(tag) && semver.valid(tag)) tags.push(tag);
|
|
184
|
+
}
|
|
185
|
+
return tags;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns the most recent tag from the commit history, or `undefined` if no valid semver tags are found
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* await git.getMostRecentTag("v"); // "1.2.3"
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
async getMostRecentTag(tagPrefix) {
|
|
196
|
+
return (await this.getTags(tagPrefix))[0] || void 0;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get commit history in a parsable format
|
|
200
|
+
*
|
|
201
|
+
* An array of strings with commit details is returned in the following format:
|
|
202
|
+
* ```txt
|
|
203
|
+
* subject
|
|
204
|
+
* body
|
|
205
|
+
* hash
|
|
206
|
+
* committer date
|
|
207
|
+
* committer name
|
|
208
|
+
* committer email
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* await git.getCommits("v1.0.0", "HEAD", "src/utils");
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
async getCommits(from = "", to = "HEAD", ...paths) {
|
|
217
|
+
const SCISSOR = "^----------- FORK VERSION -----------^";
|
|
218
|
+
const LOG_FORMAT = [
|
|
219
|
+
"%s",
|
|
220
|
+
"%b",
|
|
221
|
+
"%H",
|
|
222
|
+
"%d",
|
|
223
|
+
"%cI",
|
|
224
|
+
"%cN",
|
|
225
|
+
"%cE",
|
|
226
|
+
SCISSOR
|
|
227
|
+
].join("%n");
|
|
228
|
+
const splitCommits = (await this.log(`--format=${LOG_FORMAT}`, [from, to].filter(Boolean).join(".."), paths.length ? "--" : "", ...paths)).split(`\n${SCISSOR}\n`);
|
|
229
|
+
if (splitCommits.length === 0) return splitCommits;
|
|
230
|
+
if (splitCommits[0] === SCISSOR) splitCommits.shift();
|
|
231
|
+
if (splitCommits[splitCommits.length - 1] === "") splitCommits.pop();
|
|
232
|
+
return splitCommits;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
export { Git };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ForkConfig } from "../config/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/services/logger.d.ts
|
|
4
|
+
interface LoggerConfig {
|
|
5
|
+
silent?: ForkConfig["silent"];
|
|
6
|
+
debug?: ForkConfig["debug"];
|
|
7
|
+
}
|
|
8
|
+
declare class Logger {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(config: LoggerConfig);
|
|
11
|
+
log(message: string): void;
|
|
12
|
+
warn(message: string): void;
|
|
13
|
+
error(message: string): void;
|
|
14
|
+
debug(message: string, ...optionalParams: any[]): void;
|
|
15
|
+
skipping(message: string): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Logger };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
//#region src/services/logger.ts
|
|
3
|
+
var Logger = class {
|
|
4
|
+
#silent;
|
|
5
|
+
#debug;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.#silent = config.silent ?? false;
|
|
8
|
+
this.#debug = config.debug ?? false;
|
|
9
|
+
this.log = this.log.bind(this);
|
|
10
|
+
this.warn = this.warn.bind(this);
|
|
11
|
+
this.error = this.error.bind(this);
|
|
12
|
+
this.debug = this.debug.bind(this);
|
|
13
|
+
this.skipping = this.skipping.bind(this);
|
|
14
|
+
}
|
|
15
|
+
log(message) {
|
|
16
|
+
if (!this.#silent) console.log(message);
|
|
17
|
+
}
|
|
18
|
+
warn(message) {
|
|
19
|
+
if (!this.#silent) console.warn(styleText("yellowBright", message));
|
|
20
|
+
}
|
|
21
|
+
error(message) {
|
|
22
|
+
if (!this.#silent) console.error(styleText("redBright", message));
|
|
23
|
+
}
|
|
24
|
+
debug(message, ...optionalParams) {
|
|
25
|
+
if (!this.#silent && this.#debug) {
|
|
26
|
+
console.debug(styleText("cyanBright", message));
|
|
27
|
+
if (optionalParams.length > 0) console.debug(...optionalParams);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
skipping(message) {
|
|
31
|
+
if (!this.#silent) console.log(styleText("magenta", message));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Logger };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { escapeRegex } from "./escape-regex.js";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
//#region src/utils/clean-tag.ts
|
|
4
|
+
/**
|
|
5
|
+
* Cleans a git tag by removing the specified prefix and ensuring it's a valid semver version.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* cleanTag("v1.2.3", "v"); // "1.2.3"
|
|
10
|
+
* cleanTag("release-2.0.0", "release-"); // "2.0.0"
|
|
11
|
+
* cleanTag("1.0.0"); // "1.0.0"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function cleanTag(tag, tagPrefix) {
|
|
15
|
+
if (!tag) return void 0;
|
|
16
|
+
const escapedTagPrefix = tagPrefix ? escapeRegex(tagPrefix) : void 0;
|
|
17
|
+
const tagWithoutPrefix = escapedTagPrefix ? tag.replace(new RegExp(`^${escapedTagPrefix}`), "") : tag;
|
|
18
|
+
return semver.clean(tagWithoutPrefix) ?? void 0;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { cleanTag };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/utils/escape-regex.ts
|
|
2
|
+
/**
|
|
3
|
+
* Escapes special characters in a string for use in a regular expression.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* escapeRegex("Hello. How are you?"); // "Hello\. How are you\?"
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param input The string to be escaped for use in a regular expression.
|
|
11
|
+
* @returns The escaped string, safe for use in a regular expression.
|
|
12
|
+
*/
|
|
13
|
+
function escapeRegex(input) {
|
|
14
|
+
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { escapeRegex };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { lstatSync } from "node:fs";
|
|
2
|
+
//#region src/utils/file-state.ts
|
|
3
|
+
/**
|
|
4
|
+
* Determine if a file exists.
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* fileExists("~/.bashrc"); // true
|
|
8
|
+
* fileExists("~/missing-file.txt"); // false
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
function fileExists(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
return lstatSync(filePath).isFile();
|
|
14
|
+
} catch (_error) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { fileExists };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/utils/format-commit-message.ts
|
|
2
|
+
/**
|
|
3
|
+
* Formats the commit message by replacing the `{{currentTag}}` placeholder
|
|
4
|
+
* globally with the new version.
|
|
5
|
+
*
|
|
6
|
+
* Falls back to `chore(release): {{currentTag}}` if message is argument is falsy.
|
|
7
|
+
*/
|
|
8
|
+
function formatCommitMessage(message, version) {
|
|
9
|
+
if (!message) message = "chore(release): {{currentTag}}";
|
|
10
|
+
return message.replace(/* @__PURE__ */ new RegExp("{{currentTag}}", "g"), version);
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { formatCommitMessage };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/utils/parse-regexp-string.ts
|
|
2
|
+
/**
|
|
3
|
+
* Parses a string into a RegExp object. If the string is in the form of a regular expression literal
|
|
4
|
+
* (e.g., "/pattern/flags"), it will be parsed accordingly. Otherwise, it will be treated as a
|
|
5
|
+
* plain string pattern.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* parseRegExpString("/abc/i"); // returns a valid RegExp object with pattern "abc" and flag "i"
|
|
10
|
+
* parseRegExpString("abc"); // returns a RegExp object with pattern "abc" and no flags
|
|
11
|
+
* parseRegExpString("[unclosed"); // returns null due to invalid regex
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param input The string to parse into a RegExp object.
|
|
15
|
+
* @returns A RegExp object if parsing is successful, or null if the input is invalid.
|
|
16
|
+
*/
|
|
17
|
+
function parseRegExpString(input) {
|
|
18
|
+
const literal = /^\/(.+)\/([a-z]*)$/i.exec(input);
|
|
19
|
+
if (literal) try {
|
|
20
|
+
return new RegExp(literal[1], literal[2]);
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return new RegExp(input);
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { parseRegExpString };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
//#region src/utils/release-type.ts
|
|
3
|
+
/**
|
|
4
|
+
* Get the priority of given type.
|
|
5
|
+
* @example
|
|
6
|
+
* - "patch" => 0
|
|
7
|
+
* - "minor" => 1
|
|
8
|
+
* - "major" => 2
|
|
9
|
+
*/
|
|
10
|
+
function getPriority(type) {
|
|
11
|
+
return [
|
|
12
|
+
"patch",
|
|
13
|
+
"minor",
|
|
14
|
+
"major"
|
|
15
|
+
].indexOf(type ?? "");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the given versions highest state.
|
|
19
|
+
* @example
|
|
20
|
+
* - "patch"
|
|
21
|
+
* - "minor"
|
|
22
|
+
* - "major"
|
|
23
|
+
*/
|
|
24
|
+
function getVersionType(version) {
|
|
25
|
+
const parseVersion = semver.parse(version);
|
|
26
|
+
if (parseVersion?.major) return "major";
|
|
27
|
+
else if (parseVersion?.minor) return "minor";
|
|
28
|
+
else if (parseVersion?.patch) return "patch";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the recommended release type for the given version depending on if
|
|
32
|
+
* the user asks for a prerelease with or without a tag.
|
|
33
|
+
* ```js
|
|
34
|
+
* getReleaseType("patch", "1.0.0", false) => "patch"
|
|
35
|
+
* getReleaseType("major", "0.0.0-beta", "beta") => "premajor"
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
39
|
+
if (!preReleaseTag) return releaseType;
|
|
40
|
+
if (Array.isArray(semver.prerelease(currentVersion))) {
|
|
41
|
+
const currentReleaseType = getVersionType(currentVersion);
|
|
42
|
+
if (currentReleaseType === releaseType || getPriority(currentReleaseType) > getPriority(releaseType)) return "prerelease";
|
|
43
|
+
}
|
|
44
|
+
return `pre${releaseType}`;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { getReleaseType };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/utils/trim-string-array.ts
|
|
2
|
+
/**
|
|
3
|
+
* Trims whitespace from each string in the provided array and optionally applies a transformation function to each item.
|
|
4
|
+
* If the resulting array is empty after trimming, it returns undefined.
|
|
5
|
+
*
|
|
6
|
+
* @param array The array of strings to be trimmed and transformed.
|
|
7
|
+
* @param transformFn Optional function to apply to each trimmed item (e.g., for escaping regex characters).
|
|
8
|
+
* @returns A new array of trimmed (and optionally transformed) strings, or undefined if the resulting array is empty.
|
|
9
|
+
*/
|
|
10
|
+
function trimStringArray(array, transformFn) {
|
|
11
|
+
const items = [];
|
|
12
|
+
if (Array.isArray(array)) for (const item of array) {
|
|
13
|
+
const _item = item.trim();
|
|
14
|
+
if (_item) items.push(transformFn ? transformFn(_item) : _item);
|
|
15
|
+
}
|
|
16
|
+
if (items.length === 0) return;
|
|
17
|
+
return items;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { trimStringArray };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fork-version",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Fork-Version automates version control tasks such as determining, updating, and committing versions, files, and changelogs, simplifying the process when adhering to the conventional commit standard.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,30 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"private": false,
|
|
37
37
|
"type": "module",
|
|
38
|
-
"main": "dist/index.cjs",
|
|
39
|
-
"module": "dist/index.js",
|
|
40
38
|
"types": "dist/index.d.ts",
|
|
41
39
|
"exports": {
|
|
42
|
-
".":
|
|
43
|
-
|
|
44
|
-
"types": "./dist/index.d.ts",
|
|
45
|
-
"default": "./dist/index.js"
|
|
46
|
-
},
|
|
47
|
-
"require": {
|
|
48
|
-
"types": "./dist/index.d.cts",
|
|
49
|
-
"default": "./dist/index.cjs"
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
"./cli": {
|
|
53
|
-
"import": {
|
|
54
|
-
"types": "./dist/cli.d.ts",
|
|
55
|
-
"default": "./dist/cli.js"
|
|
56
|
-
},
|
|
57
|
-
"require": {
|
|
58
|
-
"types": "./dist/cli.d.cts",
|
|
59
|
-
"default": "./dist/cli.cjs"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
40
|
+
".": "./dist/index.js",
|
|
41
|
+
"./cli": "./dist/cli.js",
|
|
62
42
|
"./package.json": "./package.json"
|
|
63
43
|
},
|
|
64
44
|
"bin": {
|
|
@@ -71,10 +51,10 @@
|
|
|
71
51
|
],
|
|
72
52
|
"scripts": {
|
|
73
53
|
"fork-version": "node dist/cli.js",
|
|
74
|
-
"dev": "
|
|
75
|
-
"build": "
|
|
76
|
-
"update-json-schema": "node scripts/update-json-schema.
|
|
77
|
-
"update-readme-cli-options": "node scripts/update-readme-cli-options.
|
|
54
|
+
"dev": "tsdown --watch",
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"update-json-schema": "node scripts/update-json-schema.ts",
|
|
57
|
+
"update-readme-cli-options": "node scripts/update-readme-cli-options.ts",
|
|
78
58
|
"lint": "eslint --fix \"src/**/*.{js,ts}\"",
|
|
79
59
|
"lint:check": "eslint \"src/**/*.{js,ts}\"",
|
|
80
60
|
"lint:format": "prettier --write \"src/**/*.{js,ts}\"",
|
|
@@ -100,6 +80,7 @@
|
|
|
100
80
|
"zod": "4.3.6"
|
|
101
81
|
},
|
|
102
82
|
"devDependencies": {
|
|
83
|
+
"@arethetypeswrong/core": "0.18.2",
|
|
103
84
|
"@eslint/js": "10.0.1",
|
|
104
85
|
"@types/json-schema": "7.0.15",
|
|
105
86
|
"@types/node": "24.11.0",
|
|
@@ -111,9 +92,10 @@
|
|
|
111
92
|
"eslint-plugin-prettier": "5.5.5",
|
|
112
93
|
"globals": "17.4.0",
|
|
113
94
|
"prettier": "3.8.1",
|
|
95
|
+
"publint": "0.3.18",
|
|
114
96
|
"rimraf": "6.1.3",
|
|
115
|
-
"
|
|
116
|
-
"typescript": "
|
|
97
|
+
"tsdown": "0.21.7",
|
|
98
|
+
"typescript": "6.0.2",
|
|
117
99
|
"typescript-eslint": "8.58.0",
|
|
118
100
|
"vitest": "4.1.2"
|
|
119
101
|
}
|