@@ -11,12 +11,12 @@ const require = createRequire(import.meta.url)
11
11
const Enquirer = require ( 'enquirer' )
12
12
const enquirer = new Enquirer ( )
13
13
14
- function abort ( ) {
14
+ function abort ( ) {
15
15
console . error ( red ( '✖' ) + ' Operation cancelled' )
16
16
process . exit ( 1 )
17
17
}
18
18
19
- function prompt ( questions ) {
19
+ function prompt ( questions ) {
20
20
return enquirer . prompt ( questions ) . catch ( abort )
21
21
}
22
22
@@ -26,16 +26,22 @@ const requireInCwd = createRequire(path.resolve(cwd, 'index.cjs'))
26
26
// Only works in directories that has a `package.json`
27
27
const pkgJsonPath = path . resolve ( cwd , 'package.json' )
28
28
if ( ! existsSync ( pkgJsonPath ) ) {
29
- console . error ( `${ bold ( yellow ( 'package.json' ) ) } not found in the current directory.` )
29
+ console . error (
30
+ `${ bold ( yellow ( 'package.json' ) ) } not found in the current directory.` ,
31
+ )
30
32
abort ( )
31
33
}
32
34
33
35
const rawPkgJson = readFileSync ( pkgJsonPath , 'utf-8' )
34
- function inferIndent ( rawJson ) {
36
+ function inferIndent ( rawJson ) {
35
37
const lines = rawJson . split ( '\n' )
36
- const firstLineWithIndent = lines . find ( l => l . startsWith ( ' ' ) || l . startsWith ( '\t' ) )
38
+ const firstLineWithIndent = lines . find (
39
+ l => l . startsWith ( ' ' ) || l . startsWith ( '\t' ) ,
40
+ )
37
41
38
- if ( ! firstLineWithIndent ) { return '' }
42
+ if ( ! firstLineWithIndent ) {
43
+ return ''
44
+ }
39
45
return / ^ \s + / . exec ( firstLineWithIndent ) [ 0 ]
40
46
}
41
47
const indent = inferIndent ( rawPkgJson )
@@ -61,7 +67,7 @@ for (const fmt of eslintConfigFormats) {
61
67
message :
62
68
`Found existing ESLint config file: ${ bold ( blue ( configFileName ) ) } .\n` +
63
69
'Do you want to remove the config file and continue?' ,
64
- initial : false
70
+ initial : false ,
65
71
} )
66
72
67
73
if ( shouldRemove ) {
@@ -81,7 +87,7 @@ if (pkg.eslintConfig) {
81
87
message :
82
88
`Found existing ${ bold ( blue ( 'eslintConfig' ) ) } field in ${ bold ( yellow ( 'package.json' ) ) } .\n` +
83
89
'Do you want to remove the config field and continue?' ,
84
- initial : false
90
+ initial : false ,
85
91
} )
86
92
87
93
if ( shouldRemoveConfigField ) {
@@ -105,9 +111,11 @@ if (!vueVersion || !/^3/.test(vueVersion)) {
105
111
enabled : 'Yes' ,
106
112
name : 'continueAnyway' ,
107
113
message : 'Vue 3.x is required but not detected. Continue anyway?' ,
108
- initial : false
114
+ initial : false ,
109
115
} )
110
- if ( ! continueAnyway ) { abort ( ) }
116
+ if ( ! continueAnyway ) {
117
+ abort ( )
118
+ }
111
119
}
112
120
113
121
// 4. Check TypeScript
@@ -126,7 +134,7 @@ const { hasTypeScript } = await prompt({
126
134
enabled : 'Yes' ,
127
135
name : 'hasTypeScript' ,
128
136
message : 'Does your project use TypeScript?' ,
129
- initial : detectedTypeScript
137
+ initial : detectedTypeScript ,
130
138
} )
131
139
132
140
const supportedScriptLangs = { }
@@ -182,15 +190,16 @@ const { needsPrettier } = await prompt({
182
190
disabled : 'No' ,
183
191
enabled : 'Yes' ,
184
192
name : 'needsPrettier' ,
185
- message : 'Do you need Prettier to format your code?'
193
+ message : 'Do you need Prettier to format your code?' ,
186
194
} )
187
195
188
196
const { needsOxlint } = await prompt ( {
189
197
type : 'toggle' ,
190
198
disabled : 'No' ,
191
199
enabled : 'Yes' ,
192
200
name : 'needsOxlint' ,
193
- message : 'Would you like to supplement ESLint with Oxlint for faster linting (experimental)?'
201
+ message :
202
+ 'Would you like to supplement ESLint with Oxlint for faster linting (experimental)?' ,
194
203
} )
195
204
196
205
const { pkg : pkgToExtend , files } = createConfig ( {
@@ -212,14 +221,20 @@ for (const [name, content] of Object.entries(files)) {
212
221
213
222
// Prompt: Run `npm install` or `yarn` or `pnpm install`
214
223
const userAgent = process . env . npm_config_user_agent ?? ''
215
- const packageManager = / p n p m / . test ( userAgent ) ? 'pnpm' : / y a r n / . test ( userAgent ) ? 'yarn' : 'npm'
224
+ const packageManager = / p n p m / . test ( userAgent )
225
+ ? 'pnpm'
226
+ : / y a r n / . test ( userAgent )
227
+ ? 'yarn'
228
+ : 'npm'
216
229
217
- const installCommand = packageManager === 'yarn' ? 'yarn' : `${ packageManager } install`
218
- const lintCommand = packageManager === 'npm' ? 'npm run lint' : `${ packageManager } lint`
230
+ const installCommand =
231
+ packageManager === 'yarn' ? 'yarn' : `${ packageManager } install`
232
+ const lintCommand =
233
+ packageManager === 'npm' ? 'npm run lint' : `${ packageManager } lint`
219
234
220
235
console . info (
221
236
'\n' +
222
- `${ bold ( yellow ( 'package.json' ) ) } and ${ bold ( blue ( 'eslint.config.js' ) ) } have been updated.\n` +
223
- `Now please run ${ bold ( green ( installCommand ) ) } to re-install the dependencies.\n` +
224
- `Then you can run ${ bold ( green ( lintCommand ) ) } to lint your files.`
237
+ `${ bold ( yellow ( 'package.json' ) ) } and ${ bold ( blue ( 'eslint.config.js' ) ) } have been updated.\n` +
238
+ `Now please run ${ bold ( green ( installCommand ) ) } to re-install the dependencies.\n` +
239
+ `Then you can run ${ bold ( green ( lintCommand ) ) } to lint your files.` ,
225
240
)
0 commit comments