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