@cluerise/tools 4.2.1 → 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/README.md +1 -1
- package/dist/configs/.nvmrc +1 -1
- package/dist/configs/.prettierignore +6 -6
- package/dist/configs/_gitignore +2 -1
- package/dist/configs/eslint.config.js +12 -12
- package/dist/configs/release-cwd.config.cjs +26 -0
- package/dist/configs/release.config.js +8 -2
- package/dist/scripts/check-heroku-node-version/main.js +43 -14
- package/dist/scripts/create-commit-message/main.js +29 -22
- package/dist/scripts/format-commit-message/main.js +21 -18
- package/dist/scripts/init/main.js +66 -33
- package/dist/scripts/lint/main.js +42 -35
- package/dist/scripts/release/main.js +233 -34124
- package/dist/scripts/update-node-versions/main.js +44 -15
- package/package.json +4 -4
- package/dist/scripts/release/assets/index-BOULatd3.js +0 -50541
|
@@ -11,19 +11,19 @@ import * as Prettier from "prettier";
|
|
|
11
11
|
class CoreConfig {
|
|
12
12
|
static #packageName = "@cluerise/tools";
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Determine if the application is running in production mode.
|
|
15
15
|
*
|
|
16
|
-
* This
|
|
16
|
+
* This checks the environment variable `import.meta.env.PROD` to determine the mode.
|
|
17
17
|
*
|
|
18
|
-
* @returns True if in production mode, false
|
|
18
|
+
* @returns True if running in production mode, otherwise false.
|
|
19
19
|
*/
|
|
20
20
|
static get isProd() {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Get the path to package configuration files in production.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
26
|
+
* Used to load configuration from the package when running in production.
|
|
27
27
|
*
|
|
28
28
|
* @returns The path to the configuration files in the package.
|
|
29
29
|
*/
|
|
@@ -34,10 +34,9 @@ class CoreConfig {
|
|
|
34
34
|
return this.isProd ? `./node_modules/${this.#packageName}` : ".";
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Get the directory path where configuration files are stored.
|
|
38
38
|
*
|
|
39
|
-
* In production
|
|
40
|
-
* In development mode, it points to the root directory.
|
|
39
|
+
* In production, this points to `dist/configs` in the package; in development, it points to the root directory.
|
|
41
40
|
*
|
|
42
41
|
* @returns The path to the configuration directory.
|
|
43
42
|
*/
|
|
@@ -47,13 +46,18 @@ class CoreConfig {
|
|
|
47
46
|
}
|
|
48
47
|
class ConsoleStatusLogger {
|
|
49
48
|
#command;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new logger for a specific command.
|
|
51
|
+
*
|
|
52
|
+
* @param command The command name to log.
|
|
53
|
+
*/
|
|
50
54
|
constructor(command) {
|
|
51
55
|
this.#command = command;
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
|
-
*
|
|
58
|
+
* Log the beginning of a command with the provided argument.
|
|
55
59
|
*
|
|
56
|
-
* @param argument
|
|
60
|
+
* @param argument The argument for the command.
|
|
57
61
|
*
|
|
58
62
|
* @example
|
|
59
63
|
* const logger = new ConsoleStatusLogger('Linting');
|
|
@@ -69,10 +73,10 @@ class ConsoleStatusLogger {
|
|
|
69
73
|
return exitCode === 0 ? "OK" : "Failed";
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
72
|
-
*
|
|
76
|
+
* Log the end of a command with the provided argument and exit code.
|
|
73
77
|
*
|
|
74
|
-
* @param argument
|
|
75
|
-
* @param exitCode
|
|
78
|
+
* @param argument The argument for the command.
|
|
79
|
+
* @param exitCode The exit code of the command execution. If null, it indicates completion without an error.
|
|
76
80
|
*
|
|
77
81
|
* @example
|
|
78
82
|
* const logger = new ConsoleStatusLogger('Linting');
|
|
@@ -91,19 +95,19 @@ class GitProvider {
|
|
|
91
95
|
static #origins = gitProviderOrigins;
|
|
92
96
|
static #names = Object.keys(this.#origins);
|
|
93
97
|
/**
|
|
94
|
-
*
|
|
98
|
+
* Check if the provided name is a valid Git provider name.
|
|
95
99
|
*
|
|
96
|
-
* @param name
|
|
97
|
-
* @returns True if the name is valid, false
|
|
100
|
+
* @param name The name to check.
|
|
101
|
+
* @returns True if the name is valid, otherwise false.
|
|
98
102
|
*/
|
|
99
103
|
static isValidName(name) {
|
|
100
104
|
return this.#names.includes(name);
|
|
101
105
|
}
|
|
102
106
|
/**
|
|
103
|
-
*
|
|
107
|
+
* Get the origin URL for the given Git provider name.
|
|
104
108
|
*
|
|
105
|
-
* @param name
|
|
106
|
-
* @returns The origin URL
|
|
109
|
+
* @param name The Git provider name.
|
|
110
|
+
* @returns The origin URL.
|
|
107
111
|
*/
|
|
108
112
|
static getOrigin(name) {
|
|
109
113
|
return this.#origins[name];
|
|
@@ -130,6 +134,13 @@ class PackageJson {
|
|
|
130
134
|
constructor(data) {
|
|
131
135
|
this.#data = data;
|
|
132
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Load and parse the `package.json` file, returning a `PackageJson` instance.
|
|
139
|
+
*
|
|
140
|
+
* Throws an error if the file is invalid or cannot be parsed.
|
|
141
|
+
*
|
|
142
|
+
* @returns A new `PackageJson` instance with parsed data.
|
|
143
|
+
*/
|
|
133
144
|
static async init() {
|
|
134
145
|
const content = await FileSystem.readFile("package.json", { encoding: "utf8" });
|
|
135
146
|
const data = JsonUtils.parse(content);
|
|
@@ -142,21 +153,41 @@ class PackageJson {
|
|
|
142
153
|
return new PackageJson(data);
|
|
143
154
|
}
|
|
144
155
|
/**
|
|
145
|
-
*
|
|
156
|
+
* Get the package name from `package.json`.
|
|
157
|
+
*
|
|
158
|
+
* @returns The package name.
|
|
159
|
+
*/
|
|
160
|
+
get name() {
|
|
161
|
+
return this.#data.name;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get the package version from `package.json`.
|
|
165
|
+
*
|
|
166
|
+
* @returns The package version.
|
|
167
|
+
*/
|
|
168
|
+
get version() {
|
|
169
|
+
return this.#data.version;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the engines field from `package.json`, if present.
|
|
173
|
+
*
|
|
174
|
+
* @returns The engines object or undefined.
|
|
146
175
|
*/
|
|
147
176
|
get engines() {
|
|
148
177
|
return this.#data.engines;
|
|
149
178
|
}
|
|
150
179
|
/**
|
|
151
|
-
*
|
|
180
|
+
* Set the engines field in `package.json`.
|
|
152
181
|
*
|
|
153
|
-
* @param engines
|
|
182
|
+
* @param engines The engines object to set.
|
|
154
183
|
*/
|
|
155
184
|
set engines(engines) {
|
|
156
185
|
this.#data.engines = engines;
|
|
157
186
|
}
|
|
158
187
|
/**
|
|
159
|
-
*
|
|
188
|
+
* Get the repository field from `package.json`, if present.
|
|
189
|
+
*
|
|
190
|
+
* @returns The repository object or string, or undefined.
|
|
160
191
|
*/
|
|
161
192
|
get repository() {
|
|
162
193
|
return this.#data.repository;
|
|
@@ -193,9 +224,11 @@ class PackageJson {
|
|
|
193
224
|
throw new Error("Unsupported repository URL");
|
|
194
225
|
}
|
|
195
226
|
/**
|
|
196
|
-
*
|
|
227
|
+
* Parse the repository information from `package.json` and return a `GitRepository` object or null.
|
|
228
|
+
*
|
|
229
|
+
* Returns null if no repository is defined or if parsing fails.
|
|
197
230
|
*
|
|
198
|
-
* @returns The parsed GitRepository or null if
|
|
231
|
+
* @returns The parsed `GitRepository`, or null if not available.
|
|
199
232
|
*/
|
|
200
233
|
parseGitRepository() {
|
|
201
234
|
if (!this.repository) {
|
|
@@ -207,7 +240,7 @@ class PackageJson {
|
|
|
207
240
|
return this.#parseGitRepository(this.repository.url);
|
|
208
241
|
}
|
|
209
242
|
/**
|
|
210
|
-
*
|
|
243
|
+
* Save the current `package.json` data to disk, formatting it as prettified JSON.
|
|
211
244
|
*/
|
|
212
245
|
async save() {
|
|
213
246
|
const content = JsonUtils.prettify(this.#data) + "\n";
|
|
@@ -272,7 +305,7 @@ class ToolInitializer {
|
|
|
272
305
|
this.#configPackage = configPackage;
|
|
273
306
|
}
|
|
274
307
|
/**
|
|
275
|
-
*
|
|
308
|
+
* Get the names of all available tools.
|
|
276
309
|
*
|
|
277
310
|
* @returns An array of tool names.
|
|
278
311
|
*/
|
|
@@ -380,9 +413,9 @@ export default createReleaseConfig(${JsonUtils.prettify(configParams)});
|
|
|
380
413
|
await FileUtils.createFile(settingsPath, settingsContent);
|
|
381
414
|
}
|
|
382
415
|
/**
|
|
383
|
-
*
|
|
416
|
+
* Initialize the specified tool.
|
|
384
417
|
*
|
|
385
|
-
* @param toolName
|
|
418
|
+
* @param toolName The name of the tool to initialize.
|
|
386
419
|
* @returns A promise that resolves when the tool is initialized.
|
|
387
420
|
*/
|
|
388
421
|
async initTool(toolName) {
|
|
@@ -433,9 +466,9 @@ class FileLinter {
|
|
|
433
466
|
}
|
|
434
467
|
}
|
|
435
468
|
/**
|
|
436
|
-
*
|
|
469
|
+
* Lint files using `lint-staged` with the provided arguments.
|
|
437
470
|
*
|
|
438
|
-
* @param args
|
|
471
|
+
* @param args An array of arguments to pass to `lint-staged`.
|
|
439
472
|
* @returns The exit status of the `lint-staged` command.
|
|
440
473
|
*/
|
|
441
474
|
static lintStaged(args) {
|
|
@@ -528,9 +561,9 @@ class FileLinter {
|
|
|
528
561
|
return results;
|
|
529
562
|
}
|
|
530
563
|
/**
|
|
531
|
-
*
|
|
564
|
+
* Lint files matching the provided patterns using ESLint and Prettier.
|
|
532
565
|
*
|
|
533
|
-
* @param patterns
|
|
566
|
+
* @param patterns An array of glob patterns to match files against. Defaults to ['**'] which matches all files.
|
|
534
567
|
* @returns A promise that resolves to a LintFilesResult indicating the success or failure of the linting process.
|
|
535
568
|
*/
|
|
536
569
|
async lint(patterns = ["**"]) {
|
|
@@ -10,19 +10,19 @@ import * as Prettier from "prettier";
|
|
|
10
10
|
class CoreConfig {
|
|
11
11
|
static #packageName = "@cluerise/tools";
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Determine if the application is running in production mode.
|
|
14
14
|
*
|
|
15
|
-
* This
|
|
15
|
+
* This checks the environment variable `import.meta.env.PROD` to determine the mode.
|
|
16
16
|
*
|
|
17
|
-
* @returns True if in production mode, false
|
|
17
|
+
* @returns True if running in production mode, otherwise false.
|
|
18
18
|
*/
|
|
19
19
|
static get isProd() {
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Get the path to package configuration files in production.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
25
|
+
* Used to load configuration from the package when running in production.
|
|
26
26
|
*
|
|
27
27
|
* @returns The path to the configuration files in the package.
|
|
28
28
|
*/
|
|
@@ -33,10 +33,9 @@ class CoreConfig {
|
|
|
33
33
|
return this.isProd ? `./node_modules/${this.#packageName}` : ".";
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Get the directory path where configuration files are stored.
|
|
37
37
|
*
|
|
38
|
-
* In production
|
|
39
|
-
* In development mode, it points to the root directory.
|
|
38
|
+
* In production, this points to `dist/configs` in the package; in development, it points to the root directory.
|
|
40
39
|
*
|
|
41
40
|
* @returns The path to the configuration directory.
|
|
42
41
|
*/
|
|
@@ -46,13 +45,18 @@ class CoreConfig {
|
|
|
46
45
|
}
|
|
47
46
|
class ConsoleStatusLogger {
|
|
48
47
|
#command;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new logger for a specific command.
|
|
50
|
+
*
|
|
51
|
+
* @param command The command name to log.
|
|
52
|
+
*/
|
|
49
53
|
constructor(command) {
|
|
50
54
|
this.#command = command;
|
|
51
55
|
}
|
|
52
56
|
/**
|
|
53
|
-
*
|
|
57
|
+
* Log the beginning of a command with the provided argument.
|
|
54
58
|
*
|
|
55
|
-
* @param argument
|
|
59
|
+
* @param argument The argument for the command.
|
|
56
60
|
*
|
|
57
61
|
* @example
|
|
58
62
|
* const logger = new ConsoleStatusLogger('Linting');
|
|
@@ -68,10 +72,10 @@ class ConsoleStatusLogger {
|
|
|
68
72
|
return exitCode === 0 ? "OK" : "Failed";
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
71
|
-
*
|
|
75
|
+
* Log the end of a command with the provided argument and exit code.
|
|
72
76
|
*
|
|
73
|
-
* @param argument
|
|
74
|
-
* @param exitCode
|
|
77
|
+
* @param argument The argument for the command.
|
|
78
|
+
* @param exitCode The exit code of the command execution. If null, it indicates completion without an error.
|
|
75
79
|
*
|
|
76
80
|
* @example
|
|
77
81
|
* const logger = new ConsoleStatusLogger('Linting');
|
|
@@ -109,10 +113,12 @@ const runMain = (main2) => {
|
|
|
109
113
|
};
|
|
110
114
|
class StringUtils {
|
|
111
115
|
/**
|
|
112
|
-
*
|
|
116
|
+
* Capitalize the first letter of a given string.
|
|
113
117
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
118
|
+
* If the string is empty, it is returned unchanged.
|
|
119
|
+
*
|
|
120
|
+
* @param value The string to capitalize.
|
|
121
|
+
* @returns The string with the first letter capitalized, or the original string if empty.
|
|
116
122
|
*/
|
|
117
123
|
static capitalize(value) {
|
|
118
124
|
const [firstLetter] = value;
|
|
@@ -128,7 +134,7 @@ class CommitLinter {
|
|
|
128
134
|
this.#config = config;
|
|
129
135
|
}
|
|
130
136
|
/**
|
|
131
|
-
*
|
|
137
|
+
* Initialize the CommitLinter with the loaded commitlint configuration.
|
|
132
138
|
*
|
|
133
139
|
* @returns A Promise that resolves to an instance of CommitLinter.
|
|
134
140
|
*/
|
|
@@ -137,9 +143,9 @@ class CommitLinter {
|
|
|
137
143
|
return new CommitLinter(config);
|
|
138
144
|
}
|
|
139
145
|
/**
|
|
140
|
-
*
|
|
146
|
+
* Lint commit messages using commitlint.
|
|
141
147
|
*
|
|
142
|
-
* @param args
|
|
148
|
+
* @param args An array of arguments to pass to commitlint.
|
|
143
149
|
* @returns The exit status of the commitlint command.
|
|
144
150
|
*/
|
|
145
151
|
static lint(args) {
|
|
@@ -164,9 +170,9 @@ class CommitLinter {
|
|
|
164
170
|
return this.#isValidEnumValue("scope-enum", scope);
|
|
165
171
|
}
|
|
166
172
|
/**
|
|
167
|
-
*
|
|
173
|
+
* Parse a semantic branch name into its type and scope.
|
|
168
174
|
*
|
|
169
|
-
* @param name
|
|
175
|
+
* @param name The branch name to parse.
|
|
170
176
|
* @returns An object containing the type and scope of the commit message.
|
|
171
177
|
* @throws An error if the branch name is invalid.
|
|
172
178
|
*/
|
|
@@ -183,12 +189,13 @@ class CommitLinter {
|
|
|
183
189
|
};
|
|
184
190
|
}
|
|
185
191
|
/**
|
|
186
|
-
*
|
|
192
|
+
* Get the prefix of a semantic commit message as a string.
|
|
187
193
|
*
|
|
188
194
|
* This prefix consists of the type and scope of the commit message.
|
|
189
195
|
* If the scope is not provided, it will only return the type.
|
|
190
|
-
*
|
|
191
|
-
* @
|
|
196
|
+
*
|
|
197
|
+
* @param prefix An object containing the type and scope of the commit message.
|
|
198
|
+
* @returns The stringified prefix.
|
|
192
199
|
*/
|
|
193
200
|
static stringifySemanticCommitMessagePrefix({ type, scope }) {
|
|
194
201
|
return `${type}${scope ? `(${scope})` : ""}`;
|
|
@@ -200,9 +207,9 @@ class CommitLinter {
|
|
|
200
207
|
return { prefix, content };
|
|
201
208
|
}
|
|
202
209
|
/**
|
|
203
|
-
*
|
|
210
|
+
* Format a semantic commit message by capitalizing the content after the prefix.
|
|
204
211
|
*
|
|
205
|
-
* @param message
|
|
212
|
+
* @param message The commit message to format.
|
|
206
213
|
* @returns The formatted commit message.
|
|
207
214
|
*/
|
|
208
215
|
static formatSemanticCommitMessage(message) {
|
|
@@ -213,20 +220,20 @@ class CommitLinter {
|
|
|
213
220
|
return `${prefix}: ${StringUtils.capitalize(content)}`;
|
|
214
221
|
}
|
|
215
222
|
/**
|
|
216
|
-
*
|
|
223
|
+
* Create a semantic commit message from a prefix and a message.
|
|
217
224
|
*
|
|
218
|
-
* @param prefix
|
|
219
|
-
* @param message
|
|
225
|
+
* @param prefix The prefix of the commit message, containing type and scope.
|
|
226
|
+
* @param message The content of the commit message.
|
|
220
227
|
* @returns The formatted semantic commit message.
|
|
221
228
|
*/
|
|
222
229
|
static createSemanticCommitMessage(prefix, message) {
|
|
223
230
|
const [subject, ...comments] = message.split("\n#");
|
|
224
231
|
let commitMessage = this.stringifySemanticCommitMessagePrefix(prefix) + ": ";
|
|
225
232
|
if (subject) {
|
|
226
|
-
commitMessage += StringUtils.capitalize(subject);
|
|
233
|
+
commitMessage += StringUtils.capitalize(subject.trim());
|
|
227
234
|
}
|
|
228
235
|
if (comments.length > 0) {
|
|
229
|
-
commitMessage += "\n\n#" + comments.join("\n#");
|
|
236
|
+
commitMessage += "\n\n#" + comments.map((comment) => comment.trim()).join("\n#");
|
|
230
237
|
}
|
|
231
238
|
return commitMessage;
|
|
232
239
|
}
|
|
@@ -248,9 +255,9 @@ class FileLinter {
|
|
|
248
255
|
}
|
|
249
256
|
}
|
|
250
257
|
/**
|
|
251
|
-
*
|
|
258
|
+
* Lint files using `lint-staged` with the provided arguments.
|
|
252
259
|
*
|
|
253
|
-
* @param args
|
|
260
|
+
* @param args An array of arguments to pass to `lint-staged`.
|
|
254
261
|
* @returns The exit status of the `lint-staged` command.
|
|
255
262
|
*/
|
|
256
263
|
static lintStaged(args) {
|
|
@@ -343,9 +350,9 @@ class FileLinter {
|
|
|
343
350
|
return results;
|
|
344
351
|
}
|
|
345
352
|
/**
|
|
346
|
-
*
|
|
353
|
+
* Lint files matching the provided patterns using ESLint and Prettier.
|
|
347
354
|
*
|
|
348
|
-
* @param patterns
|
|
355
|
+
* @param patterns An array of glob patterns to match files against. Defaults to ['**'] which matches all files.
|
|
349
356
|
* @returns A promise that resolves to a LintFilesResult indicating the success or failure of the linting process.
|
|
350
357
|
*/
|
|
351
358
|
async lint(patterns = ["**"]) {
|