@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.
@@ -11,19 +11,19 @@ import * as Prettier from "prettier";
11
11
  class CoreConfig {
12
12
  static #packageName = "@cluerise/tools";
13
13
  /**
14
- * Determines if the application is running in production mode.
14
+ * Determine if the application is running in production mode.
15
15
  *
16
- * This is based on the environment variable `import.meta.env.PROD`.
16
+ * This checks the environment variable `import.meta.env.PROD` to determine the mode.
17
17
  *
18
- * @returns True if in production mode, false otherwise.
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
- * Returns the package and its path to the configuration files.
24
+ * Get the path to package configuration files in production.
25
25
  *
26
- * This is used to load configurations from the package in production mode.
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
- * Returns the directory where configuration files are stored.
37
+ * Get the directory path where configuration files are stored.
38
38
  *
39
- * In production mode, this points to the `dist/configs` directory within the package.
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
- * Begins logging for a command with the specified argument.
58
+ * Log the beginning of a command with the provided argument.
55
59
  *
56
- * @param argument - The argument for the command.
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
- * Ends logging for a command with the specified argument and exit code.
76
+ * Log the end of a command with the provided argument and exit code.
73
77
  *
74
- * @param argument - The argument for the command.
75
- * @param exitCode - The exit code of the command execution. If null, it indicates completion without an error.
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
- * Checks if the provided name is a valid Git provider name.
98
+ * Check if the provided name is a valid Git provider name.
95
99
  *
96
- * @param name - The name of the Git provider to validate.
97
- * @returns True if the name is valid, false otherwise.
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
- * Returns a Git provider origin.
107
+ * Get the origin URL for the given Git provider name.
104
108
  *
105
- * @param name - The name of the Git provider.
106
- * @returns The origin URL of the Git provider.
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
- * Returns the required engines.
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
- * Sets the required engines.
180
+ * Set the engines field in `package.json`.
152
181
  *
153
- * @param engines - The engines to set.
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
- * Returns the repository information.
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
- * Parses the repository information from package.json.
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 no repository is defined.
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
- * Saves the package.json file with the current data.
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
- * Returns the names of all available tools.
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
- * Initializes the specified tool.
416
+ * Initialize the specified tool.
384
417
  *
385
- * @param toolName - The name of the tool to initialize.
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
- * Lints files using `lint-staged` with the provided arguments.
469
+ * Lint files using `lint-staged` with the provided arguments.
437
470
  *
438
- * @param args - An array of arguments to pass to `lint-staged`.
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
- * Lints files matching the provided patterns using ESLint and Prettier.
564
+ * Lint files matching the provided patterns using ESLint and Prettier.
532
565
  *
533
- * @param patterns - An array of glob patterns to match files against. Defaults to ['**'] which matches all files.
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
- * Determines if the application is running in production mode.
13
+ * Determine if the application is running in production mode.
14
14
  *
15
- * This is based on the environment variable `import.meta.env.PROD`.
15
+ * This checks the environment variable `import.meta.env.PROD` to determine the mode.
16
16
  *
17
- * @returns True if in production mode, false otherwise.
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
- * Returns the package and its path to the configuration files.
23
+ * Get the path to package configuration files in production.
24
24
  *
25
- * This is used to load configurations from the package in production mode.
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
- * Returns the directory where configuration files are stored.
36
+ * Get the directory path where configuration files are stored.
37
37
  *
38
- * In production mode, this points to the `dist/configs` directory within the package.
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
- * Begins logging for a command with the specified argument.
57
+ * Log the beginning of a command with the provided argument.
54
58
  *
55
- * @param argument - The argument for the command.
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
- * Ends logging for a command with the specified argument and exit code.
75
+ * Log the end of a command with the provided argument and exit code.
72
76
  *
73
- * @param argument - The argument for the command.
74
- * @param exitCode - The exit code of the command execution. If null, it indicates completion without an error.
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
- * Capitalizes the first letter of a given string.
116
+ * Capitalize the first letter of a given string.
113
117
  *
114
- * @param value - The string to capitalize.
115
- * @returns The string with the first letter capitalized.
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
- * Initializes the CommitLinter with the loaded commitlint configuration.
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
- * Lints commit messages using commitlint.
146
+ * Lint commit messages using commitlint.
141
147
  *
142
- * @param args - An array of arguments to pass to commitlint.
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
- * Parses a semantic branch name into its type and scope.
173
+ * Parse a semantic branch name into its type and scope.
168
174
  *
169
- * @param name - The branch name to parse.
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
- * Returns the prefix of a semantic commit message as a string.
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
- * @param prefix - An object containing the type and scope of the commit message.
191
- * @returns
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
- * Formats a semantic commit message by capitalizing the content after the prefix.
210
+ * Format a semantic commit message by capitalizing the content after the prefix.
204
211
  *
205
- * @param message - The commit message to format.
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
- * Creates a semantic commit message from a prefix and a message.
223
+ * Create a semantic commit message from a prefix and a message.
217
224
  *
218
- * @param prefix - The prefix of the commit message, containing type and scope.
219
- * @param message - The content of the commit 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
- * Lints files using `lint-staged` with the provided arguments.
258
+ * Lint files using `lint-staged` with the provided arguments.
252
259
  *
253
- * @param args - An array of arguments to pass to `lint-staged`.
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
- * Lints files matching the provided patterns using ESLint and Prettier.
353
+ * Lint files matching the provided patterns using ESLint and Prettier.
347
354
  *
348
- * @param patterns - An array of glob patterns to match files against. Defaults to ['**'] which matches all files.
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 = ["**"]) {