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