From: Haoqun Jiang Date: Wed, 22 Feb 2023 13:11:04 +0000 (+0800) Subject: feat: use separate commands for linting and formatting X-Git-Tag: v3.6.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fde3d1f07a5d5e3792e4c0bf457d6e9f4af4937;p=thirdparty%2Fvuejs%2Fcreate-vue.git feat: use separate commands for linting and formatting Closes #190 --- diff --git a/index.ts b/index.ts index 0fc6bb45..bfd82c71 100755 --- a/index.ts +++ b/index.ts @@ -450,7 +450,7 @@ async function init() { } console.log(` ${bold(green(getCommand(packageManager, 'install')))}`) if (needsPrettier) { - console.log(` ${bold(green(getCommand(packageManager, 'lint')))}`) + console.log(` ${bold(green(getCommand(packageManager, 'format')))}`) } console.log(` ${bold(green(getCommand(packageManager, 'dev')))}`) console.log() diff --git a/utils/renderEslint.ts b/utils/renderEslint.ts index b6033a7c..762f0f88 100644 --- a/utils/renderEslint.ts +++ b/utils/renderEslint.ts @@ -45,19 +45,27 @@ export default function renderEslint( additionalDependencies }) + const scripts: Record = { + // Note that we reuse .gitignore here to avoid duplicating the configuration + lint: needsTypeScript + ? 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore' + : 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore' + } + + // Theoretically, we could add Prettier without requring ESLint. + // But it doesn't seem to be a good practice, so we just leave it here. + if (needsPrettier) { + // Default to only format the `src/` directory to avoid too much noise, and + // the need for a `.prettierignore` file. + // Users can still append any paths they'd like to format to the command, + // e.g. `npm run format cypress/`. + scripts.format = 'prettier --write src/' + } + // update package.json const packageJsonPath = path.resolve(rootDir, 'package.json') const existingPkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) - const updatedPkg = sortDependencies( - deepMerge(deepMerge(existingPkg, pkg), { - scripts: { - // Note that we reuse .gitignore here to avoid duplicating the configuration - lint: needsTypeScript - ? 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore' - : 'eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore' - } - }) - ) + const updatedPkg = sortDependencies(deepMerge(deepMerge(existingPkg, pkg), { scripts })) fs.writeFileSync(packageJsonPath, JSON.stringify(updatedPkg, null, 2) + '\n', 'utf-8') // write to .eslintrc.cjs, .prettierrc.json, etc.