Skip to content

Commit bc13ba5

Browse files
injurkaantfu
andauthoredMar 15, 2024
feat: improve cli (#420)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent daf20cc commit bc13ba5

13 files changed

+434
-192
lines changed
 

‎README.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
2222
## Usage
2323

24+
### Wizard
25+
26+
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config.
27+
28+
```bash
29+
npx @antfu/eslint-config@latest
30+
```
31+
2432
### Install
2533

2634
```bash
@@ -91,16 +99,6 @@ For example:
9199
}
92100
```
93101

94-
### Migration
95-
96-
We provided an experimental CLI tool to help you migrate from the legacy config to the new flat config.
97-
98-
```bash
99-
npx @antfu/eslint-config@latest
100-
```
101-
102-
Before running the migration, make sure to commit your unsaved changes first.
103-
104102
## VS Code support (auto fix)
105103

106104
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"dependencies": {
8989
"@antfu/eslint-define-config": "^1.23.0-2",
9090
"@antfu/install-pkg": "^0.3.1",
91+
"@clack/prompts": "^0.7.0",
9192
"@eslint-types/jsdoc": "46.8.2-1",
9293
"@eslint-types/typescript-eslint": "^7.0.2",
9394
"@eslint-types/unicorn": "^51.0.1",
@@ -117,7 +118,6 @@
117118
"local-pkg": "^0.5.0",
118119
"parse-gitignore": "^2.0.0",
119120
"picocolors": "^1.0.0",
120-
"prompts": "^2.4.2",
121121
"toml-eslint-parser": "^0.9.3",
122122
"vue-eslint-parser": "^9.4.2",
123123
"yaml-eslint-parser": "^1.2.2",

‎pnpm-lock.yaml

+22-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/cli/constants.ts

+62-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import c from 'picocolors'
2-
import { devDependencies, version } from '../../package.json'
2+
import pkgJson from '../../package.json'
3+
import type { ExtraLibrariesOption, FrameworkOption, PromItem } from './types'
34

4-
export const ARROW = c.cyan('→')
5-
export const CHECK = c.green('✔')
6-
export const CROSS = c.red('✘')
7-
export const WARN = c.yellow('ℹ')
8-
9-
export const eslintVersion = devDependencies.eslint
10-
export { version }
5+
export { pkgJson }
116

127
export const vscodeSettingsString = `
138
// Enable the ESlint flat config support
@@ -53,3 +48,62 @@ export const vscodeSettingsString = `
5348
"astro",
5449
]
5550
`
51+
52+
export const frameworkOptions: PromItem<FrameworkOption>[] = [
53+
{
54+
label: c.green('Vue'),
55+
value: 'vue',
56+
},
57+
{
58+
label: c.cyan('React'),
59+
value: 'react',
60+
},
61+
{
62+
label: c.red('Svelte'),
63+
value: 'svelte',
64+
},
65+
{
66+
label: c.magenta('Astro'),
67+
value: 'astro',
68+
},
69+
{
70+
label: c.blue('Slidev'),
71+
value: 'slidev',
72+
},
73+
]
74+
75+
export const frameworks: FrameworkOption[] = frameworkOptions.map(({ value }) => (value))
76+
77+
export const extraOptions: PromItem<ExtraLibrariesOption>[] = [
78+
{
79+
hint: 'Use external formatters (Prettier and/or dprint) to format files that ESLint cannot handle yet (.css, .html, etc)',
80+
label: c.red('Formatter'),
81+
value: 'formatter',
82+
},
83+
{
84+
label: c.cyan('UnoCSS'),
85+
value: 'unocss',
86+
},
87+
]
88+
89+
export const extra: ExtraLibrariesOption[] = extraOptions.map(({ value }) => (value))
90+
91+
export const dependenciesMap = {
92+
astro: [
93+
'eslint-plugin-astro',
94+
'astro-eslint-parser',
95+
],
96+
react: [
97+
'eslint-plugin-react',
98+
'eslint-plugin-react-hooks',
99+
'eslint-plugin-react-refresh',
100+
],
101+
slidev: [
102+
'prettier-plugin-slidev',
103+
],
104+
svelte: [
105+
'eslint-plugin-svelte',
106+
'svelte-eslint-parser',
107+
],
108+
vue: [],
109+
} as const

‎src/cli/index.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
/* eslint-disable no-console */
21
import process from 'node:process'
32
import c from 'picocolors'
43
import { hideBin } from 'yargs/helpers'
54
import yargs from 'yargs'
5+
import * as p from '@clack/prompts'
66
import { run } from './run'
7-
import { CROSS, version } from './constants'
7+
import { pkgJson } from './constants'
88

99
function header() {
10-
console.log(`\n${c.green(`@antfu/eslint-config `)}${c.dim(`v${version}`)}`)
10+
// eslint-disable-next-line no-console
11+
console.log('\n')
12+
p.intro(`${c.green(`@antfu/eslint-config `)}${c.dim(`v${pkgJson.version}`)}`)
1113
}
1214

1315
const instance = yargs(hideBin(process.argv))
@@ -17,24 +19,38 @@ const instance = yargs(hideBin(process.argv))
1719
'*',
1820
'Run the initialization or migration',
1921
args => args
20-
.option('yes', { alias: 'y', description: 'Skip prompts and use default values', type: 'boolean' })
22+
.option('yes', {
23+
alias: 'y',
24+
description: 'Skip prompts and use default values',
25+
type: 'boolean',
26+
})
27+
.option('template', {
28+
alias: 't',
29+
description: 'Use the framework template for optimal customization: vue / react / svelte / astro',
30+
type: 'string',
31+
})
32+
.option('extra', {
33+
alias: 'e',
34+
array: true,
35+
description: 'Use the extra utils: formatter / perfectionist / unocss',
36+
type: 'string',
37+
})
2138
.help(),
2239
async (args) => {
2340
header()
24-
console.log()
2541
try {
2642
await run(args)
2743
}
2844
catch (error) {
29-
console.error(c.inverse(c.red(' Failed to migrate ')))
30-
console.error(c.red(`${CROSS} ${String(error)}`))
45+
p.log.error(c.inverse(c.red(' Failed to migrate ')))
46+
p.log.error(c.red(` ${String(error)}`))
3147
process.exit(1)
3248
}
3349
},
3450
)
3551
.showHelpOnFail(false)
3652
.alias('h', 'help')
37-
.version('version', version)
53+
.version('version', pkgJson.version)
3854
.alias('v', 'version')
3955

4056
// eslint-disable-next-line no-unused-expressions

0 commit comments

Comments
 (0)