@cluerise/tools 3.0.0 → 4.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/README.md +10 -9
- package/dist/configs/.nvmrc +1 -1
- package/dist/configs/.prettierignore +7 -0
- package/dist/configs/commitlint.config.ts +1 -1
- package/dist/configs/eslint-markdown.config.js +8 -0
- package/dist/configs/eslint.config.js +329 -0
- package/dist/configs/hooks/commit-msg +1 -1
- package/dist/configs/hooks/post-commit +1 -1
- package/dist/configs/hooks/pre-commit +1 -1
- package/dist/configs/hooks/prepare-commit-msg +1 -1
- package/dist/configs/lint-staged.config.js +4 -4
- package/dist/configs/pnpm-workspace.yaml +1 -0
- package/dist/configs/release.config.js +1 -1
- package/dist/configs/tsconfig.json +2 -7
- package/dist/scripts/check-heroku-node-version/main.js +154 -62
- package/dist/scripts/create-commit-message/main.js +157 -79
- package/dist/scripts/format-commit-message/main.js +131 -62
- package/dist/scripts/init/main.js +511 -270
- package/dist/scripts/lint/main.js +381 -78
- package/dist/scripts/release/main.js +222 -123
- package/dist/scripts/update-node-versions/main.js +167 -69
- package/package.json +31 -26
- package/dist/configs/.eslintignore +0 -47
- package/dist/configs/.eslintrc.cjs +0 -114
- package/dist/configs/_npmrc +0 -1
- /package/dist/bin/{cluenar-tools.sh → cluerise-tools.sh} +0 -0
|
@@ -1,25 +1,135 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var _origins, _names, _data, _PackageJson_instances, parseGitRepository_fn, _nodeReleasesUrl;
|
|
1
10
|
import SemVer from "semver";
|
|
2
|
-
import FileSystem from "fs/promises";
|
|
11
|
+
import FileSystem from "node:fs/promises";
|
|
3
12
|
import { z } from "zod";
|
|
4
13
|
import { parse } from "smol-toml";
|
|
5
|
-
class ParseGitRepositoryError extends Error {
|
|
6
|
-
}
|
|
7
14
|
const gitProviderOrigins = {
|
|
8
15
|
github: "https://github.com"
|
|
9
16
|
};
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
const _GitProvider = class _GitProvider {
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the provided name is a valid Git provider name.
|
|
20
|
+
*
|
|
21
|
+
* @param name - The name of the Git provider to validate.
|
|
22
|
+
* @returns True if the name is valid, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
static isValidName(name) {
|
|
25
|
+
return __privateGet(this, _names).includes(name);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns a Git provider origin.
|
|
29
|
+
*
|
|
30
|
+
* @param name - The name of the Git provider.
|
|
31
|
+
* @returns The origin URL of the Git provider.
|
|
32
|
+
*/
|
|
33
|
+
static getOrigin(name) {
|
|
34
|
+
return __privateGet(this, _origins)[name];
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
_origins = new WeakMap();
|
|
38
|
+
_names = new WeakMap();
|
|
39
|
+
__privateAdd(_GitProvider, _origins, gitProviderOrigins);
|
|
40
|
+
__privateAdd(_GitProvider, _names, Object.keys(__privateGet(_GitProvider, _origins)));
|
|
41
|
+
let GitProvider = _GitProvider;
|
|
42
|
+
const enginesSchema = z.object({
|
|
43
|
+
node: z.string()
|
|
44
|
+
});
|
|
45
|
+
const repositoryObjectSchema = z.object({
|
|
46
|
+
type: z.string(),
|
|
47
|
+
url: z.string(),
|
|
48
|
+
directory: z.ostring()
|
|
49
|
+
});
|
|
50
|
+
const repositorySchema = z.union([z.string(), repositoryObjectSchema]);
|
|
51
|
+
const packageJsonDataSchema = z.object({
|
|
52
|
+
name: z.string(),
|
|
53
|
+
version: z.string(),
|
|
54
|
+
description: z.string(),
|
|
55
|
+
engines: enginesSchema.optional(),
|
|
56
|
+
repository: repositorySchema.optional()
|
|
57
|
+
});
|
|
58
|
+
const _PackageJson = class _PackageJson {
|
|
59
|
+
constructor(data) {
|
|
60
|
+
__privateAdd(this, _PackageJson_instances);
|
|
61
|
+
__privateAdd(this, _data);
|
|
62
|
+
__privateSet(this, _data, data);
|
|
63
|
+
}
|
|
64
|
+
static async init() {
|
|
65
|
+
const content = await FileSystem.readFile("package.json", { encoding: "utf8" });
|
|
66
|
+
const data = JsonUtils.parse(content);
|
|
67
|
+
const parseResult = packageJsonDataSchema.safeParse(data);
|
|
68
|
+
if (!parseResult.success) {
|
|
69
|
+
throw new Error("Invalid package.json", {
|
|
70
|
+
cause: parseResult.error
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return new _PackageJson(parseResult.data);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the required engines.
|
|
77
|
+
*/
|
|
78
|
+
get engines() {
|
|
79
|
+
return __privateGet(this, _data).engines;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Sets the required engines.
|
|
83
|
+
*
|
|
84
|
+
* @param engines - The engines to set.
|
|
85
|
+
*/
|
|
86
|
+
set engines(engines) {
|
|
87
|
+
__privateGet(this, _data).engines = engines;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns the repository information.
|
|
91
|
+
*/
|
|
92
|
+
get repository() {
|
|
93
|
+
return __privateGet(this, _data).repository;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parses the repository information from package.json.
|
|
97
|
+
*
|
|
98
|
+
* @returns The parsed GitRepository or null if no repository is defined.
|
|
99
|
+
*/
|
|
100
|
+
parseGitRepository() {
|
|
101
|
+
if (!this.repository) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (typeof this.repository === "string") {
|
|
105
|
+
return __privateMethod(this, _PackageJson_instances, parseGitRepository_fn).call(this, this.repository);
|
|
106
|
+
}
|
|
107
|
+
return __privateMethod(this, _PackageJson_instances, parseGitRepository_fn).call(this, this.repository.url);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Saves the package.json file with the current data.
|
|
111
|
+
*/
|
|
112
|
+
async save() {
|
|
113
|
+
const content = JsonUtils.prettify(__privateGet(this, _data)) + "\n";
|
|
114
|
+
await FileSystem.writeFile("package.json", content, { encoding: "utf8" });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
_data = new WeakMap();
|
|
118
|
+
_PackageJson_instances = new WeakSet();
|
|
119
|
+
parseGitRepository_fn = function(urlString) {
|
|
120
|
+
if (!urlString) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
13
123
|
const urlValue = urlString.includes(":") ? urlString : `https://${urlString}`;
|
|
14
124
|
const url = new URL(urlValue);
|
|
15
125
|
const scheme = url.protocol.slice(0, -1);
|
|
16
|
-
if (
|
|
126
|
+
if (GitProvider.isValidName(scheme)) {
|
|
17
127
|
const [owner, repositoryName] = url.pathname.split("/");
|
|
18
128
|
if (!owner || !repositoryName) {
|
|
19
|
-
throw new
|
|
129
|
+
throw new Error("Unknown owner or repositoryName");
|
|
20
130
|
}
|
|
21
131
|
return {
|
|
22
|
-
origin:
|
|
132
|
+
origin: GitProvider.getOrigin(scheme),
|
|
23
133
|
owner,
|
|
24
134
|
repositoryName
|
|
25
135
|
};
|
|
@@ -27,7 +137,7 @@ const parseRepositoryUrl = (urlString) => {
|
|
|
27
137
|
if (scheme === "https") {
|
|
28
138
|
const [, owner, repositoryName] = url.pathname.split("/");
|
|
29
139
|
if (!owner || !repositoryName) {
|
|
30
|
-
throw new
|
|
140
|
+
throw new Error("Unknown owner or repositoryName");
|
|
31
141
|
}
|
|
32
142
|
return {
|
|
33
143
|
origin: url.origin,
|
|
@@ -35,52 +145,28 @@ const parseRepositoryUrl = (urlString) => {
|
|
|
35
145
|
repositoryName: repositoryName.endsWith(".git") ? repositoryName.slice(0, -4) : repositoryName
|
|
36
146
|
};
|
|
37
147
|
}
|
|
38
|
-
throw new
|
|
39
|
-
};
|
|
40
|
-
const parsePackageJsonRepository = (repository) => {
|
|
41
|
-
if (typeof repository === "string") {
|
|
42
|
-
return parseRepositoryUrl(repository);
|
|
43
|
-
}
|
|
44
|
-
return parseRepositoryUrl(repository.url);
|
|
45
|
-
};
|
|
46
|
-
const enginesSchema = z.object({
|
|
47
|
-
node: z.string()
|
|
48
|
-
});
|
|
49
|
-
const repositoryObjectSchema = z.object({
|
|
50
|
-
type: z.string(),
|
|
51
|
-
url: z.string(),
|
|
52
|
-
directory: z.ostring()
|
|
53
|
-
});
|
|
54
|
-
const repositorySchema = z.union([z.string(), repositoryObjectSchema]);
|
|
55
|
-
const packageJsonSchema = z.object({
|
|
56
|
-
name: z.string(),
|
|
57
|
-
version: z.string(),
|
|
58
|
-
description: z.string(),
|
|
59
|
-
engines: enginesSchema.optional(),
|
|
60
|
-
repository: repositorySchema.optional()
|
|
61
|
-
});
|
|
62
|
-
const readPackageJson = async () => {
|
|
63
|
-
const packageJsonData = await FileSystem.readFile("package.json", { encoding: "utf8" });
|
|
64
|
-
const packageJson = JSON.parse(packageJsonData);
|
|
65
|
-
const parseResult = packageJsonSchema.safeParse(packageJson);
|
|
66
|
-
if (!parseResult.success) {
|
|
67
|
-
throw parseResult.error;
|
|
68
|
-
}
|
|
69
|
-
return packageJson;
|
|
70
|
-
};
|
|
71
|
-
const CoreCommands = {
|
|
72
|
-
readPackageJson,
|
|
73
|
-
parsePackageJsonRepository
|
|
148
|
+
throw new Error("Unsupported repository URL");
|
|
74
149
|
};
|
|
150
|
+
let PackageJson = _PackageJson;
|
|
75
151
|
const runMain = (main2) => {
|
|
76
|
-
main2(process.argv.slice(2)).then((exitCode) => {
|
|
152
|
+
Promise.resolve().then(() => main2(process.argv.slice(2))).then((exitCode) => {
|
|
77
153
|
process.exit(exitCode);
|
|
78
154
|
}).catch((error) => {
|
|
79
|
-
console.error(error);
|
|
155
|
+
console.error("Error:", error);
|
|
80
156
|
process.exit(1);
|
|
81
157
|
});
|
|
82
158
|
};
|
|
83
|
-
|
|
159
|
+
class JsonUtils {
|
|
160
|
+
static stringify(value) {
|
|
161
|
+
return JSON.stringify(value);
|
|
162
|
+
}
|
|
163
|
+
static prettify(value) {
|
|
164
|
+
return JSON.stringify(value, null, 2);
|
|
165
|
+
}
|
|
166
|
+
static parse(value) {
|
|
167
|
+
return JSON.parse(value);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
84
170
|
const herokuNodeReleaseSchema = z.object({
|
|
85
171
|
version: z.string(),
|
|
86
172
|
channel: z.string(),
|
|
@@ -92,16 +178,22 @@ const herokuNodeReleasesSchema = z.object({
|
|
|
92
178
|
name: z.string(),
|
|
93
179
|
releases: z.array(herokuNodeReleaseSchema)
|
|
94
180
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
181
|
+
class Heroku {
|
|
182
|
+
/**
|
|
183
|
+
* Fetches supported Node.js releases on Heroku.
|
|
184
|
+
*
|
|
185
|
+
* @returns A promise that resolves to an array of HerokuNodeRelease objects.
|
|
186
|
+
*/
|
|
187
|
+
static async fetchNodeReleases() {
|
|
188
|
+
const response = await fetch(__privateGet(this, _nodeReleasesUrl));
|
|
189
|
+
const data = await response.text();
|
|
190
|
+
const releasesData = parse(data);
|
|
191
|
+
const { releases } = herokuNodeReleasesSchema.parse(releasesData);
|
|
192
|
+
return releases;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
_nodeReleasesUrl = new WeakMap();
|
|
196
|
+
__privateAdd(Heroku, _nodeReleasesUrl, "https://raw.githubusercontent.com/heroku/heroku-buildpack-nodejs/latest/inventory/node.toml");
|
|
105
197
|
const getResultMessage = (nodeVersion, supported) => {
|
|
106
198
|
const nodeVersionIsRange = SemVer.valid(nodeVersion) === null;
|
|
107
199
|
const name = `Node.js version ${nodeVersionIsRange ? `range "${nodeVersion}"` : nodeVersion}`;
|
|
@@ -110,7 +202,7 @@ const getResultMessage = (nodeVersion, supported) => {
|
|
|
110
202
|
const main = async () => {
|
|
111
203
|
var _a;
|
|
112
204
|
try {
|
|
113
|
-
const packageJson = await
|
|
205
|
+
const packageJson = await PackageJson.init();
|
|
114
206
|
const nodeVersion = (_a = packageJson.engines) == null ? void 0 : _a.node;
|
|
115
207
|
if (!nodeVersion) {
|
|
116
208
|
console.error("Error: Node.js version is not specified in package.json");
|
|
@@ -121,13 +213,13 @@ const main = async () => {
|
|
|
121
213
|
console.error(`Error: Node.js version "${nodeVersion}" is not valid semver version or range`);
|
|
122
214
|
return 1;
|
|
123
215
|
}
|
|
124
|
-
const releases = await
|
|
216
|
+
const releases = await Heroku.fetchNodeReleases();
|
|
125
217
|
const nodeVersionIsSupported = releases.some((release) => SemVer.satisfies(release.version, nodeVersion));
|
|
126
218
|
if (!nodeVersionIsSupported) {
|
|
127
219
|
console.error(`Error: ${getResultMessage(nodeVersion, false)}`);
|
|
128
220
|
return 1;
|
|
129
221
|
}
|
|
130
|
-
console.
|
|
222
|
+
console.info(`Info: ${getResultMessage(nodeVersion, true)}`);
|
|
131
223
|
return 0;
|
|
132
224
|
} catch (error) {
|
|
133
225
|
console.error("Error: Cannot check Node.js version on Heroku");
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var _config, _CommitLinter_instances, isValidEnumValue_fn, isValidType_fn, isValidScope_fn, _CommitLinter_static, parseSemanticCommitMessage_fn;
|
|
10
|
+
import FileSystem from "node:fs/promises";
|
|
2
11
|
import { z, ZodError } from "zod";
|
|
3
|
-
import ChildProcess from "child_process";
|
|
12
|
+
import ChildProcess from "node:child_process";
|
|
13
|
+
import loadCommitlintConfig from "@commitlint/load";
|
|
4
14
|
import "eslint";
|
|
5
15
|
import "glob";
|
|
6
16
|
import "prettier";
|
|
7
|
-
import loadCommitlintConfig from "@commitlint/load";
|
|
8
17
|
const enginesSchema = z.object({
|
|
9
18
|
node: z.string()
|
|
10
19
|
});
|
|
@@ -22,53 +31,142 @@ z.object({
|
|
|
22
31
|
repository: repositorySchema.optional()
|
|
23
32
|
});
|
|
24
33
|
const runMain = (main2) => {
|
|
25
|
-
main2(process.argv.slice(2)).then((exitCode) => {
|
|
34
|
+
Promise.resolve().then(() => main2(process.argv.slice(2))).then((exitCode) => {
|
|
26
35
|
process.exit(exitCode);
|
|
27
36
|
}).catch((error) => {
|
|
28
|
-
console.error(error);
|
|
37
|
+
console.error("Error:", error);
|
|
29
38
|
process.exit(1);
|
|
30
39
|
});
|
|
31
40
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
class StringUtils {
|
|
42
|
+
/**
|
|
43
|
+
* Capitalizes the first letter of a given string.
|
|
44
|
+
*
|
|
45
|
+
* @param value - The string to capitalize.
|
|
46
|
+
* @returns The string with the first letter capitalized.
|
|
47
|
+
*/
|
|
48
|
+
static capitalize(value) {
|
|
49
|
+
const [firstLetter] = value;
|
|
50
|
+
if (!firstLetter) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
return `${firstLetter.toUpperCase()}${value.slice(1)}`;
|
|
36
54
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ChildProcess.execSync("
|
|
46
|
-
return true;
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
55
|
+
}
|
|
56
|
+
class Git {
|
|
57
|
+
/**
|
|
58
|
+
* Returns the current branch name of the git repository.
|
|
59
|
+
*
|
|
60
|
+
* @returns The name of the current branch.
|
|
61
|
+
*/
|
|
62
|
+
static getBranchName() {
|
|
63
|
+
return ChildProcess.execSync("git symbolic-ref --short HEAD").toString().trim();
|
|
49
64
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
commitMessage += StringUtils.capitalize(subject);
|
|
65
|
+
/**
|
|
66
|
+
* Checks if the repository is currently in a rebase state.
|
|
67
|
+
*
|
|
68
|
+
* @returns True if the repository is rebasing, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
static isRebasing() {
|
|
71
|
+
try {
|
|
72
|
+
ChildProcess.execSync("ls `git rev-parse --git-dir` | grep rebase");
|
|
73
|
+
return true;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
63
77
|
}
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
}
|
|
79
|
+
const _CommitLinter = class _CommitLinter {
|
|
80
|
+
constructor(config) {
|
|
81
|
+
__privateAdd(this, _CommitLinter_instances);
|
|
82
|
+
__privateAdd(this, _config);
|
|
83
|
+
__privateSet(this, _config, config);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Initializes the CommitLinter with the loaded commitlint configuration.
|
|
87
|
+
*
|
|
88
|
+
* @returns A Promise that resolves to an instance of CommitLinter.
|
|
89
|
+
*/
|
|
90
|
+
static async init() {
|
|
91
|
+
const config = await loadCommitlintConfig();
|
|
92
|
+
return new _CommitLinter(config);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Lints commit messages using commitlint.
|
|
96
|
+
*
|
|
97
|
+
* @param args - An array of arguments to pass to commitlint.
|
|
98
|
+
* @returns The exit status of the commitlint command.
|
|
99
|
+
*/
|
|
100
|
+
static lint(args) {
|
|
101
|
+
const { status } = ChildProcess.spawnSync("commitlint", args, { stdio: "inherit" });
|
|
102
|
+
return status ?? 0;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Parses a semantic branch name into its type and scope.
|
|
106
|
+
*
|
|
107
|
+
* @param name - The branch name to parse.
|
|
108
|
+
* @returns An object containing the type and scope of the commit message.
|
|
109
|
+
* @throws An error if the branch name is invalid.
|
|
110
|
+
*/
|
|
111
|
+
parseSemanticBranchName(name) {
|
|
112
|
+
const [typeValue, scopeValue] = name.split("-");
|
|
113
|
+
if (!typeValue || !__privateMethod(this, _CommitLinter_instances, isValidType_fn).call(this, typeValue)) {
|
|
114
|
+
throw new Error("Invalid commit type in branch name");
|
|
115
|
+
}
|
|
116
|
+
const type = typeValue.toLowerCase();
|
|
117
|
+
const scope = scopeValue && __privateMethod(this, _CommitLinter_instances, isValidScope_fn).call(this, scopeValue) ? scopeValue.toLowerCase() : null;
|
|
118
|
+
return {
|
|
119
|
+
type,
|
|
120
|
+
scope
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns the prefix of a semantic commit message as a string.
|
|
125
|
+
*
|
|
126
|
+
* This prefix consists of the type and scope of the commit message.
|
|
127
|
+
* If the scope is not provided, it will only return the type.
|
|
128
|
+
* @param prefix - An object containing the type and scope of the commit message.
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
static stringifySemanticCommitMessagePrefix({ type, scope }) {
|
|
132
|
+
return `${type}${scope ? `(${scope})` : ""}`;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Formats a semantic commit message by capitalizing the content after the prefix.
|
|
136
|
+
*
|
|
137
|
+
* @param message - The commit message to format.
|
|
138
|
+
* @returns The formatted commit message.
|
|
139
|
+
*/
|
|
140
|
+
static formatSemanticCommitMessage(message) {
|
|
141
|
+
const { prefix, content } = __privateMethod(this, _CommitLinter_static, parseSemanticCommitMessage_fn).call(this, message);
|
|
142
|
+
if (!prefix || !content) {
|
|
143
|
+
return message;
|
|
144
|
+
}
|
|
145
|
+
return `${prefix}: ${StringUtils.capitalize(content)}`;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates a semantic commit message from a prefix and a message.
|
|
149
|
+
*
|
|
150
|
+
* @param prefix - The prefix of the commit message, containing type and scope.
|
|
151
|
+
* @param message - The content of the commit message.
|
|
152
|
+
* @returns The formatted semantic commit message.
|
|
153
|
+
*/
|
|
154
|
+
static createSemanticCommitMessage(prefix, message) {
|
|
155
|
+
const [subject, ...comments] = message.split("\n#");
|
|
156
|
+
let commitMessage = this.stringifySemanticCommitMessagePrefix(prefix) + ": ";
|
|
157
|
+
if (subject) {
|
|
158
|
+
commitMessage += StringUtils.capitalize(subject);
|
|
159
|
+
}
|
|
160
|
+
if (comments.length > 0) {
|
|
161
|
+
commitMessage += "\n\n#" + comments.join("\n#");
|
|
162
|
+
}
|
|
163
|
+
return commitMessage;
|
|
66
164
|
}
|
|
67
|
-
return commitMessage;
|
|
68
165
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
166
|
+
_config = new WeakMap();
|
|
167
|
+
_CommitLinter_instances = new WeakSet();
|
|
168
|
+
isValidEnumValue_fn = function(ruleName, value) {
|
|
169
|
+
const rule = __privateGet(this, _config).rules[ruleName];
|
|
72
170
|
if (!rule) {
|
|
73
171
|
return true;
|
|
74
172
|
}
|
|
@@ -78,43 +176,21 @@ const isValidEnumValue = async (ruleName, value) => {
|
|
|
78
176
|
}
|
|
79
177
|
return values.includes(value);
|
|
80
178
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const CommitLintConfig = {
|
|
84
|
-
isValidType,
|
|
85
|
-
isValidScope
|
|
179
|
+
isValidType_fn = function(type) {
|
|
180
|
+
return __privateMethod(this, _CommitLinter_instances, isValidEnumValue_fn).call(this, "type-enum", type);
|
|
86
181
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!typeValue || !await CommitLintConfig.isValidType(typeValue)) {
|
|
90
|
-
throw new Error("Invalid commit type in branch name");
|
|
91
|
-
}
|
|
92
|
-
const type = typeValue.toLowerCase();
|
|
93
|
-
const scope = scopeValue && await CommitLintConfig.isValidScope(scopeValue) ? scopeValue.toLowerCase() : null;
|
|
94
|
-
return {
|
|
95
|
-
type,
|
|
96
|
-
scope
|
|
97
|
-
};
|
|
182
|
+
isValidScope_fn = function(scope) {
|
|
183
|
+
return __privateMethod(this, _CommitLinter_instances, isValidEnumValue_fn).call(this, "scope-enum", scope);
|
|
98
184
|
};
|
|
99
|
-
|
|
185
|
+
_CommitLinter_static = new WeakSet();
|
|
186
|
+
parseSemanticCommitMessage_fn = function(message) {
|
|
100
187
|
const firstColonPosition = message.search(":");
|
|
101
188
|
const prefix = message.slice(0, firstColonPosition).trim();
|
|
102
189
|
const content = message.slice(firstColonPosition + 1).trim();
|
|
103
190
|
return { prefix, content };
|
|
104
191
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (!prefix || !content) {
|
|
108
|
-
return message;
|
|
109
|
-
}
|
|
110
|
-
return `${prefix}: ${StringUtils.capitalize(content)}`;
|
|
111
|
-
};
|
|
112
|
-
const CommitLintCommands = {
|
|
113
|
-
createSemanticCommitMessage,
|
|
114
|
-
parseSemanticBranchName,
|
|
115
|
-
formatSemanticCommitMessage,
|
|
116
|
-
startsWithSemanticCommitMessagePrefix
|
|
117
|
-
};
|
|
192
|
+
__privateAdd(_CommitLinter, _CommitLinter_static);
|
|
193
|
+
let CommitLinter = _CommitLinter;
|
|
118
194
|
const commitMessagePathArgSchema = z.string();
|
|
119
195
|
const parseCreateCommitMessageArgs = ([commitMessagePathArg]) => {
|
|
120
196
|
const commitMessagePath = commitMessagePathArgSchema.parse(commitMessagePathArg);
|
|
@@ -124,25 +200,27 @@ const parseCreateCommitMessageArgs = ([commitMessagePathArg]) => {
|
|
|
124
200
|
};
|
|
125
201
|
const main = async (args) => {
|
|
126
202
|
try {
|
|
127
|
-
if (
|
|
203
|
+
if (Git.isRebasing()) {
|
|
128
204
|
return 0;
|
|
129
205
|
}
|
|
130
206
|
const { commitMessagePath } = parseCreateCommitMessageArgs(args);
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
207
|
+
const commitMessageBuffer = await FileSystem.readFile(commitMessagePath);
|
|
208
|
+
const commitMessage = commitMessageBuffer.toString();
|
|
209
|
+
const commitLinter = await CommitLinter.init();
|
|
210
|
+
const commitMessagePrefix = commitLinter.parseSemanticBranchName(Git.getBranchName());
|
|
211
|
+
if (!commitMessage.startsWith(CommitLinter.stringifySemanticCommitMessagePrefix(commitMessagePrefix))) {
|
|
212
|
+
const nextCommitMessage = CommitLinter.createSemanticCommitMessage(commitMessagePrefix, commitMessage);
|
|
136
213
|
await FileSystem.writeFile(commitMessagePath, nextCommitMessage);
|
|
137
214
|
}
|
|
138
215
|
} catch (error) {
|
|
139
216
|
if (error instanceof ZodError) {
|
|
140
|
-
console.warn("Invalid commit message path");
|
|
217
|
+
console.warn("Warning: Invalid commit message path");
|
|
141
218
|
}
|
|
142
219
|
if (error instanceof Error) {
|
|
143
|
-
console.warn(error.message);
|
|
220
|
+
console.warn("Warning:", error.message);
|
|
221
|
+
} else {
|
|
222
|
+
console.warn("Warning:", error);
|
|
144
223
|
}
|
|
145
|
-
console.warn(error);
|
|
146
224
|
}
|
|
147
225
|
return 0;
|
|
148
226
|
};
|