@@ -45,19 +45,27 @@ export default function renderEslint(
4545 additionalDependencies
4646 } )
4747
48+ const scripts : Record < string , string > = {
49+ // Note that we reuse .gitignore here to avoid duplicating the configuration
50+ lint : needsTypeScript
51+ ? 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore'
52+ : 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore'
53+ }
54+
55+ // Theoretically, we could add Prettier without requring ESLint.
56+ // But it doesn't seem to be a good practice, so we just leave it here.
57+ if ( needsPrettier ) {
58+ // Default to only format the `src/` directory to avoid too much noise, and
59+ // the need for a `.prettierignore` file.
60+ // Users can still append any paths they'd like to format to the command,
61+ // e.g. `npm run format cypress/`.
62+ scripts . format = 'prettier --write src/'
63+ }
64+
4865 // update package.json
4966 const packageJsonPath = path . resolve ( rootDir , 'package.json' )
5067 const existingPkg = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) )
51- const updatedPkg = sortDependencies (
52- deepMerge ( deepMerge ( existingPkg , pkg ) , {
53- scripts : {
54- // Note that we reuse .gitignore here to avoid duplicating the configuration
55- lint : needsTypeScript
56- ? 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore'
57- : 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore'
58- }
59- } )
60- )
68+ const updatedPkg = sortDependencies ( deepMerge ( deepMerge ( existingPkg , pkg ) , { scripts } ) )
6169 fs . writeFileSync ( packageJsonPath , JSON . stringify ( updatedPkg , null , 2 ) + '\n' , 'utf-8' )
6270
6371 // write to .eslintrc.cjs, .prettierrc.json, etc.
0 commit comments