@@ -11,12 +11,12 @@ const require = createRequire(import.meta.url)
1111const Enquirer = require ( 'enquirer' )
1212const enquirer = new Enquirer ( )
1313
14- function abort ( ) {
14+ function abort ( ) {
1515 console . error ( red ( '✖' ) + ' Operation cancelled' )
1616 process . exit ( 1 )
1717}
1818
19- function prompt ( questions ) {
19+ function prompt ( questions ) {
2020 return enquirer . prompt ( questions ) . catch ( abort )
2121}
2222
@@ -26,16 +26,22 @@ const requireInCwd = createRequire(path.resolve(cwd, 'index.cjs'))
2626// Only works in directories that has a `package.json`
2727const pkgJsonPath = path . resolve ( cwd , 'package.json' )
2828if ( ! 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+ )
3032 abort ( )
3133}
3234
3335const rawPkgJson = readFileSync ( pkgJsonPath , 'utf-8' )
34- function inferIndent ( rawJson ) {
36+ function inferIndent ( rawJson ) {
3537 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+ )
3741
38- if ( ! firstLineWithIndent ) { return '' }
42+ if ( ! firstLineWithIndent ) {
43+ return ''
44+ }
3945 return / ^ \s + / . exec ( firstLineWithIndent ) [ 0 ]
4046}
4147const indent = inferIndent ( rawPkgJson )
@@ -61,7 +67,7 @@ for (const fmt of eslintConfigFormats) {
6167 message :
6268 `Found existing ESLint config file: ${ bold ( blue ( configFileName ) ) } .\n` +
6369 'Do you want to remove the config file and continue?' ,
64- initial : false
70+ initial : false ,
6571 } )
6672
6773 if ( shouldRemove ) {
@@ -81,7 +87,7 @@ if (pkg.eslintConfig) {
8187 message :
8288 `Found existing ${ bold ( blue ( 'eslintConfig' ) ) } field in ${ bold ( yellow ( 'package.json' ) ) } .\n` +
8389 'Do you want to remove the config field and continue?' ,
84- initial : false
90+ initial : false ,
8591 } )
8692
8793 if ( shouldRemoveConfigField ) {
@@ -105,9 +111,11 @@ if (!vueVersion || !/^3/.test(vueVersion)) {
105111 enabled : 'Yes' ,
106112 name : 'continueAnyway' ,
107113 message : 'Vue 3.x is required but not detected. Continue anyway?' ,
108- initial : false
114+ initial : false ,
109115 } )
110- if ( ! continueAnyway ) { abort ( ) }
116+ if ( ! continueAnyway ) {
117+ abort ( )
118+ }
111119}
112120
113121// 4. Check TypeScript
@@ -126,7 +134,7 @@ const { hasTypeScript } = await prompt({
126134 enabled : 'Yes' ,
127135 name : 'hasTypeScript' ,
128136 message : 'Does your project use TypeScript?' ,
129- initial : detectedTypeScript
137+ initial : detectedTypeScript ,
130138} )
131139
132140const supportedScriptLangs = { }
@@ -182,15 +190,16 @@ const { needsPrettier } = await prompt({
182190 disabled : 'No' ,
183191 enabled : 'Yes' ,
184192 name : 'needsPrettier' ,
185- message : 'Do you need Prettier to format your code?'
193+ message : 'Do you need Prettier to format your code?' ,
186194} )
187195
188196const { needsOxlint } = await prompt ( {
189197 type : 'toggle' ,
190198 disabled : 'No' ,
191199 enabled : 'Yes' ,
192200 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)?' ,
194203} )
195204
196205const { pkg : pkgToExtend , files } = createConfig ( {
@@ -212,14 +221,20 @@ for (const [name, content] of Object.entries(files)) {
212221
213222// Prompt: Run `npm install` or `yarn` or `pnpm install`
214223const 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'
216229
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`
219234
220235console . info (
221236 '\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.` ,
225240)
0 commit comments