@cluerise/tools 5.4.0 → 5.4.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/dist/configs/.nvmrc +1 -1
- package/dist/scripts/check-heroku-node-version/main.js +227 -228
- package/dist/scripts/create-commit-message/main.js +227 -213
- package/dist/scripts/format-commit-message/main.js +194 -181
- package/dist/scripts/init/main.js +557 -601
- package/dist/scripts/lint/main.js +432 -431
- package/dist/scripts/release/main.js +425 -495
- package/dist/scripts/update-node-versions/main.js +243 -259
- package/dist/scripts/update-xcode-version/main.js +202 -204
- package/package.json +17 -17
|
@@ -1,194 +1,207 @@
|
|
|
1
1
|
import FileSystem from "node:fs/promises";
|
|
2
|
-
import {
|
|
2
|
+
import { ZodError, z } from "zod";
|
|
3
3
|
import ChildProcess from "node:child_process";
|
|
4
4
|
import loadCommitlintConfig from "@commitlint/load";
|
|
5
5
|
import "eslint";
|
|
6
6
|
import "glob";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
//#region src/modules/core/package-json/git-provider.ts
|
|
8
|
+
var gitProviderOrigins = { github: "https://github.com" };
|
|
9
|
+
(class {
|
|
10
|
+
static #origins = gitProviderOrigins;
|
|
11
|
+
static #names = Object.keys(this.#origins);
|
|
12
|
+
/**
|
|
13
|
+
* Check if the provided name is a valid Git provider name.
|
|
14
|
+
*
|
|
15
|
+
* @param name The name to check.
|
|
16
|
+
* @returns True if the name is valid, otherwise false.
|
|
17
|
+
*/
|
|
18
|
+
static isValidName(name) {
|
|
19
|
+
return this.#names.includes(name);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the origin URL for the given Git provider name.
|
|
23
|
+
*
|
|
24
|
+
* @param name The Git provider name.
|
|
25
|
+
* @returns The origin URL.
|
|
26
|
+
*/
|
|
27
|
+
static getOrigin(name) {
|
|
28
|
+
return this.#origins[name];
|
|
29
|
+
}
|
|
9
30
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/modules/core/package-json/package-json-data.ts
|
|
33
|
+
var enginesSchema = z.object({ node: z.string() });
|
|
34
|
+
var repositoryObjectSchema = z.object({
|
|
35
|
+
type: z.string(),
|
|
36
|
+
url: z.string(),
|
|
37
|
+
directory: z.string().optional()
|
|
14
38
|
});
|
|
15
|
-
|
|
39
|
+
var repositorySchema = z.union([z.string(), repositoryObjectSchema]);
|
|
16
40
|
z.object({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
name: z.string(),
|
|
42
|
+
version: z.string().optional(),
|
|
43
|
+
description: z.string().optional(),
|
|
44
|
+
engines: enginesSchema.optional(),
|
|
45
|
+
repository: repositorySchema.optional()
|
|
22
46
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/modules/core/run-main.ts
|
|
49
|
+
/**
|
|
50
|
+
* Execute the provided main function and handle any errors that occur.
|
|
51
|
+
*
|
|
52
|
+
* If the main function resolves, the process exits with the returned code.
|
|
53
|
+
* If an error is thrown, it logs the error and exits with code 1.
|
|
54
|
+
*
|
|
55
|
+
* @param main The main function to execute.
|
|
56
|
+
*/
|
|
57
|
+
var runMain = (main) => {
|
|
58
|
+
Promise.resolve().then(() => main(process.argv.slice(2))).then((exitCode) => {
|
|
59
|
+
process.exit(exitCode);
|
|
60
|
+
}).catch((error) => {
|
|
61
|
+
console.error("Error:", error);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
30
64
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
class CommitLinter {
|
|
49
|
-
#config;
|
|
50
|
-
constructor(config) {
|
|
51
|
-
this.#config = config;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Initialize the CommitLinter with the loaded commitlint configuration.
|
|
55
|
-
*
|
|
56
|
-
* @returns A Promise that resolves to an instance of CommitLinter.
|
|
57
|
-
*/
|
|
58
|
-
static async init() {
|
|
59
|
-
const config = await loadCommitlintConfig();
|
|
60
|
-
return new CommitLinter(config);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Lint commit messages using commitlint.
|
|
64
|
-
*
|
|
65
|
-
* @param args An array of arguments to pass to commitlint.
|
|
66
|
-
* @returns The exit status of the commitlint command.
|
|
67
|
-
*/
|
|
68
|
-
static lint(args) {
|
|
69
|
-
const { status } = ChildProcess.spawnSync("commitlint", args, { stdio: "inherit" });
|
|
70
|
-
return status ?? 0;
|
|
71
|
-
}
|
|
72
|
-
#getRuleValues(ruleName) {
|
|
73
|
-
const rule = this.#config.rules[ruleName];
|
|
74
|
-
if (!rule) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
const [_severity, _condition, values] = rule;
|
|
78
|
-
return values ?? null;
|
|
79
|
-
}
|
|
80
|
-
#isValidType(type) {
|
|
81
|
-
const values = this.#getRuleValues("type-enum");
|
|
82
|
-
if (!values) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
return values.includes(type);
|
|
86
|
-
}
|
|
87
|
-
#isValidScope(scope) {
|
|
88
|
-
const values = this.#getRuleValues("scope-enum");
|
|
89
|
-
if (!values) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
if ("scopes" in values) {
|
|
93
|
-
return values.scopes.includes(scope);
|
|
94
|
-
}
|
|
95
|
-
return values.includes(scope);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Parse a semantic branch name into its type and scope.
|
|
99
|
-
*
|
|
100
|
-
* @param name The branch name to parse.
|
|
101
|
-
* @returns An object containing the type and scope of the commit message.
|
|
102
|
-
* @throws An error if the branch name is invalid.
|
|
103
|
-
*/
|
|
104
|
-
parseSemanticBranchName(name) {
|
|
105
|
-
const [typeValue, scopeValue] = name.split("-");
|
|
106
|
-
if (!typeValue || !this.#isValidType(typeValue)) {
|
|
107
|
-
throw new Error("Invalid commit type in branch name");
|
|
108
|
-
}
|
|
109
|
-
const type = typeValue.toLowerCase();
|
|
110
|
-
const scope = scopeValue && this.#isValidScope(scopeValue) ? scopeValue.toLowerCase() : null;
|
|
111
|
-
return {
|
|
112
|
-
type,
|
|
113
|
-
scope
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Get the prefix of a semantic commit message as a string.
|
|
118
|
-
*
|
|
119
|
-
* This prefix consists of the type and scope of the commit message.
|
|
120
|
-
* If the scope is not provided, it will only return the type.
|
|
121
|
-
*
|
|
122
|
-
* @param prefix An object containing the type and scope of the commit message.
|
|
123
|
-
* @returns The stringified prefix.
|
|
124
|
-
*/
|
|
125
|
-
static stringifySemanticCommitMessagePrefix({ type, scope }) {
|
|
126
|
-
return `${type}${scope ? `(${scope})` : ""}`;
|
|
127
|
-
}
|
|
128
|
-
static #parseSemanticCommitMessage(message) {
|
|
129
|
-
const firstColonPosition = message.search(":");
|
|
130
|
-
const prefix = message.slice(0, firstColonPosition).trim();
|
|
131
|
-
const content = message.slice(firstColonPosition + 1).trim();
|
|
132
|
-
return { prefix, content };
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Format 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 } = this.#parseSemanticCommitMessage(message);
|
|
142
|
-
if (!prefix || !content) {
|
|
143
|
-
return message;
|
|
144
|
-
}
|
|
145
|
-
return `${prefix}: ${StringUtils.capitalize(content)}`;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Create 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.trim());
|
|
159
|
-
}
|
|
160
|
-
if (comments.length > 0) {
|
|
161
|
-
commitMessage += "\n\n#" + comments.map((comment) => comment.trim()).join("\n#");
|
|
162
|
-
}
|
|
163
|
-
return commitMessage;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const commitMessagePathArgSchema = z.string();
|
|
167
|
-
const parseFormatCommitMessageArgs = ([commitMessagePathArg]) => {
|
|
168
|
-
const commitMessagePath = commitMessagePathArgSchema.parse(commitMessagePathArg);
|
|
169
|
-
return {
|
|
170
|
-
commitMessagePath
|
|
171
|
-
};
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/modules/core/utils/string-utils.ts
|
|
67
|
+
var StringUtils = class {
|
|
68
|
+
/**
|
|
69
|
+
* Capitalize the first letter of a given string.
|
|
70
|
+
*
|
|
71
|
+
* If the string is empty, it is returned unchanged.
|
|
72
|
+
*
|
|
73
|
+
* @param value The string to capitalize.
|
|
74
|
+
* @returns The string with the first letter capitalized, or the original string if empty.
|
|
75
|
+
*/
|
|
76
|
+
static capitalize(value) {
|
|
77
|
+
const [firstLetter] = value;
|
|
78
|
+
if (!firstLetter) return value;
|
|
79
|
+
return `${firstLetter.toUpperCase()}${value.slice(1)}`;
|
|
80
|
+
}
|
|
172
81
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/modules/lint/commit-linter.ts
|
|
84
|
+
var CommitLinter = class CommitLinter {
|
|
85
|
+
#config;
|
|
86
|
+
constructor(config) {
|
|
87
|
+
this.#config = config;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Initialize the CommitLinter with the loaded commitlint configuration.
|
|
91
|
+
*
|
|
92
|
+
* @returns A Promise that resolves to an instance of CommitLinter.
|
|
93
|
+
*/
|
|
94
|
+
static async init() {
|
|
95
|
+
return new CommitLinter(await loadCommitlintConfig());
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Lint commit messages using commitlint.
|
|
99
|
+
*
|
|
100
|
+
* @param args An array of arguments to pass to commitlint.
|
|
101
|
+
* @returns The exit status of the commitlint command.
|
|
102
|
+
*/
|
|
103
|
+
static lint(args) {
|
|
104
|
+
const { status } = ChildProcess.spawnSync("commitlint", args, { stdio: "inherit" });
|
|
105
|
+
return status ?? 0;
|
|
106
|
+
}
|
|
107
|
+
#getRuleValues(ruleName) {
|
|
108
|
+
const rule = this.#config.rules[ruleName];
|
|
109
|
+
if (!rule) return null;
|
|
110
|
+
const [_severity, _condition, values] = rule;
|
|
111
|
+
return values ?? null;
|
|
112
|
+
}
|
|
113
|
+
#isValidType(type) {
|
|
114
|
+
const values = this.#getRuleValues("type-enum");
|
|
115
|
+
if (!values) return true;
|
|
116
|
+
return values.includes(type);
|
|
117
|
+
}
|
|
118
|
+
#isValidScope(scope) {
|
|
119
|
+
const values = this.#getRuleValues("scope-enum");
|
|
120
|
+
if (!values) return true;
|
|
121
|
+
if ("scopes" in values) return values.scopes.includes(scope);
|
|
122
|
+
return values.includes(scope);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Parse a semantic branch name into its type and scope.
|
|
126
|
+
*
|
|
127
|
+
* @param name The branch name to parse.
|
|
128
|
+
* @returns An object containing the type and scope of the commit message.
|
|
129
|
+
* @throws An error if the branch name is invalid.
|
|
130
|
+
*/
|
|
131
|
+
parseSemanticBranchName(name) {
|
|
132
|
+
const [typeValue, scopeValue] = name.split("-");
|
|
133
|
+
if (!typeValue || !this.#isValidType(typeValue)) throw new Error("Invalid commit type in branch name");
|
|
134
|
+
return {
|
|
135
|
+
type: typeValue.toLowerCase(),
|
|
136
|
+
scope: scopeValue && this.#isValidScope(scopeValue) ? scopeValue.toLowerCase() : null
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get the prefix of a semantic commit message as a string.
|
|
141
|
+
*
|
|
142
|
+
* This prefix consists of the type and scope of the commit message.
|
|
143
|
+
* If the scope is not provided, it will only return the type.
|
|
144
|
+
*
|
|
145
|
+
* @param prefix An object containing the type and scope of the commit message.
|
|
146
|
+
* @returns The stringified prefix.
|
|
147
|
+
*/
|
|
148
|
+
static stringifySemanticCommitMessagePrefix({ type, scope }) {
|
|
149
|
+
return `${type}${scope ? `(${scope})` : ""}`;
|
|
150
|
+
}
|
|
151
|
+
static #parseSemanticCommitMessage(message) {
|
|
152
|
+
const firstColonPosition = message.search(":");
|
|
153
|
+
return {
|
|
154
|
+
prefix: message.slice(0, firstColonPosition).trim(),
|
|
155
|
+
content: message.slice(firstColonPosition + 1).trim()
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Format a semantic commit message by capitalizing the content after the prefix.
|
|
160
|
+
*
|
|
161
|
+
* @param message The commit message to format.
|
|
162
|
+
* @returns The formatted commit message.
|
|
163
|
+
*/
|
|
164
|
+
static formatSemanticCommitMessage(message) {
|
|
165
|
+
const { prefix, content } = this.#parseSemanticCommitMessage(message);
|
|
166
|
+
if (!prefix || !content) return message;
|
|
167
|
+
return `${prefix}: ${StringUtils.capitalize(content)}`;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Create a semantic commit message from a prefix and a message.
|
|
171
|
+
*
|
|
172
|
+
* @param prefix The prefix of the commit message, containing type and scope.
|
|
173
|
+
* @param message The content of the commit message.
|
|
174
|
+
* @returns The formatted semantic commit message.
|
|
175
|
+
*/
|
|
176
|
+
static createSemanticCommitMessage(prefix, message) {
|
|
177
|
+
const [subject, ...comments] = message.split("\n#");
|
|
178
|
+
let commitMessage = this.stringifySemanticCommitMessagePrefix(prefix) + ": ";
|
|
179
|
+
if (subject) commitMessage += StringUtils.capitalize(subject.trim());
|
|
180
|
+
if (comments.length > 0) commitMessage += "\n\n#" + comments.map((comment) => comment.trim()).join("\n#");
|
|
181
|
+
return commitMessage;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/app/scripts/format-commit-message/args.ts
|
|
186
|
+
var commitMessagePathArgSchema = z.string();
|
|
187
|
+
var parseFormatCommitMessageArgs = ([commitMessagePathArg]) => {
|
|
188
|
+
return { commitMessagePath: commitMessagePathArgSchema.parse(commitMessagePathArg) };
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/app/scripts/format-commit-message/main.ts
|
|
192
|
+
var main = async (args) => {
|
|
193
|
+
try {
|
|
194
|
+
const { commitMessagePath } = parseFormatCommitMessageArgs(args);
|
|
195
|
+
const commitMessage = (await FileSystem.readFile(commitMessagePath)).toString();
|
|
196
|
+
const formattedCommitMessage = CommitLinter.formatSemanticCommitMessage(commitMessage);
|
|
197
|
+
if (formattedCommitMessage !== commitMessage) await FileSystem.writeFile(commitMessagePath, formattedCommitMessage);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (error instanceof ZodError) console.warn("Warning: Invalid commit message path");
|
|
200
|
+
if (error instanceof Error) console.warn("Warning:", error.message);
|
|
201
|
+
else console.warn("Warning:", error);
|
|
202
|
+
}
|
|
203
|
+
return 0;
|
|
193
204
|
};
|
|
194
205
|
runMain(main);
|
|
206
|
+
//#endregion
|
|
207
|
+
export {};
|