@kirklin/eslint-config 2.0.0 → 2.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/dist/cli.js CHANGED
@@ -1,63 +1,194 @@
1
1
  // src/cli/index.ts
2
- import process2 from "process";
3
- import c3 from "picocolors";
2
+ import process5 from "process";
3
+ import c6 from "picocolors";
4
4
  import { hideBin } from "yargs/helpers";
5
5
  import yargs from "yargs";
6
+ import * as p5 from "@clack/prompts";
6
7
 
7
8
  // src/cli/run.ts
8
- import fs from "fs";
9
- import fsp from "fs/promises";
10
- import path from "path";
11
- import process from "process";
12
- import prompts from "prompts";
13
- import c2 from "picocolors";
14
- import parse from "parse-gitignore";
9
+ import fs3 from "fs";
10
+ import path4 from "path";
11
+ import process4 from "process";
12
+ import c5 from "picocolors";
13
+ import * as p4 from "@clack/prompts";
15
14
 
16
15
  // src/cli/constants.ts
17
16
  import c from "picocolors";
18
17
 
19
18
  // package.json
20
- var version = "2.0.0";
21
- var devDependencies = {
22
- "@antfu/eslint-plugin-prettier": "^5.0.1-1",
23
- "@antfu/ni": "^0.21.12",
24
- "@kirklin/eslint-config": "workspace:*",
25
- "@stylistic/eslint-plugin-migrate": "^1.5.1",
26
- "@types/eslint": "^8.56.0",
27
- "@types/fs-extra": "^11.0.4",
28
- "@types/node": "^20.10.6",
29
- "@types/prompts": "^2.4.9",
30
- "@types/yargs": "^17.0.32",
31
- "@unocss/eslint-plugin": "^0.58.2",
32
- bumpp: "^9.2.1",
33
- eslint: "npm:eslint-ts-patch@^8.56.0-0",
34
- "eslint-flat-config-viewer": "^0.1.4",
35
- "eslint-plugin-format": "^0.1.0",
36
- "eslint-plugin-react": "^7.33.2",
37
- "eslint-plugin-react-hooks": "^4.6.0",
38
- "eslint-plugin-react-refresh": "^0.4.5",
39
- "eslint-plugin-svelte": "^2.35.1",
40
- "eslint-ts-patch": "^8.56.0-0",
41
- esno: "^4.0.0",
42
- execa: "^8.0.1",
43
- "fast-glob": "^3.3.2",
44
- "fs-extra": "^11.2.0",
45
- "lint-staged": "^15.2.0",
46
- rimraf: "^5.0.5",
47
- "simple-git-hooks": "^2.9.0",
48
- "svelte-eslint-parser": "^0.33.1",
49
- tsup: "^8.0.1",
50
- typescript: "^5.3.3",
51
- vitest: "^1.1.0",
52
- vue: "^3.4.3"
19
+ var package_default = {
20
+ name: "@kirklin/eslint-config",
21
+ type: "module",
22
+ version: "2.2.0",
23
+ packageManager: "pnpm@8.15.5",
24
+ description: "Kirk Lin's ESLint config",
25
+ author: "Kirk Lin (https://github.com/kirklin/)",
26
+ license: "MIT",
27
+ funding: "https://www.buymeacoffee.com/linkirk",
28
+ homepage: "https://github.com/kirklin/eslint-config",
29
+ keywords: [
30
+ "eslint-config"
31
+ ],
32
+ exports: {
33
+ ".": {
34
+ import: "./dist/index.js",
35
+ require: "./dist/index.cjs"
36
+ }
37
+ },
38
+ main: "./dist/index.js",
39
+ types: "./dist/index.d.ts",
40
+ bin: "./bin/index.js",
41
+ files: [
42
+ "bin",
43
+ "dist"
44
+ ],
45
+ scripts: {
46
+ build: "tsup --format esm,cjs --clean --dts",
47
+ stub: "tsup --format esm",
48
+ dev: "tsup --format esm,cjs --watch & eslint-flat-config-viewer",
49
+ watch: "tsup --format esm,cjs --watch",
50
+ lint: "eslint .",
51
+ "lint:fix": "eslint . --fix",
52
+ prepack: "nr build",
53
+ release: "bumpp && pnpm publish",
54
+ test: "vitest",
55
+ typecheck: "tsc --noEmit",
56
+ prepare: "simple-git-hooks"
57
+ },
58
+ peerDependencies: {
59
+ "@unocss/eslint-plugin": ">=0.50.0",
60
+ "astro-eslint-parser": "^0.16.3",
61
+ eslint: ">=8.40.0",
62
+ "eslint-plugin-astro": "^0.31.4",
63
+ "eslint-plugin-format": ">=0.1.0",
64
+ "eslint-plugin-react": "^7.33.2",
65
+ "eslint-plugin-react-hooks": "^4.6.0",
66
+ "eslint-plugin-react-refresh": "^0.4.4",
67
+ "eslint-plugin-svelte": "^2.34.1",
68
+ "prettier-plugin-astro": "^0.13.0",
69
+ "prettier-plugin-slidev": "^1.0.5",
70
+ "svelte-eslint-parser": "^0.33.1"
71
+ },
72
+ peerDependenciesMeta: {
73
+ "@unocss/eslint-plugin": {
74
+ optional: true
75
+ },
76
+ "astro-eslint-parser": {
77
+ optional: true
78
+ },
79
+ "eslint-plugin-astro": {
80
+ optional: true
81
+ },
82
+ "eslint-plugin-format": {
83
+ optional: true
84
+ },
85
+ "eslint-plugin-react": {
86
+ optional: true
87
+ },
88
+ "eslint-plugin-react-hooks": {
89
+ optional: true
90
+ },
91
+ "eslint-plugin-react-refresh": {
92
+ optional: true
93
+ },
94
+ "eslint-plugin-svelte": {
95
+ optional: true
96
+ },
97
+ "prettier-plugin-astro": {
98
+ optional: true
99
+ },
100
+ "prettier-plugin-slidev": {
101
+ optional: true
102
+ },
103
+ "svelte-eslint-parser": {
104
+ optional: true
105
+ }
106
+ },
107
+ dependencies: {
108
+ "@antfu/eslint-define-config": "1.23.0-2",
109
+ "@antfu/install-pkg": "^0.3.1",
110
+ "@clack/prompts": "^0.7.0",
111
+ "@eslint-types/jsdoc": "48.2.1",
112
+ "@eslint-types/typescript-eslint": "^7.2.0",
113
+ "@eslint-types/unicorn": "^51.0.1",
114
+ "@stylistic/eslint-plugin": "^1.7.0",
115
+ "@typescript-eslint/eslint-plugin": "^7.3.1",
116
+ "@typescript-eslint/parser": "^7.3.1",
117
+ "eslint-config-flat-gitignore": "^0.1.3",
118
+ "eslint-merge-processors": "^0.1.0",
119
+ "eslint-plugin-eslint-comments": "^3.2.0",
120
+ "eslint-plugin-i": "^2.29.1",
121
+ "eslint-plugin-jsdoc": "^48.2.1",
122
+ "eslint-plugin-jsonc": "^2.14.1",
123
+ "eslint-plugin-kirklin": "^1.1.0",
124
+ "eslint-plugin-markdown": "^4.0.1",
125
+ "eslint-plugin-n": "^16.6.2",
126
+ "eslint-plugin-no-only-tests": "^3.1.0",
127
+ "eslint-plugin-perfectionist": "^2.7.0",
128
+ "eslint-plugin-toml": "^0.10.0",
129
+ "eslint-plugin-unicorn": "^51.0.1",
130
+ "eslint-plugin-unused-imports": "^3.1.0",
131
+ "eslint-plugin-vitest": "^0.3.26",
132
+ "eslint-plugin-vue": "^9.23.0",
133
+ "eslint-plugin-yml": "^1.13.1",
134
+ "eslint-processor-vue-blocks": "^0.1.1",
135
+ globals: "^14.0.0",
136
+ "jsonc-eslint-parser": "^2.4.0",
137
+ "local-pkg": "^0.5.0",
138
+ "parse-gitignore": "^2.0.0",
139
+ picocolors: "^1.0.0",
140
+ "toml-eslint-parser": "^0.9.3",
141
+ "vue-eslint-parser": "^9.4.2",
142
+ "yaml-eslint-parser": "^1.2.2",
143
+ yargs: "^17.7.2"
144
+ },
145
+ devDependencies: {
146
+ "@antfu/eslint-plugin-prettier": "5.0.1-1",
147
+ "@antfu/ni": "^0.21.12",
148
+ "@kirklin/eslint-config": "workspace:*",
149
+ "@stylistic/eslint-plugin-migrate": "^1.7.0",
150
+ "@types/eslint": "^8.56.6",
151
+ "@types/fs-extra": "^11.0.4",
152
+ "@types/node": "^20.11.30",
153
+ "@types/prompts": "^2.4.9",
154
+ "@types/yargs": "^17.0.32",
155
+ "@unocss/eslint-plugin": "^0.58.6",
156
+ "astro-eslint-parser": "^0.16.3",
157
+ bumpp: "^9.4.0",
158
+ eslint: "npm:eslint-ts-patch@8.57.0-0",
159
+ "eslint-flat-config-viewer": "^0.1.11",
160
+ "eslint-plugin-astro": "^0.32.0",
161
+ "eslint-plugin-format": "^0.1.0",
162
+ "eslint-plugin-react": "^7.34.1",
163
+ "eslint-plugin-react-hooks": "^4.6.0",
164
+ "eslint-plugin-react-refresh": "^0.4.6",
165
+ "eslint-plugin-svelte": "^2.35.1",
166
+ "eslint-ts-patch": "8.57.0-0",
167
+ esno: "^4.7.0",
168
+ execa: "^8.0.1",
169
+ "fast-glob": "^3.3.2",
170
+ "fs-extra": "^11.2.0",
171
+ "lint-staged": "^15.2.2",
172
+ "prettier-plugin-astro": "^0.13.0",
173
+ "prettier-plugin-slidev": "^1.0.5",
174
+ rimraf: "^5.0.5",
175
+ "simple-git-hooks": "^2.11.0",
176
+ svelte: "^4.2.12",
177
+ "svelte-eslint-parser": "^0.33.1",
178
+ tsup: "^8.0.2",
179
+ typescript: "^5.4.2",
180
+ vitest: "^1.4.0",
181
+ vue: "^3.4.21"
182
+ },
183
+ "simple-git-hooks": {
184
+ "pre-commit": "pnpm lint-staged"
185
+ },
186
+ "lint-staged": {
187
+ "*": "eslint --fix"
188
+ }
53
189
  };
54
190
 
55
191
  // src/cli/constants.ts
56
- var ARROW = c.cyan("\u2192");
57
- var CHECK = c.green("\u2714");
58
- var CROSS = c.red("\u2718");
59
- var WARN = c.yellow("\u2139");
60
- var eslintVersion = devDependencies.eslint;
61
192
  var vscodeSettingsString = `
62
193
  // Enable the ESlint flat config support
63
194
  "eslint.experimental.useFlatConfig": true,
@@ -98,9 +229,64 @@ var vscodeSettingsString = `
98
229
  "json",
99
230
  "jsonc",
100
231
  "yaml",
101
- "toml"
232
+ "toml",
233
+ "astro",
102
234
  ]
103
235
  `;
236
+ var frameworkOptions = [
237
+ {
238
+ label: c.green("Vue"),
239
+ value: "vue"
240
+ },
241
+ {
242
+ label: c.cyan("React"),
243
+ value: "react"
244
+ },
245
+ {
246
+ label: c.red("Svelte"),
247
+ value: "svelte"
248
+ },
249
+ {
250
+ label: c.magenta("Astro"),
251
+ value: "astro"
252
+ },
253
+ {
254
+ label: c.blue("Slidev"),
255
+ value: "slidev"
256
+ }
257
+ ];
258
+ var frameworks = frameworkOptions.map(({ value }) => value);
259
+ var extraOptions = [
260
+ {
261
+ hint: "Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)",
262
+ label: c.red("Formatter"),
263
+ value: "formatter"
264
+ },
265
+ {
266
+ label: c.cyan("UnoCSS"),
267
+ value: "unocss"
268
+ }
269
+ ];
270
+ var extra = extraOptions.map(({ value }) => value);
271
+ var dependenciesMap = {
272
+ astro: [
273
+ "eslint-plugin-astro",
274
+ "astro-eslint-parser"
275
+ ],
276
+ react: [
277
+ "eslint-plugin-react",
278
+ "eslint-plugin-react-hooks",
279
+ "eslint-plugin-react-refresh"
280
+ ],
281
+ slidev: [
282
+ "prettier-plugin-slidev"
283
+ ],
284
+ svelte: [
285
+ "eslint-plugin-svelte",
286
+ "svelte-eslint-parser"
287
+ ],
288
+ vue: []
289
+ };
104
290
 
105
291
  // src/cli/utils.ts
106
292
  import { execSync } from "child_process";
@@ -112,44 +298,97 @@ function isGitClean() {
112
298
  return false;
113
299
  }
114
300
  }
301
+ function getEslintConfigContent(mainConfig, additionalConfigs) {
302
+ return `
303
+ import kirklin from '@kirklin/eslint-config'
115
304
 
116
- // src/cli/run.ts
117
- async function run(options = {}) {
118
- const SKIP_PROMPT = !!process.env.SKIP_PROMPT || options.yes;
119
- const SKIP_GIT_CHECK = !!process.env.SKIP_GIT_CHECK;
305
+ export default kirklin({
306
+ ${mainConfig}
307
+ }${additionalConfigs?.map((config) => `,{
308
+ ${config}
309
+ }`)})
310
+ `.trimStart();
311
+ }
312
+
313
+ // src/cli/stages/update-package-json.ts
314
+ import path from "path";
315
+ import fsp from "fs/promises";
316
+ import process from "process";
317
+ import c2 from "picocolors";
318
+ import * as p from "@clack/prompts";
319
+ async function updatePackageJson(result) {
320
+ var _a;
120
321
  const cwd = process.cwd();
121
- const pathFlatConfig = path.join(cwd, "eslint.config.js");
122
322
  const pathPackageJSON = path.join(cwd, "package.json");
123
- const pathESLintIgnore = path.join(cwd, ".eslintignore");
124
- if (fs.existsSync(pathFlatConfig)) {
125
- console.log(c2.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
126
- return process.exit(1);
127
- }
128
- if (!SKIP_GIT_CHECK && !isGitClean()) {
129
- const { confirmed } = await prompts({
130
- initial: false,
131
- message: "There are uncommitted changes in the current repository, are you sure to continue?",
132
- name: "confirmed",
133
- type: "confirm"
134
- });
135
- if (!confirmed) {
136
- return process.exit(1);
137
- }
138
- }
139
- console.log(c2.cyan(`${ARROW} bumping @kirklin/eslint-config to v${version}`));
323
+ p.log.step(c2.cyan(`Bumping @kirklin/eslint-config to v${package_default.version}`));
140
324
  const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
141
325
  const pkg = JSON.parse(pkgContent);
142
326
  pkg.devDependencies ?? (pkg.devDependencies = {});
143
- pkg.devDependencies["@kirklin/eslint-config"] = `^${version}`;
144
- if (!pkg.devDependencies.eslint) {
145
- pkg.devDependencies.eslint = eslintVersion;
327
+ pkg.devDependencies["@kirklin/eslint-config"] = `^${package_default.version}`;
328
+ (_a = pkg.devDependencies).eslint ?? (_a.eslint = package_default.devDependencies.eslint.replace("npm:eslint-ts-patch@", "").replace(/-\d+$/, ""));
329
+ const addedPackages = [];
330
+ if (result.extra.length) {
331
+ result.extra.forEach((item) => {
332
+ switch (item) {
333
+ case "formatter":
334
+ [
335
+ "eslint-plugin-format",
336
+ result.frameworks.includes("astro") ? "prettier-plugin-astro" : null
337
+ ].forEach((f) => {
338
+ if (!f) {
339
+ return;
340
+ }
341
+ pkg.devDependencies[f] = package_default.devDependencies[f];
342
+ addedPackages.push(f);
343
+ });
344
+ break;
345
+ case "unocss":
346
+ [
347
+ "@unocss/eslint-plugin"
348
+ ].forEach((f) => {
349
+ pkg.devDependencies[f] = package_default.devDependencies[f];
350
+ addedPackages.push(f);
351
+ });
352
+ break;
353
+ }
354
+ });
355
+ }
356
+ for (const framework of result.frameworks) {
357
+ const deps = dependenciesMap[framework];
358
+ if (deps) {
359
+ deps.forEach((f) => {
360
+ pkg.devDependencies[f] = package_default.devDependencies[f];
361
+ addedPackages.push(f);
362
+ });
363
+ }
364
+ }
365
+ if (addedPackages.length) {
366
+ p.note(`${c2.dim(addedPackages.join(", "))}`, "Added packages");
146
367
  }
147
368
  await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
148
- console.log(c2.green(`${CHECK} changes wrote to package.json`));
369
+ p.log.success(c2.green(`Changes wrote to package.json`));
370
+ }
371
+
372
+ // src/cli/stages/update-eslint-files.ts
373
+ import fs from "fs";
374
+ import fsp2 from "fs/promises";
375
+ import process2 from "process";
376
+ import path2 from "path";
377
+ import c3 from "picocolors";
378
+ import * as p2 from "@clack/prompts";
379
+ import parse from "parse-gitignore";
380
+ async function updateEslintFiles(result) {
381
+ const cwd = process2.cwd();
382
+ const pathESLintIgnore = path2.join(cwd, ".eslintignore");
383
+ const pathPackageJSON = path2.join(cwd, "package.json");
384
+ const pkgContent = await fsp2.readFile(pathPackageJSON, "utf-8");
385
+ const pkg = JSON.parse(pkgContent);
386
+ const configFileName = pkg.type === "module" ? "eslint.config.js" : "eslint.config.mjs";
387
+ const pathFlatConfig = path2.join(cwd, configFileName);
149
388
  const eslintIgnores = [];
150
389
  if (fs.existsSync(pathESLintIgnore)) {
151
- console.log(c2.cyan(`${ARROW} migrating existing .eslintignore`));
152
- const content = await fsp.readFile(pathESLintIgnore, "utf-8");
390
+ p2.log.step(c3.cyan(`Migrating existing .eslintignore`));
391
+ const content = await fsp2.readFile(pathESLintIgnore, "utf-8");
153
392
  const parsed = parse(content);
154
393
  const globs = parsed.globs();
155
394
  for (const glob of globs) {
@@ -160,102 +399,175 @@ async function run(options = {}) {
160
399
  }
161
400
  }
162
401
  }
163
- let eslintConfigContent = "";
164
- const kirklinConfig = `${eslintIgnores.length ? `ignores: ${JSON.stringify(eslintIgnores)}` : ""}`;
165
- if (pkg.type === "module") {
166
- eslintConfigContent = `
167
- import kirklin from '@kirklin/eslint-config'
168
-
169
- export default kirklin({
170
- ${kirklinConfig}
171
- })
172
- `.trimStart();
173
- } else {
174
- eslintConfigContent = `
175
- const kirklin = require('@kirklin/eslint-config').default
176
-
177
- module.exports = kirklin({
178
- ${kirklinConfig}
179
- })
180
- `.trimStart();
402
+ const configLines = [];
403
+ if (eslintIgnores.length) {
404
+ configLines.push(`ignores: ${JSON.stringify(eslintIgnores)},`);
405
+ }
406
+ if (result.extra.includes("formatter")) {
407
+ configLines.push(`formatters: true,`);
408
+ }
409
+ if (result.extra.includes("unocss")) {
410
+ configLines.push(`unocss: true,`);
181
411
  }
182
- await fsp.writeFile(pathFlatConfig, eslintConfigContent);
183
- console.log(c2.green(`${CHECK} created eslint.config.js`));
412
+ for (const framework of result.frameworks) {
413
+ configLines.push(`${framework}: true,`);
414
+ }
415
+ const mainConfig = configLines.map((i) => ` ${i}`).join("\n");
416
+ const additionalConfig = [];
417
+ const eslintConfigContent = getEslintConfigContent(mainConfig, additionalConfig);
418
+ await fsp2.writeFile(pathFlatConfig, eslintConfigContent);
419
+ p2.log.success(c3.green(`Created ${configFileName}`));
184
420
  const files = fs.readdirSync(cwd);
185
421
  const legacyConfig = [];
186
422
  files.forEach((file) => {
187
- if (file.includes("eslint") || file.includes("prettier")) {
423
+ if (/eslint|prettier/.test(file) && !/eslint\.config\./.test(file)) {
188
424
  legacyConfig.push(file);
189
425
  }
190
426
  });
191
427
  if (legacyConfig.length) {
192
- console.log(`${WARN} you can now remove those files manually:`);
193
- console.log(` ${c2.dim(legacyConfig.join(", "))}`);
428
+ p2.note(`${c3.dim(legacyConfig.join(", "))}`, "You can now remove those files manually");
194
429
  }
195
- let promptResult = {
196
- updateVscodeSettings: true
197
- };
198
- if (!SKIP_PROMPT) {
199
- try {
200
- promptResult = await prompts({
201
- initial: true,
202
- message: "Update .vscode/settings.json for better VS Code experience?",
203
- name: "updateVscodeSettings",
204
- type: "confirm"
205
- }, {
206
- onCancel: () => {
207
- throw new Error(`Cancelled`);
208
- }
209
- });
210
- } catch (cancelled) {
211
- console.log(cancelled.message);
212
- return;
213
- }
430
+ }
431
+
432
+ // src/cli/stages/update-vscode-settings.ts
433
+ import path3 from "path";
434
+ import fsp3 from "fs/promises";
435
+ import fs2 from "fs";
436
+ import process3 from "process";
437
+ import c4 from "picocolors";
438
+ import * as p3 from "@clack/prompts";
439
+ async function updateVscodeSettings(result) {
440
+ const cwd = process3.cwd();
441
+ if (!result.updateVscodeSettings) {
442
+ return;
214
443
  }
215
- if (promptResult?.updateVscodeSettings ?? true) {
216
- const dotVscodePath = path.join(cwd, ".vscode");
217
- const settingsPath = path.join(dotVscodePath, "settings.json");
218
- if (!fs.existsSync(dotVscodePath)) {
219
- await fsp.mkdir(dotVscodePath, { recursive: true });
220
- }
221
- if (!fs.existsSync(settingsPath)) {
222
- await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}
444
+ const dotVscodePath = path3.join(cwd, ".vscode");
445
+ const settingsPath = path3.join(dotVscodePath, "settings.json");
446
+ if (!fs2.existsSync(dotVscodePath)) {
447
+ await fsp3.mkdir(dotVscodePath, { recursive: true });
448
+ }
449
+ if (!fs2.existsSync(settingsPath)) {
450
+ await fsp3.writeFile(settingsPath, `{${vscodeSettingsString}}
223
451
  `, "utf-8");
224
- console.log(c2.green(`${CHECK} created .vscode/settings.json`));
225
- } else {
226
- let settingsContent = await fsp.readFile(settingsPath, "utf8");
227
- settingsContent = settingsContent.trim().replace(/\s*}$/, "");
228
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
229
- settingsContent += `${vscodeSettingsString}}
452
+ p3.log.success(c4.green(`Created .vscode/settings.json`));
453
+ } else {
454
+ let settingsContent = await fsp3.readFile(settingsPath, "utf8");
455
+ settingsContent = settingsContent.trim().replace(/\s*}$/, "");
456
+ settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
457
+ settingsContent += `${vscodeSettingsString}}
230
458
  `;
231
- await fsp.writeFile(settingsPath, settingsContent, "utf-8");
232
- console.log(c2.green(`${CHECK} updated .vscode/settings.json`));
459
+ await fsp3.writeFile(settingsPath, settingsContent, "utf-8");
460
+ p3.log.success(c4.green(`Updated .vscode/settings.json`));
461
+ }
462
+ }
463
+
464
+ // src/cli/run.ts
465
+ async function run(options = {}) {
466
+ const argSkipPrompt = !!process4.env.SKIP_PROMPT || options.yes;
467
+ const argTemplate = options.frameworks?.map((m) => m.trim());
468
+ const argExtra = options.extra?.map((m) => m.trim());
469
+ if (fs3.existsSync(path4.join(process4.cwd(), "eslint.config.js"))) {
470
+ p4.log.warn(c5.yellow(`eslint.config.js already exists, migration wizard exited.`));
471
+ return process4.exit(1);
472
+ }
473
+ let result = {
474
+ extra: argExtra ?? [],
475
+ frameworks: argTemplate ?? [],
476
+ uncommittedConfirmed: false,
477
+ updateVscodeSettings: true
478
+ };
479
+ if (!argSkipPrompt) {
480
+ result = await p4.group({
481
+ uncommittedConfirmed: () => {
482
+ if (argSkipPrompt || isGitClean()) {
483
+ return;
484
+ }
485
+ return p4.confirm({
486
+ initialValue: false,
487
+ message: "There are uncommitted changes in the current repository, are you sure to continue?"
488
+ });
489
+ },
490
+ frameworks: ({ results }) => {
491
+ const isArgTemplateValid = typeof argTemplate === "string" && !!frameworks.includes(argTemplate);
492
+ if (!results.uncommittedConfirmed || isArgTemplateValid) {
493
+ return;
494
+ }
495
+ const message = !isArgTemplateValid && argTemplate ? `"${argTemplate}" isn't a valid template. Please choose from below: ` : "Select a framework:";
496
+ return p4.multiselect({
497
+ message: c5.reset(message),
498
+ options: frameworkOptions
499
+ });
500
+ },
501
+ extra: ({ results }) => {
502
+ const isArgExtraValid = argExtra?.length && !argExtra.filter((element) => !extra.includes(element)).length;
503
+ if (!results.uncommittedConfirmed || isArgExtraValid) {
504
+ return;
505
+ }
506
+ const message = !isArgExtraValid && argExtra ? `"${argExtra}" isn't a valid extra util. Please choose from below: ` : "Select a extra utils:";
507
+ return p4.multiselect({
508
+ message: c5.reset(message),
509
+ options: extraOptions,
510
+ required: false
511
+ });
512
+ },
513
+ updateVscodeSettings: ({ results }) => {
514
+ if (!results.uncommittedConfirmed) {
515
+ return;
516
+ }
517
+ return p4.confirm({
518
+ initialValue: true,
519
+ message: "Update .vscode/settings.json for better VS Code experience?"
520
+ });
521
+ }
522
+ }, {
523
+ onCancel: () => {
524
+ p4.cancel("Operation cancelled.");
525
+ process4.exit(0);
526
+ }
527
+ });
528
+ if (!result.uncommittedConfirmed) {
529
+ return process4.exit(1);
233
530
  }
234
531
  }
235
- console.log(c2.green(`${CHECK} migration completed`));
236
- console.log(`Now you can update the dependencies and run ${c2.blue("eslint . --fix")}
532
+ await updatePackageJson(result);
533
+ await updateEslintFiles(result);
534
+ await updateVscodeSettings(result);
535
+ p4.log.success(c5.green(`Setup completed`));
536
+ p4.outro(`Now you can update the dependencies and run ${c5.blue("eslint . --fix")}
237
537
  `);
238
538
  }
239
539
 
240
540
  // src/cli/index.ts
241
541
  function header() {
242
- console.log(`
243
- ${c3.green(`@kirklin/eslint-config `)}${c3.dim(`v${version}`)}`);
542
+ console.log("\n");
543
+ p5.intro(`${c6.green(`@kirklin/eslint-config `)}${c6.dim(`v${package_default.version}`)}`);
244
544
  }
245
- var instance = yargs(hideBin(process2.argv)).scriptName("@kirklin/eslint-config").usage("").command(
545
+ var instance = yargs(hideBin(process5.argv)).scriptName("@kirklin/eslint-config").usage("").command(
246
546
  "*",
247
547
  "Run the initialization or migration",
248
- (args) => args.option("yes", { alias: "y", description: "Skip prompts and use default values", type: "boolean" }).help(),
548
+ (args) => args.option("yes", {
549
+ alias: "y",
550
+ description: "Skip prompts and use default values",
551
+ type: "boolean"
552
+ }).option("template", {
553
+ alias: "t",
554
+ description: "Use the framework template for optimal customization: vue / react / svelte / astro",
555
+ type: "string"
556
+ }).option("extra", {
557
+ alias: "e",
558
+ array: true,
559
+ description: "Use the extra utils: formatter / perfectionist / unocss",
560
+ type: "string"
561
+ }).help(),
249
562
  async (args) => {
250
563
  header();
251
- console.log();
252
564
  try {
253
565
  await run(args);
254
566
  } catch (error) {
255
- console.error(c3.inverse(c3.red(" Failed to migrate ")));
256
- console.error(c3.red(`${CROSS} ${String(error)}`));
257
- process2.exit(1);
567
+ p5.log.error(c6.inverse(c6.red(" Failed to migrate ")));
568
+ p5.log.error(c6.red(`\u2718 ${String(error)}`));
569
+ process5.exit(1);
258
570
  }
259
571
  }
260
- ).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
572
+ ).showHelpOnFail(false).alias("h", "help").version("version", package_default.version).alias("v", "version");
261
573
  instance.help().argv;