diff --git a/index.ts b/index.ts index 19bd910b..36c5357c 100755 --- a/index.ts +++ b/index.ts @@ -120,6 +120,7 @@ async function init() { argv.nightwatch ?? argv.playwright ?? argv.eslint ?? + argv['eslint-with-prettier'] ?? (argv.devtools || argv['vue-devtools']) ) === 'boolean' @@ -463,6 +464,7 @@ async function init() { needsPrettier, needsPlaywright }) + render('config/eslint') } if (needsPrettier) { diff --git a/scripts/snapshot.mjs b/scripts/snapshot.mjs index 01b909fa..93243228 100644 --- a/scripts/snapshot.mjs +++ b/scripts/snapshot.mjs @@ -54,7 +54,7 @@ function fullCombination(arr) { } let flagCombinations = fullCombination(featureFlags) -flagCombinations.push(['default'], ['devtools']) +flagCombinations.push(['default'], ['devtools'], ['eslint'], ['eslint-with-prettier']) // `--with-tests` are equivalent of `--vitest --cypress` // Previously it means `--cypress` without `--vitest`. diff --git a/template/config/eslint/.vscode/extensions.json b/template/config/eslint/.vscode/extensions.json new file mode 100644 index 00000000..940260d8 --- /dev/null +++ b/template/config/eslint/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["dbaeumer.vscode-eslint"] +} diff --git a/template/config/eslint/.vscode/settings.json b/template/config/eslint/.vscode/settings.json new file mode 100644 index 00000000..c8e04def --- /dev/null +++ b/template/config/eslint/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.codeActionsOnSave": { + "source.fixAll": "explicit" + } +} diff --git a/utils/renderEslint.ts b/utils/renderEslint.ts index f92f1ed4..ecb74ae6 100644 --- a/utils/renderEslint.ts +++ b/utils/renderEslint.ts @@ -85,10 +85,4 @@ export default function renderEslint( const fullPath = path.resolve(rootDir, fileName) fs.writeFileSync(fullPath, content as string, 'utf-8') } - - // update .vscode/extensions.json - const extensionsJsonPath = path.resolve(rootDir, '.vscode/extensions.json') - const existingExtensions = JSON.parse(fs.readFileSync(extensionsJsonPath, 'utf8')) - existingExtensions.recommendations.push('dbaeumer.vscode-eslint') - fs.writeFileSync(extensionsJsonPath, JSON.stringify(existingExtensions, null, 2) + '\n', 'utf-8') } diff --git a/utils/renderTemplate.ts b/utils/renderTemplate.ts index 2588dc3f..f2b869e8 100644 --- a/utils/renderTemplate.ts +++ b/utils/renderTemplate.ts @@ -51,6 +51,15 @@ function renderTemplate(src, dest, callbacks) { return } + if (filename === 'settings.json' && fs.existsSync(dest)) { + // merge instead of overwriting + const settings = JSON.parse(fs.readFileSync(dest, 'utf8')) + const newSettings = JSON.parse(fs.readFileSync(src, 'utf8')) + const extensions = deepMerge(settings, newSettings) + fs.writeFileSync(dest, JSON.stringify(settings, null, 2) + '\n') + return + } + if (filename.startsWith('_')) { // rename `_file` to `.file` dest = path.resolve(path.dirname(dest), filename.replace(/^_/, '.'))