@antfu/eslint-config 2.8.2 → 2.8.3

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