@cluerise/tools 4.1.1 → 4.2.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 +3 -3
- package/dist/configs/eslint.config.js +1 -4
- package/dist/configs/pnpm-workspace.yaml +3 -0
- package/dist/configs/prettier.config.js +1 -0
- package/dist/configs/release.config.js +10 -1
- package/dist/scripts/check-heroku-node-version/main.js +51 -69
- package/dist/scripts/create-commit-message/main.js +31 -46
- package/dist/scripts/format-commit-message/main.js +31 -46
- package/dist/scripts/init/main.js +284 -319
- package/dist/scripts/lint/main.js +152 -182
- package/dist/scripts/release/assets/index-BOULatd3.js +50541 -0
- package/dist/scripts/release/main.js +34222 -174
- package/dist/scripts/update-node-versions/main.js +53 -71
- package/package.json +15 -14
|
@@ -1,12 +1,3 @@
|
|
|
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 _packageName, _CoreConfig_static, rootDirectory_get, _command, _ConsoleStatusLogger_static, createResultMessage_fn, _origins, _names, _data, _PackageJson_instances, parseGitRepository_fn, _configDirectory, _configPackage, _ToolInitializer_instances, initCommitlint_fn, initEditorConfig_fn, initESLint_fn, initGit_fn, initLintStaged_fn, initNvm_fn, initPnpm_fn, initPrettier_fn, getReleaseConfigParams_fn, initRelease_fn, initTypeScript_fn, initVSCode_fn, _options, _eslint, _eslintFixer, _FileLinter_static, preparePrettierLintResult_fn, _FileLinter_instances, prettierLint_fn, prepareESLintLintResult_fn, eslintLint_fn;
|
|
10
1
|
import { z, ZodError } from "zod";
|
|
11
2
|
import Path from "node:path";
|
|
12
3
|
import FileSystem from "node:fs/promises";
|
|
@@ -18,6 +9,7 @@ import { ESLint } from "eslint";
|
|
|
18
9
|
import { glob } from "glob";
|
|
19
10
|
import * as Prettier from "prettier";
|
|
20
11
|
class CoreConfig {
|
|
12
|
+
static #packageName = "@cluerise/tools";
|
|
21
13
|
/**
|
|
22
14
|
* Determines if the application is running in production mode.
|
|
23
15
|
*
|
|
@@ -36,7 +28,10 @@ class CoreConfig {
|
|
|
36
28
|
* @returns The path to the configuration files in the package.
|
|
37
29
|
*/
|
|
38
30
|
static get configPackage() {
|
|
39
|
-
return `${
|
|
31
|
+
return `${this.#packageName}/dist/configs`;
|
|
32
|
+
}
|
|
33
|
+
static get #rootDirectory() {
|
|
34
|
+
return this.isProd ? `./node_modules/${this.#packageName}` : ".";
|
|
40
35
|
}
|
|
41
36
|
/**
|
|
42
37
|
* Returns the directory where configuration files are stored.
|
|
@@ -47,20 +42,13 @@ class CoreConfig {
|
|
|
47
42
|
* @returns The path to the configuration directory.
|
|
48
43
|
*/
|
|
49
44
|
static get configDirectory() {
|
|
50
|
-
return this.isProd ? `${
|
|
45
|
+
return this.isProd ? `${this.#rootDirectory}/dist/configs` : this.#rootDirectory;
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
rootDirectory_get = function() {
|
|
56
|
-
return this.isProd ? `./node_modules/${__privateGet(this, _packageName)}` : ".";
|
|
57
|
-
};
|
|
58
|
-
__privateAdd(CoreConfig, _CoreConfig_static);
|
|
59
|
-
__privateAdd(CoreConfig, _packageName, "@cluerise/tools");
|
|
60
|
-
const _ConsoleStatusLogger = class _ConsoleStatusLogger {
|
|
48
|
+
class ConsoleStatusLogger {
|
|
49
|
+
#command;
|
|
61
50
|
constructor(command) {
|
|
62
|
-
|
|
63
|
-
__privateSet(this, _command, command);
|
|
51
|
+
this.#command = command;
|
|
64
52
|
}
|
|
65
53
|
/**
|
|
66
54
|
* Begins logging for a command with the specified argument.
|
|
@@ -72,7 +60,13 @@ const _ConsoleStatusLogger = class _ConsoleStatusLogger {
|
|
|
72
60
|
* logger.begin('src/index.ts'); // Logs: "Linting src/index.ts..."
|
|
73
61
|
*/
|
|
74
62
|
begin(argument) {
|
|
75
|
-
console.info(`${
|
|
63
|
+
console.info(`${this.#command} ${argument}...`);
|
|
64
|
+
}
|
|
65
|
+
static #createResultMessage(exitCode) {
|
|
66
|
+
if (exitCode === null) {
|
|
67
|
+
return "Done";
|
|
68
|
+
}
|
|
69
|
+
return exitCode === 0 ? "OK" : "Failed";
|
|
76
70
|
}
|
|
77
71
|
/**
|
|
78
72
|
* Ends logging for a command with the specified argument and exit code.
|
|
@@ -87,24 +81,15 @@ const _ConsoleStatusLogger = class _ConsoleStatusLogger {
|
|
|
87
81
|
* logger.end('src/index.ts', 1); // Logs: "Linting src/index.ts... Failed"
|
|
88
82
|
*/
|
|
89
83
|
end(argument, exitCode = null) {
|
|
90
|
-
|
|
91
|
-
console.info(`${__privateGet(this, _command)} ${argument}... ${__privateMethod(_a = _ConsoleStatusLogger, _ConsoleStatusLogger_static, createResultMessage_fn).call(_a, exitCode)}`);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
_command = new WeakMap();
|
|
95
|
-
_ConsoleStatusLogger_static = new WeakSet();
|
|
96
|
-
createResultMessage_fn = function(exitCode) {
|
|
97
|
-
if (exitCode === null) {
|
|
98
|
-
return "Done";
|
|
84
|
+
console.info(`${this.#command} ${argument}... ${ConsoleStatusLogger.#createResultMessage(exitCode)}`);
|
|
99
85
|
}
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
__privateAdd(_ConsoleStatusLogger, _ConsoleStatusLogger_static);
|
|
103
|
-
let ConsoleStatusLogger = _ConsoleStatusLogger;
|
|
86
|
+
}
|
|
104
87
|
const gitProviderOrigins = {
|
|
105
88
|
github: "https://github.com"
|
|
106
89
|
};
|
|
107
|
-
|
|
90
|
+
class GitProvider {
|
|
91
|
+
static #origins = gitProviderOrigins;
|
|
92
|
+
static #names = Object.keys(this.#origins);
|
|
108
93
|
/**
|
|
109
94
|
* Checks if the provided name is a valid Git provider name.
|
|
110
95
|
*
|
|
@@ -112,7 +97,7 @@ const _GitProvider = class _GitProvider {
|
|
|
112
97
|
* @returns True if the name is valid, false otherwise.
|
|
113
98
|
*/
|
|
114
99
|
static isValidName(name) {
|
|
115
|
-
return
|
|
100
|
+
return this.#names.includes(name);
|
|
116
101
|
}
|
|
117
102
|
/**
|
|
118
103
|
* Returns a Git provider origin.
|
|
@@ -121,14 +106,9 @@ const _GitProvider = class _GitProvider {
|
|
|
121
106
|
* @returns The origin URL of the Git provider.
|
|
122
107
|
*/
|
|
123
108
|
static getOrigin(name) {
|
|
124
|
-
return
|
|
109
|
+
return this.#origins[name];
|
|
125
110
|
}
|
|
126
|
-
}
|
|
127
|
-
_origins = new WeakMap();
|
|
128
|
-
_names = new WeakMap();
|
|
129
|
-
__privateAdd(_GitProvider, _origins, gitProviderOrigins);
|
|
130
|
-
__privateAdd(_GitProvider, _names, Object.keys(__privateGet(_GitProvider, _origins)));
|
|
131
|
-
let GitProvider = _GitProvider;
|
|
111
|
+
}
|
|
132
112
|
const enginesSchema = z.object({
|
|
133
113
|
node: z.string()
|
|
134
114
|
});
|
|
@@ -145,11 +125,10 @@ const packageJsonDataSchema = z.object({
|
|
|
145
125
|
engines: enginesSchema.optional(),
|
|
146
126
|
repository: repositorySchema.optional()
|
|
147
127
|
});
|
|
148
|
-
|
|
128
|
+
class PackageJson {
|
|
129
|
+
#data;
|
|
149
130
|
constructor(data) {
|
|
150
|
-
|
|
151
|
-
__privateAdd(this, _data);
|
|
152
|
-
__privateSet(this, _data, data);
|
|
131
|
+
this.#data = data;
|
|
153
132
|
}
|
|
154
133
|
static async init() {
|
|
155
134
|
const content = await FileSystem.readFile("package.json", { encoding: "utf8" });
|
|
@@ -160,13 +139,13 @@ const _PackageJson = class _PackageJson {
|
|
|
160
139
|
cause: parseResult.error
|
|
161
140
|
});
|
|
162
141
|
}
|
|
163
|
-
return new
|
|
142
|
+
return new PackageJson(data);
|
|
164
143
|
}
|
|
165
144
|
/**
|
|
166
145
|
* Returns the required engines.
|
|
167
146
|
*/
|
|
168
147
|
get engines() {
|
|
169
|
-
return
|
|
148
|
+
return this.#data.engines;
|
|
170
149
|
}
|
|
171
150
|
/**
|
|
172
151
|
* Sets the required engines.
|
|
@@ -174,13 +153,44 @@ const _PackageJson = class _PackageJson {
|
|
|
174
153
|
* @param engines - The engines to set.
|
|
175
154
|
*/
|
|
176
155
|
set engines(engines) {
|
|
177
|
-
|
|
156
|
+
this.#data.engines = engines;
|
|
178
157
|
}
|
|
179
158
|
/**
|
|
180
159
|
* Returns the repository information.
|
|
181
160
|
*/
|
|
182
161
|
get repository() {
|
|
183
|
-
return
|
|
162
|
+
return this.#data.repository;
|
|
163
|
+
}
|
|
164
|
+
#parseGitRepository(urlString) {
|
|
165
|
+
if (!urlString) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const urlValue = urlString.includes(":") ? urlString : `https://${urlString}`;
|
|
169
|
+
const url = new URL(urlValue);
|
|
170
|
+
const scheme = url.protocol.slice(0, -1);
|
|
171
|
+
if (GitProvider.isValidName(scheme)) {
|
|
172
|
+
const [owner, repositoryName] = url.pathname.split("/");
|
|
173
|
+
if (!owner || !repositoryName) {
|
|
174
|
+
throw new Error("Unknown owner or repositoryName");
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
origin: GitProvider.getOrigin(scheme),
|
|
178
|
+
owner,
|
|
179
|
+
repositoryName
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (scheme === "https") {
|
|
183
|
+
const [, owner, repositoryName] = url.pathname.split("/");
|
|
184
|
+
if (!owner || !repositoryName) {
|
|
185
|
+
throw new Error("Unknown owner or repositoryName");
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
origin: url.origin,
|
|
189
|
+
owner,
|
|
190
|
+
repositoryName: repositoryName.endsWith(".git") ? repositoryName.slice(0, -4) : repositoryName
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
throw new Error("Unsupported repository URL");
|
|
184
194
|
}
|
|
185
195
|
/**
|
|
186
196
|
* Parses the repository information from package.json.
|
|
@@ -192,52 +202,18 @@ const _PackageJson = class _PackageJson {
|
|
|
192
202
|
return null;
|
|
193
203
|
}
|
|
194
204
|
if (typeof this.repository === "string") {
|
|
195
|
-
return
|
|
205
|
+
return this.#parseGitRepository(this.repository);
|
|
196
206
|
}
|
|
197
|
-
return
|
|
207
|
+
return this.#parseGitRepository(this.repository.url);
|
|
198
208
|
}
|
|
199
209
|
/**
|
|
200
210
|
* Saves the package.json file with the current data.
|
|
201
211
|
*/
|
|
202
212
|
async save() {
|
|
203
|
-
const content = JsonUtils.prettify(
|
|
213
|
+
const content = JsonUtils.prettify(this.#data) + "\n";
|
|
204
214
|
await FileSystem.writeFile("package.json", content, { encoding: "utf8" });
|
|
205
215
|
}
|
|
206
|
-
}
|
|
207
|
-
_data = new WeakMap();
|
|
208
|
-
_PackageJson_instances = new WeakSet();
|
|
209
|
-
parseGitRepository_fn = function(urlString) {
|
|
210
|
-
if (!urlString) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
const urlValue = urlString.includes(":") ? urlString : `https://${urlString}`;
|
|
214
|
-
const url = new URL(urlValue);
|
|
215
|
-
const scheme = url.protocol.slice(0, -1);
|
|
216
|
-
if (GitProvider.isValidName(scheme)) {
|
|
217
|
-
const [owner, repositoryName] = url.pathname.split("/");
|
|
218
|
-
if (!owner || !repositoryName) {
|
|
219
|
-
throw new Error("Unknown owner or repositoryName");
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
origin: GitProvider.getOrigin(scheme),
|
|
223
|
-
owner,
|
|
224
|
-
repositoryName
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
if (scheme === "https") {
|
|
228
|
-
const [, owner, repositoryName] = url.pathname.split("/");
|
|
229
|
-
if (!owner || !repositoryName) {
|
|
230
|
-
throw new Error("Unknown owner or repositoryName");
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
origin: url.origin,
|
|
234
|
-
owner,
|
|
235
|
-
repositoryName: repositoryName.endsWith(".git") ? repositoryName.slice(0, -4) : repositoryName
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
throw new Error("Unsupported repository URL");
|
|
239
|
-
};
|
|
240
|
-
let PackageJson = _PackageJson;
|
|
216
|
+
}
|
|
241
217
|
const runMain = (main2) => {
|
|
242
218
|
Promise.resolve().then(() => main2(process.argv.slice(2))).then((exitCode) => {
|
|
243
219
|
process.exit(exitCode);
|
|
@@ -289,12 +265,11 @@ const toolNameSchema = z.union([
|
|
|
289
265
|
z.literal("vscode")
|
|
290
266
|
]);
|
|
291
267
|
class ToolInitializer {
|
|
268
|
+
#configDirectory;
|
|
269
|
+
#configPackage;
|
|
292
270
|
constructor(configDirectory, configPackage) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
__privateAdd(this, _configPackage);
|
|
296
|
-
__privateSet(this, _configDirectory, configDirectory);
|
|
297
|
-
__privateSet(this, _configPackage, configPackage);
|
|
271
|
+
this.#configDirectory = configDirectory;
|
|
272
|
+
this.#configPackage = configPackage;
|
|
298
273
|
}
|
|
299
274
|
/**
|
|
300
275
|
* Returns the names of all available tools.
|
|
@@ -304,6 +279,106 @@ class ToolInitializer {
|
|
|
304
279
|
get toolNames() {
|
|
305
280
|
return toolNameSchema.options.map((option) => option.value);
|
|
306
281
|
}
|
|
282
|
+
async #initCommitlint() {
|
|
283
|
+
const configName = "commitlint.config";
|
|
284
|
+
const configPath = `${configName}.ts`;
|
|
285
|
+
const configContent = `export { default } from '${this.#configPackage}/${configName}';
|
|
286
|
+
`;
|
|
287
|
+
await FileUtils.createFile(configPath, configContent);
|
|
288
|
+
}
|
|
289
|
+
async #initEditorConfig() {
|
|
290
|
+
await FileUtils.copyFile(this.#configDirectory, ".editorconfig");
|
|
291
|
+
}
|
|
292
|
+
async #initESLint() {
|
|
293
|
+
const configPath = "eslint.config.js";
|
|
294
|
+
const markdownConfigPath = "eslint-markdown.config.js";
|
|
295
|
+
const configContent = `export { default } from '${this.#configPackage}/${configPath}';
|
|
296
|
+
`;
|
|
297
|
+
const markdownConfigContent = `export { default } from '${this.#configPackage}/${markdownConfigPath}';
|
|
298
|
+
`;
|
|
299
|
+
await FileUtils.createFile(configPath, configContent);
|
|
300
|
+
await FileUtils.createFile(markdownConfigPath, markdownConfigContent);
|
|
301
|
+
}
|
|
302
|
+
async #initGit() {
|
|
303
|
+
const sourceGitignorePath = "_gitignore";
|
|
304
|
+
const destinationGitignorePath = ".gitignore";
|
|
305
|
+
await FileUtils.copyFile(this.#configDirectory, sourceGitignorePath, destinationGitignorePath);
|
|
306
|
+
const gitHookDirectory = "hooks";
|
|
307
|
+
const gitHookPaths = [
|
|
308
|
+
Path.join(gitHookDirectory, "commit-msg"),
|
|
309
|
+
Path.join(gitHookDirectory, "post-commit"),
|
|
310
|
+
Path.join(gitHookDirectory, "pre-commit"),
|
|
311
|
+
Path.join(gitHookDirectory, "prepare-commit-msg")
|
|
312
|
+
];
|
|
313
|
+
await Promise.all(
|
|
314
|
+
gitHookPaths.map((gitHookPath) => FileUtils.copyFile(this.#configDirectory, gitHookPath, void 0, 493))
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
async #initLintStaged() {
|
|
318
|
+
const configPath = "lint-staged.config.js";
|
|
319
|
+
const configContent = `export { default } from '${this.#configPackage}/${configPath}';
|
|
320
|
+
`;
|
|
321
|
+
await FileUtils.createFile(configPath, configContent);
|
|
322
|
+
}
|
|
323
|
+
async #initNvm() {
|
|
324
|
+
await FileUtils.copyFile(this.#configDirectory, ".nvmrc");
|
|
325
|
+
}
|
|
326
|
+
async #initPnpm() {
|
|
327
|
+
const workspacePath = "pnpm-workspace.yaml";
|
|
328
|
+
const workspaceContent = "engineStrict: true\n\npublicHoistPattern:\n - '@commitlint/cli'\n - eslint\n - lint-staged\n - prettier\n";
|
|
329
|
+
await FileUtils.createFile(workspacePath, workspaceContent);
|
|
330
|
+
}
|
|
331
|
+
async #initPrettier() {
|
|
332
|
+
const configPath = "prettier.config.js";
|
|
333
|
+
const configContent = `export { default } from '${this.#configPackage}/${configPath}';
|
|
334
|
+
`;
|
|
335
|
+
await FileUtils.createFile(configPath, configContent);
|
|
336
|
+
await FileUtils.copyFile(this.#configDirectory, ".prettierignore");
|
|
337
|
+
}
|
|
338
|
+
async #getReleaseConfigParams() {
|
|
339
|
+
const defaultConfigParams = {
|
|
340
|
+
host: "<host>",
|
|
341
|
+
owner: "<owner>",
|
|
342
|
+
repository: "<repository>"
|
|
343
|
+
};
|
|
344
|
+
try {
|
|
345
|
+
const packageJson = await PackageJson.init();
|
|
346
|
+
const repository = packageJson.parseGitRepository();
|
|
347
|
+
if (!repository) {
|
|
348
|
+
return defaultConfigParams;
|
|
349
|
+
}
|
|
350
|
+
const { origin, owner, repositoryName } = repository;
|
|
351
|
+
return {
|
|
352
|
+
host: origin,
|
|
353
|
+
owner,
|
|
354
|
+
repository: repositoryName
|
|
355
|
+
};
|
|
356
|
+
} catch {
|
|
357
|
+
return defaultConfigParams;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
async #initRelease() {
|
|
361
|
+
const configPath = "release.config.js";
|
|
362
|
+
const configParams = await this.#getReleaseConfigParams();
|
|
363
|
+
const configContent = `import { createReleaseConfig } from '${this.#configPackage}/${configPath}';
|
|
364
|
+
|
|
365
|
+
export default createReleaseConfig(${JsonUtils.prettify(configParams)});
|
|
366
|
+
`;
|
|
367
|
+
await FileUtils.createFile(configPath, configContent);
|
|
368
|
+
}
|
|
369
|
+
async #initTypeScript() {
|
|
370
|
+
const configPath = "tsconfig.json";
|
|
371
|
+
const configContent = `{
|
|
372
|
+
"extends": "${this.#configDirectory}/${configPath}"
|
|
373
|
+
}
|
|
374
|
+
`;
|
|
375
|
+
await FileUtils.createFile(configPath, configContent);
|
|
376
|
+
}
|
|
377
|
+
async #initVSCode() {
|
|
378
|
+
const settingsPath = Path.join(".vscode", "settings.json");
|
|
379
|
+
const settingsContent = '{\n "editor.codeActionsOnSave": {\n "source.fixAll.eslint": "explicit"\n },\n "typescript.tsdk": "node_modules/typescript/lib"\n}\n';
|
|
380
|
+
await FileUtils.createFile(settingsPath, settingsContent);
|
|
381
|
+
}
|
|
307
382
|
/**
|
|
308
383
|
* Initializes the specified tool.
|
|
309
384
|
*
|
|
@@ -313,27 +388,27 @@ class ToolInitializer {
|
|
|
313
388
|
async initTool(toolName) {
|
|
314
389
|
switch (toolName) {
|
|
315
390
|
case "commitlint":
|
|
316
|
-
return
|
|
391
|
+
return this.#initCommitlint();
|
|
317
392
|
case "editorconfig":
|
|
318
|
-
return
|
|
393
|
+
return this.#initEditorConfig();
|
|
319
394
|
case "eslint":
|
|
320
|
-
return
|
|
395
|
+
return this.#initESLint();
|
|
321
396
|
case "git":
|
|
322
|
-
return
|
|
397
|
+
return this.#initGit();
|
|
323
398
|
case "lint-staged":
|
|
324
|
-
return
|
|
399
|
+
return this.#initLintStaged();
|
|
325
400
|
case "nvm":
|
|
326
|
-
return
|
|
401
|
+
return this.#initNvm();
|
|
327
402
|
case "pnpm":
|
|
328
|
-
return
|
|
403
|
+
return this.#initPnpm();
|
|
329
404
|
case "prettier":
|
|
330
|
-
return
|
|
405
|
+
return this.#initPrettier();
|
|
331
406
|
case "release":
|
|
332
|
-
return
|
|
407
|
+
return this.#initRelease();
|
|
333
408
|
case "typescript":
|
|
334
|
-
return
|
|
409
|
+
return this.#initTypeScript();
|
|
335
410
|
case "vscode":
|
|
336
|
-
return
|
|
411
|
+
return this.#initVSCode();
|
|
337
412
|
default: {
|
|
338
413
|
const unhandledToolName = toolName;
|
|
339
414
|
throw new Error(`Unknown tool name: ${unhandledToolName}`);
|
|
@@ -341,124 +416,20 @@ class ToolInitializer {
|
|
|
341
416
|
}
|
|
342
417
|
}
|
|
343
418
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const configName = "commitlint.config";
|
|
349
|
-
const configPath = `${configName}.ts`;
|
|
350
|
-
const configContent = `export { default } from '${__privateGet(this, _configPackage)}/${configName}';
|
|
351
|
-
`;
|
|
352
|
-
await FileUtils.createFile(configPath, configContent);
|
|
353
|
-
};
|
|
354
|
-
initEditorConfig_fn = async function() {
|
|
355
|
-
await FileUtils.copyFile(__privateGet(this, _configDirectory), ".editorconfig");
|
|
356
|
-
};
|
|
357
|
-
initESLint_fn = async function() {
|
|
358
|
-
const configPath = "eslint.config.js";
|
|
359
|
-
const markdownConfigPath = "eslint-markdown.config.js";
|
|
360
|
-
const configContent = `export { default } from '${__privateGet(this, _configPackage)}/${configPath}';
|
|
361
|
-
`;
|
|
362
|
-
const markdownConfigContent = `export { default } from '${__privateGet(this, _configPackage)}/${markdownConfigPath}';
|
|
363
|
-
`;
|
|
364
|
-
await FileUtils.createFile(configPath, configContent);
|
|
365
|
-
await FileUtils.createFile(markdownConfigPath, markdownConfigContent);
|
|
366
|
-
};
|
|
367
|
-
initGit_fn = async function() {
|
|
368
|
-
const sourceGitignorePath = "_gitignore";
|
|
369
|
-
const destinationGitignorePath = ".gitignore";
|
|
370
|
-
await FileUtils.copyFile(__privateGet(this, _configDirectory), sourceGitignorePath, destinationGitignorePath);
|
|
371
|
-
const gitHookDirectory = "hooks";
|
|
372
|
-
const gitHookPaths = [
|
|
373
|
-
Path.join(gitHookDirectory, "commit-msg"),
|
|
374
|
-
Path.join(gitHookDirectory, "post-commit"),
|
|
375
|
-
Path.join(gitHookDirectory, "pre-commit"),
|
|
376
|
-
Path.join(gitHookDirectory, "prepare-commit-msg")
|
|
377
|
-
];
|
|
378
|
-
await Promise.all(
|
|
379
|
-
gitHookPaths.map((gitHookPath) => FileUtils.copyFile(__privateGet(this, _configDirectory), gitHookPath, void 0, 493))
|
|
380
|
-
);
|
|
381
|
-
};
|
|
382
|
-
initLintStaged_fn = async function() {
|
|
383
|
-
const configPath = "lint-staged.config.js";
|
|
384
|
-
const configContent = `export { default } from '${__privateGet(this, _configPackage)}/${configPath}';
|
|
385
|
-
`;
|
|
386
|
-
await FileUtils.createFile(configPath, configContent);
|
|
387
|
-
};
|
|
388
|
-
initNvm_fn = async function() {
|
|
389
|
-
await FileUtils.copyFile(__privateGet(this, _configDirectory), ".nvmrc");
|
|
390
|
-
};
|
|
391
|
-
initPnpm_fn = async function() {
|
|
392
|
-
const workspacePath = "pnpm-workspace.yaml";
|
|
393
|
-
const workspaceContent = "engineStrict: true\n\npublicHoistPattern:\n - '@commitlint/cli'\n - eslint\n - lint-staged\n - prettier\n";
|
|
394
|
-
await FileUtils.createFile(workspacePath, workspaceContent);
|
|
395
|
-
};
|
|
396
|
-
initPrettier_fn = async function() {
|
|
397
|
-
const configPath = "prettier.config.js";
|
|
398
|
-
const configContent = `export { default } from '${__privateGet(this, _configPackage)}/${configPath}';
|
|
399
|
-
`;
|
|
400
|
-
await FileUtils.createFile(configPath, configContent);
|
|
401
|
-
await FileUtils.copyFile(__privateGet(this, _configDirectory), ".prettierignore");
|
|
402
|
-
};
|
|
403
|
-
getReleaseConfigParams_fn = async function() {
|
|
404
|
-
const defaultConfigParams = {
|
|
405
|
-
host: "<host>",
|
|
406
|
-
owner: "<owner>",
|
|
407
|
-
repository: "<repository>"
|
|
408
|
-
};
|
|
409
|
-
try {
|
|
410
|
-
const packageJson = await PackageJson.init();
|
|
411
|
-
const repository = packageJson.parseGitRepository();
|
|
412
|
-
if (!repository) {
|
|
413
|
-
return defaultConfigParams;
|
|
414
|
-
}
|
|
415
|
-
const { origin, owner, repositoryName } = repository;
|
|
416
|
-
return {
|
|
417
|
-
host: origin,
|
|
418
|
-
owner,
|
|
419
|
-
repository: repositoryName
|
|
420
|
-
};
|
|
421
|
-
} catch {
|
|
422
|
-
return defaultConfigParams;
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
initRelease_fn = async function() {
|
|
426
|
-
const configPath = "release.config.js";
|
|
427
|
-
const configParams = await __privateMethod(this, _ToolInitializer_instances, getReleaseConfigParams_fn).call(this);
|
|
428
|
-
const configContent = `import { createReleaseConfig } from '${__privateGet(this, _configPackage)}/${configPath}';
|
|
429
|
-
|
|
430
|
-
export default createReleaseConfig(${JsonUtils.prettify(configParams)});
|
|
431
|
-
`;
|
|
432
|
-
await FileUtils.createFile(configPath, configContent);
|
|
433
|
-
};
|
|
434
|
-
initTypeScript_fn = async function() {
|
|
435
|
-
const configPath = "tsconfig.json";
|
|
436
|
-
const configContent = `{
|
|
437
|
-
"extends": "${__privateGet(this, _configDirectory)}/${configPath}"
|
|
438
|
-
}
|
|
439
|
-
`;
|
|
440
|
-
await FileUtils.createFile(configPath, configContent);
|
|
441
|
-
};
|
|
442
|
-
initVSCode_fn = async function() {
|
|
443
|
-
const settingsPath = Path.join(".vscode", "settings.json");
|
|
444
|
-
const settingsContent = '{\n "editor.codeActionsOnSave": {\n "source.fixAll.eslint": "explicit"\n },\n "typescript.tsdk": "node_modules/typescript/lib"\n}\n';
|
|
445
|
-
await FileUtils.createFile(settingsPath, settingsContent);
|
|
446
|
-
};
|
|
447
|
-
const _FileLinter = class _FileLinter {
|
|
419
|
+
class FileLinter {
|
|
420
|
+
#options;
|
|
421
|
+
#eslint;
|
|
422
|
+
#eslintFixer = null;
|
|
448
423
|
constructor(options) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
overrideConfigFile: options == null ? void 0 : options.configPath
|
|
456
|
-
}));
|
|
457
|
-
if (options == null ? void 0 : options.fix) {
|
|
458
|
-
__privateSet(this, _eslintFixer, new ESLint({
|
|
424
|
+
this.#options = options ?? null;
|
|
425
|
+
this.#eslint = new ESLint({
|
|
426
|
+
overrideConfigFile: options?.configPath
|
|
427
|
+
});
|
|
428
|
+
if (options?.fix) {
|
|
429
|
+
this.#eslintFixer = new ESLint({
|
|
459
430
|
fix: options.fix,
|
|
460
|
-
overrideConfigFile: options
|
|
461
|
-
})
|
|
431
|
+
overrideConfigFile: options?.configPath
|
|
432
|
+
});
|
|
462
433
|
}
|
|
463
434
|
}
|
|
464
435
|
/**
|
|
@@ -471,6 +442,91 @@ const _FileLinter = class _FileLinter {
|
|
|
471
442
|
const { status } = ChildProcess.spawnSync("lint-staged", args, { stdio: "inherit" });
|
|
472
443
|
return status ?? 0;
|
|
473
444
|
}
|
|
445
|
+
static #preparePrettierLintResult(results) {
|
|
446
|
+
if (results.length === 0) {
|
|
447
|
+
return { status: "success" };
|
|
448
|
+
}
|
|
449
|
+
const title = `Linting with Prettier failed with ${results.length} problem${results.length === 1 ? "" : "s"}
|
|
450
|
+
`;
|
|
451
|
+
let message = "Prettier failed with the following files:\n";
|
|
452
|
+
message += results.map((result) => `- ${result.path}`).join("\n");
|
|
453
|
+
message += OS.EOL;
|
|
454
|
+
return {
|
|
455
|
+
status: "failure",
|
|
456
|
+
title,
|
|
457
|
+
message,
|
|
458
|
+
problemCount: results.length
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
async #isIgnoredByPrettier(path) {
|
|
462
|
+
if (path.endsWith(".sh")) {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
return this.#eslint.isPathIgnored(path);
|
|
466
|
+
}
|
|
467
|
+
async #prettierLint(patterns) {
|
|
468
|
+
const configPath = await Prettier.resolveConfigFile();
|
|
469
|
+
if (!configPath) {
|
|
470
|
+
return [];
|
|
471
|
+
}
|
|
472
|
+
const config = await Prettier.resolveConfig(configPath);
|
|
473
|
+
if (!config) {
|
|
474
|
+
return [];
|
|
475
|
+
}
|
|
476
|
+
const paths = await glob(patterns, {
|
|
477
|
+
nodir: true,
|
|
478
|
+
ignore: "node_modules/**"
|
|
479
|
+
});
|
|
480
|
+
const results = await Promise.all(
|
|
481
|
+
paths.map(async (path) => {
|
|
482
|
+
if (await this.#isIgnoredByPrettier(path)) {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
const contentBuffer = await FileSystem.readFile(path);
|
|
486
|
+
const content = contentBuffer.toString();
|
|
487
|
+
if (this.#options?.fix) {
|
|
488
|
+
const nextContent = await Prettier.format(content, {
|
|
489
|
+
...config,
|
|
490
|
+
filepath: path
|
|
491
|
+
});
|
|
492
|
+
await FileSystem.writeFile(path, nextContent);
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
const result = await Prettier.check(content, {
|
|
496
|
+
...config,
|
|
497
|
+
filepath: path
|
|
498
|
+
});
|
|
499
|
+
return result ? null : { path };
|
|
500
|
+
})
|
|
501
|
+
);
|
|
502
|
+
return results.filter((result) => result !== null);
|
|
503
|
+
}
|
|
504
|
+
async #prepareESLintLintResult(results) {
|
|
505
|
+
const problemCount = results.reduce(
|
|
506
|
+
(sum, result) => sum + result.errorCount + result.warningCount + (this.#options?.fix ? -(result.fixableErrorCount + result.fixableWarningCount) : 0),
|
|
507
|
+
0
|
|
508
|
+
);
|
|
509
|
+
if (problemCount === 0) {
|
|
510
|
+
return { status: "success" };
|
|
511
|
+
}
|
|
512
|
+
const title = `ESLint failed with ${problemCount} problem${problemCount === 1 ? "" : "s"}`;
|
|
513
|
+
const formatter = await this.#eslint.loadFormatter("stylish");
|
|
514
|
+
const message = await formatter.format(results);
|
|
515
|
+
return {
|
|
516
|
+
status: "failure",
|
|
517
|
+
title,
|
|
518
|
+
message,
|
|
519
|
+
problemCount
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
async #eslintLint(patterns) {
|
|
523
|
+
const results = await this.#eslint.lintFiles(patterns);
|
|
524
|
+
const errorResults = ESLint.getErrorResults(results);
|
|
525
|
+
if (this.#eslintFixer && errorResults.length > 0) {
|
|
526
|
+
await ESLint.outputFixes(await this.#eslintFixer.lintFiles(patterns));
|
|
527
|
+
}
|
|
528
|
+
return results;
|
|
529
|
+
}
|
|
474
530
|
/**
|
|
475
531
|
* Lints files matching the provided patterns using ESLint and Prettier.
|
|
476
532
|
*
|
|
@@ -478,14 +534,13 @@ const _FileLinter = class _FileLinter {
|
|
|
478
534
|
* @returns A promise that resolves to a LintFilesResult indicating the success or failure of the linting process.
|
|
479
535
|
*/
|
|
480
536
|
async lint(patterns = ["**"]) {
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
const
|
|
484
|
-
const eslintResult = await __privateMethod(this, _FileLinter_instances, prepareESLintLintResult_fn).call(this, eslintResults);
|
|
537
|
+
const prettierResults = await this.#prettierLint(patterns);
|
|
538
|
+
const eslintResults = await this.#eslintLint(patterns);
|
|
539
|
+
const eslintResult = await this.#prepareESLintLintResult(eslintResults);
|
|
485
540
|
if (eslintResult.status === "failure") {
|
|
486
541
|
return eslintResult;
|
|
487
542
|
}
|
|
488
|
-
const prettierResult =
|
|
543
|
+
const prettierResult = FileLinter.#preparePrettierLintResult(prettierResults);
|
|
489
544
|
if (prettierResult.status === "failure") {
|
|
490
545
|
return prettierResult;
|
|
491
546
|
}
|
|
@@ -493,97 +548,7 @@ const _FileLinter = class _FileLinter {
|
|
|
493
548
|
status: "success"
|
|
494
549
|
};
|
|
495
550
|
}
|
|
496
|
-
}
|
|
497
|
-
_options = new WeakMap();
|
|
498
|
-
_eslint = new WeakMap();
|
|
499
|
-
_eslintFixer = new WeakMap();
|
|
500
|
-
_FileLinter_static = new WeakSet();
|
|
501
|
-
preparePrettierLintResult_fn = function(results) {
|
|
502
|
-
if (results.length === 0) {
|
|
503
|
-
return { status: "success" };
|
|
504
|
-
}
|
|
505
|
-
const title = `Linting with Prettier failed with ${results.length} problem${results.length === 1 ? "" : "s"}
|
|
506
|
-
`;
|
|
507
|
-
let message = "Prettier failed with the following files:\n";
|
|
508
|
-
message += results.map((result) => `- ${result.path}`).join("\n");
|
|
509
|
-
message += OS.EOL;
|
|
510
|
-
return {
|
|
511
|
-
status: "failure",
|
|
512
|
-
title,
|
|
513
|
-
message,
|
|
514
|
-
problemCount: results.length
|
|
515
|
-
};
|
|
516
|
-
};
|
|
517
|
-
_FileLinter_instances = new WeakSet();
|
|
518
|
-
prettierLint_fn = async function(patterns) {
|
|
519
|
-
const configPath = await Prettier.resolveConfigFile();
|
|
520
|
-
if (!configPath) {
|
|
521
|
-
return [];
|
|
522
|
-
}
|
|
523
|
-
const config = await Prettier.resolveConfig(configPath);
|
|
524
|
-
if (!config) {
|
|
525
|
-
return [];
|
|
526
|
-
}
|
|
527
|
-
const paths = await glob(patterns, {
|
|
528
|
-
nodir: true,
|
|
529
|
-
ignore: "node_modules/**"
|
|
530
|
-
});
|
|
531
|
-
const results = await Promise.all(
|
|
532
|
-
paths.map(async (path) => {
|
|
533
|
-
var _a;
|
|
534
|
-
if (await __privateGet(this, _eslint).isPathIgnored(path)) {
|
|
535
|
-
return null;
|
|
536
|
-
}
|
|
537
|
-
const contentBuffer = await FileSystem.readFile(path);
|
|
538
|
-
const content = contentBuffer.toString();
|
|
539
|
-
if ((_a = __privateGet(this, _options)) == null ? void 0 : _a.fix) {
|
|
540
|
-
const nextContent = await Prettier.format(content, {
|
|
541
|
-
...config,
|
|
542
|
-
filepath: path
|
|
543
|
-
});
|
|
544
|
-
await FileSystem.writeFile(path, nextContent);
|
|
545
|
-
return null;
|
|
546
|
-
}
|
|
547
|
-
const result = await Prettier.check(content, {
|
|
548
|
-
...config,
|
|
549
|
-
filepath: path
|
|
550
|
-
});
|
|
551
|
-
return result ? null : { path };
|
|
552
|
-
})
|
|
553
|
-
);
|
|
554
|
-
return results.filter((result) => result !== null);
|
|
555
|
-
};
|
|
556
|
-
prepareESLintLintResult_fn = async function(results) {
|
|
557
|
-
const problemCount = results.reduce(
|
|
558
|
-
(sum, result) => {
|
|
559
|
-
var _a;
|
|
560
|
-
return sum + result.errorCount + result.warningCount + (((_a = __privateGet(this, _options)) == null ? void 0 : _a.fix) ? -(result.fixableErrorCount + result.fixableWarningCount) : 0);
|
|
561
|
-
},
|
|
562
|
-
0
|
|
563
|
-
);
|
|
564
|
-
if (problemCount === 0) {
|
|
565
|
-
return { status: "success" };
|
|
566
|
-
}
|
|
567
|
-
const title = `ESLint failed with ${problemCount} problem${problemCount === 1 ? "" : "s"}`;
|
|
568
|
-
const formatter = await __privateGet(this, _eslint).loadFormatter("stylish");
|
|
569
|
-
const message = await formatter.format(results);
|
|
570
|
-
return {
|
|
571
|
-
status: "failure",
|
|
572
|
-
title,
|
|
573
|
-
message,
|
|
574
|
-
problemCount
|
|
575
|
-
};
|
|
576
|
-
};
|
|
577
|
-
eslintLint_fn = async function(patterns) {
|
|
578
|
-
const results = await __privateGet(this, _eslint).lintFiles(patterns);
|
|
579
|
-
const errorResults = ESLint.getErrorResults(results);
|
|
580
|
-
if (__privateGet(this, _eslintFixer) && errorResults.length > 0) {
|
|
581
|
-
await ESLint.outputFixes(await __privateGet(this, _eslintFixer).lintFiles(patterns));
|
|
582
|
-
}
|
|
583
|
-
return results;
|
|
584
|
-
};
|
|
585
|
-
__privateAdd(_FileLinter, _FileLinter_static);
|
|
586
|
-
let FileLinter = _FileLinter;
|
|
551
|
+
}
|
|
587
552
|
const toolNameArgSchema = z.union([z.literal("all"), toolNameSchema]);
|
|
588
553
|
const parseInitArgs = ([nameArg]) => {
|
|
589
554
|
const name = toolNameArgSchema.parse(nameArg);
|
|
@@ -608,7 +573,7 @@ const main = async (args) => {
|
|
|
608
573
|
} catch (error) {
|
|
609
574
|
if (error instanceof ZodError) {
|
|
610
575
|
const firstIssue = error.issues[0];
|
|
611
|
-
if (
|
|
576
|
+
if (firstIssue?.code === "invalid_union") {
|
|
612
577
|
console.error("Error: Invalid tool name");
|
|
613
578
|
return 1;
|
|
614
579
|
}
|