From 8a1012f491b4d033ab83c04fc21d3393bf8ae1b0 Mon Sep 17 00:00:00 2001 From: Yoshipi Date: Thu, 14 Mar 2024 19:54:45 +0900 Subject: [PATCH 1/3] feat: add vscode config for ESLint #466 --- template/config/eslint/.vscode/extensions.json | 3 +++ template/config/eslint/.vscode/settings.json | 5 +++++ utils/renderEslint.ts | 6 ------ utils/renderTemplate.ts | 9 +++++++++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 template/config/eslint/.vscode/extensions.json create mode 100644 template/config/eslint/.vscode/settings.json 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(/^_/, '.')) From 7ef6604e9744b9b07d14d7d6fadc42cfa2c879bf Mon Sep 17 00:00:00 2001 From: Yoshipi Date: Thu, 14 Mar 2024 19:54:54 +0900 Subject: [PATCH 2/3] chore: add ESLint and Prettier to snapshot --- index.ts | 2 ++ scripts/snapshot.mjs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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..d42313cb 100644 --- a/scripts/snapshot.mjs +++ b/scripts/snapshot.mjs @@ -15,9 +15,12 @@ const featureFlags = [ 'vitest', 'cypress', 'playwright', - 'nightwatch' + 'nightwatch', + 'eslint', + 'eslint-with-prettier' ] const featureFlagsDenylist = [ + ['eslint', 'eslint-with-prettier'], ['cypress', 'playwright'], ['playwright', 'nightwatch'], ['cypress', 'nightwatch'], From 1a3539717405aa3825a997b9007b3bd5572a15c7 Mon Sep 17 00:00:00 2001 From: Yoshipi Date: Fri, 15 Mar 2024 11:41:18 +0900 Subject: [PATCH 3/3] refactor: move eslint and eslint-with-prettier as a separate feature flag --- scripts/snapshot.mjs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/snapshot.mjs b/scripts/snapshot.mjs index d42313cb..93243228 100644 --- a/scripts/snapshot.mjs +++ b/scripts/snapshot.mjs @@ -15,12 +15,9 @@ const featureFlags = [ 'vitest', 'cypress', 'playwright', - 'nightwatch', - 'eslint', - 'eslint-with-prettier' + 'nightwatch' ] const featureFlagsDenylist = [ - ['eslint', 'eslint-with-prettier'], ['cypress', 'playwright'], ['playwright', 'nightwatch'], ['cypress', 'nightwatch'], @@ -57,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`.