From 3ee5af01b76f4b5612cd35800296a3b7f0588596 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 9 Jun 2025 11:16:59 +0800 Subject: [PATCH 1/2] feat: add `rolldown-vite` features --- index.ts | 64 +++++++++++++++++++++++++++++++------------- locales/en-US.json | 12 ++++++++- locales/fr-FR.json | 12 ++++++++- locales/tr-TR.json | 12 ++++++++- locales/zh-Hans.json | 12 ++++++++- locales/zh-Hant.json | 12 ++++++++- utils/getLanguage.ts | 3 +++ 7 files changed, 104 insertions(+), 23 deletions(-) diff --git a/index.ts b/index.ts index 123cb430..8aa38250 100755 --- a/index.ts +++ b/index.ts @@ -39,8 +39,9 @@ const FEATURE_FLAGS = [ 'playwright', 'eslint', 'prettier', - 'eslint-with-oxlint', 'eslint-with-prettier', + 'oxlint', + 'rolldown-vite', ] as const const FEATURE_OPTIONS = [ @@ -76,6 +77,20 @@ const FEATURE_OPTIONS = [ value: 'prettier', label: language.needsPrettier.message, }, + { + value: 'experimental features', + label: language.needExperimenttal.message, + }, +] as const +const EXPERIMENTAL_FEATURE_OPTIONS = [ + { + value: 'oxlint', + label: language.needsOxlint.message, + }, + { + value: 'rolldown-vite', + label: language.needsRolldownVite.message, + }, ] as const type PromptResult = { @@ -84,7 +99,7 @@ type PromptResult = { packageName?: string features?: (typeof FEATURE_OPTIONS)[number]['value'][] e2eFramework?: 'cypress' | 'nightwatch' | 'playwright' - experimentOxlint?: boolean + experimentFeatures?: (typeof EXPERIMENTAL_FEATURE_OPTIONS)[number]['value'][] } function isValidPackageName(projectName) { @@ -177,12 +192,14 @@ Available feature flags: If used without ${cyan('--vitest')}, it will also add Nightwatch Component Testing. --eslint Add ESLint for code quality. - --eslint-with-oxlint - Add ESLint for code quality, and use Oxlint to speed up the linting process. --eslint-with-prettier (Deprecated in favor of ${cyan('--eslint --prettier')}) Add Prettier for code formatting in addition to ESLint. --prettier Add Prettier for code formatting. + --oxlint + Add Oxlint for code quality and formatting. + --rolldown-vite + Use Rolldown Vite instead of Vite for building the project. Unstable feature flags: --tests, --with-tests @@ -232,7 +249,7 @@ async function init() { packageName: defaultProjectName, features: [], e2eFramework: undefined, - experimentOxlint: false, + experimentFeatures: [], } intro( @@ -322,31 +339,30 @@ async function init() { ) } - if (result.features.includes('eslint')) { - result.experimentOxlint = await unwrapPrompt( - confirm({ - message: language.needsOxlint.message, - initialValue: false, + if (result.features.includes('experimental features')) { + result.experimentFeatures = await unwrapPrompt( + multiselect({ + message: `${language.needsExperimentalFeatures.message} ${dim(language.needsExperimentalFeatures.hint)}`, + // @ts-expect-error @clack/prompt's type doesn't support readonly array yet + options: EXPERIMENTAL_FEATURE_OPTIONS, + required: false, }), ) } } - const { features } = result + const { features, experimentFeatures } = result const needsTypeScript = argv.ts || argv.typescript || features.includes('typescript') const needsJsx = argv.jsx || features.includes('jsx') const needsRouter = argv.router || argv['vue-router'] || features.includes('router') const needsPinia = argv.pinia || features.includes('pinia') const needsVitest = argv.vitest || argv.tests || features.includes('vitest') - const needsEslint = - argv.eslint || - argv['eslint-with-oxlint'] || - argv['eslint-with-prettier'] || - features.includes('eslint') + const needsEslint = argv.eslint || argv['eslint-with-prettier'] || features.includes('eslint') const needsPrettier = argv.prettier || argv['eslint-with-prettier'] || features.includes('prettier') - const needsOxlint = argv['eslint-with-oxlint'] || result.experimentOxlint + const needsOxlint = experimentFeatures.includes('oxlint') || argv['oxlint'] + const needsRolldownVite = experimentFeatures.includes('rolldown-vite') || argv['rolldown-vite'] const { e2eFramework } = result const needsCypress = argv.cypress || argv.tests || e2eFramework === 'cypress' @@ -374,6 +390,13 @@ async function init() { const templateDir = path.resolve(templateRoot, templateName) renderTemplate(templateDir, root, callbacks) } + const replaceVite = () => { + const content = fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8') + const json = JSON.parse(content) + // Replace `vite` with `rolldown-vite` if the feature is enabled + json.devDependencies.vite = 'npm:rolldown-vite@latest' + fs.writeFileSync(path.resolve(root, 'package.json'), JSON.stringify(json, null, 2)) + } // Render base template render('base') @@ -471,7 +494,7 @@ async function init() { } // Render ESLint config - if (needsEslint) { + if (needsEslint || needsOxlint) { renderEslint(root, { needsTypeScript, needsOxlint, @@ -492,6 +515,11 @@ async function init() { render('config/prettier') } + // use rolldown-vite if the feature is enabled + if (needsRolldownVite) { + replaceVite() + } + // Render code template. // prettier-ignore const codeTemplate = diff --git a/locales/en-US.json b/locales/en-US.json index 24c335dc..b0aa57f2 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -60,7 +60,17 @@ } }, "needsOxlint": { - "message": "Install Oxlint for faster linting? (experimental)" + "message": "Oxlint (experimental)" + }, + "needExperimenttal": { + "message": "Enable experimental features" + }, + "needsExperimentalFeatures": { + "message": "Select experimental features to include in your project:", + "hint": "(↑/↓ to navigate, space to select, a to toggle all, enter to confirm)" + }, + "needsRolldownVite": { + "message": "rolldown-vite (experimental)" }, "errors": { "operationCancelled": "Operation cancelled" diff --git a/locales/fr-FR.json b/locales/fr-FR.json index 480df305..eceeab3c 100644 --- a/locales/fr-FR.json +++ b/locales/fr-FR.json @@ -60,7 +60,17 @@ } }, "needsOxlint": { - "message": "Installer Oxlint pour un linting plus rapide\u00a0? (expérimental)" + "message": "Oxlint (expérimental)" + }, + "needExperimenttal": { + "message": "Activer les fonctionnalités expérimentales" + }, + "needsExperimentalFeatures": { + "message": "Sélectionnez les fonctionnalités expérimentales à inclure:", + "hint": "(↑/↓ pour naviguer, espace pour sélectionner, a pour tout sélectionner, entrée pour confirmer)" + }, + "needsRolldownVite": { + "message": "rolldown-vite (expérimental)" }, "errors": { "operationCancelled": "Operation annulée" diff --git a/locales/tr-TR.json b/locales/tr-TR.json index 60c71a2c..bfd41c39 100644 --- a/locales/tr-TR.json +++ b/locales/tr-TR.json @@ -60,7 +60,17 @@ } }, "needsOxlint": { - "message": "Daha hızlı linting için Oxlint eklensin mi? (deneysel)" + "message": "Oxlint (deneysel)" + }, + "needExperimenttal": { + "message": "Deneysel özellikleri etkinleştir" + }, + "needsExperimentalFeatures": { + "message": "Dahil edilecek deneysel özellikleri seçin:", + "hint": "(↑/↓ gezinmek için, boşluk seçmek için, a tümünü seçmek için, enter onaylamak için)" + }, + "needsRolldownVite": { + "message": "rolldown-vite (deneysel)" }, "errors": { "operationCancelled": "İşlem iptal edildi" diff --git a/locales/zh-Hans.json b/locales/zh-Hans.json index 92e367ad..f2cfbab3 100644 --- a/locales/zh-Hans.json +++ b/locales/zh-Hans.json @@ -60,7 +60,17 @@ } }, "needsOxlint": { - "message": "是否引入 Oxlint 以加快检测?(试验阶段)" + "message": "Oxlint(试验阶段)" + }, + "needExperimenttal": { + "message": "启用试验特性" + }, + "needsExperimentalFeatures": { + "message": "选择要包含的试验特性:", + "hint": "(↑/↓ 切换,空格选择,a 全选,回车确认)" + }, + "needsRolldownVite": { + "message": "rolldown-vite(试验阶段)" }, "errors": { "operationCancelled": "操作取消" diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json index d7b80b95..82f229ac 100644 --- a/locales/zh-Hant.json +++ b/locales/zh-Hant.json @@ -60,7 +60,17 @@ } }, "needsOxlint": { - "message": "是否引入 Oxlint 以加快檢測?(試驗性功能)" + "message": "Oxlint(試驗性功能)" + }, + "needExperimenttal": { + "message": "启用試驗性功能" + }, + "needsExperimentalFeatures": { + "message": "請選擇要包含的試驗特性:", + "hint": "(↑/↓ 切換,空格選擇,a 全選,enter 確認)" + }, + "needsRolldownVite": { + "message": "rolldown-vite(試驗性功能)" }, "errors": { "operationCancelled": "操作取消" diff --git a/utils/getLanguage.ts b/utils/getLanguage.ts index 5b60fe38..9a95429b 100644 --- a/utils/getLanguage.ts +++ b/utils/getLanguage.ts @@ -37,7 +37,10 @@ interface Language { [key: string]: { title: string; desc?: string; hintOnComponentTesting?: string } } } + needExperimenttal: LanguageItem + needsExperimentalFeatures: LanguageItem needsOxlint: LanguageItem + needsRolldownVite: LanguageItem errors: { operationCancelled: string } From 45fe738b7af59b463ac949c5fd7ed532a2ee7aec Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 11 Jun 2025 09:16:20 +0800 Subject: [PATCH 2/2] feat: apply suggest --- index.ts | 6 +++--- locales/en-US.json | 2 +- locales/fr-FR.json | 4 ++-- locales/tr-TR.json | 2 +- locales/zh-Hans.json | 2 +- locales/zh-Hant.json | 2 +- utils/getLanguage.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index 8aa38250..b5918f8d 100755 --- a/index.ts +++ b/index.ts @@ -78,8 +78,8 @@ const FEATURE_OPTIONS = [ label: language.needsPrettier.message, }, { - value: 'experimental features', - label: language.needExperimenttal.message, + value: 'experimental-features', + label: language.needsExperimental.message, }, ] as const const EXPERIMENTAL_FEATURE_OPTIONS = [ @@ -339,7 +339,7 @@ async function init() { ) } - if (result.features.includes('experimental features')) { + if (result.features.includes('experimental-features')) { result.experimentFeatures = await unwrapPrompt( multiselect({ message: `${language.needsExperimentalFeatures.message} ${dim(language.needsExperimentalFeatures.hint)}`, diff --git a/locales/en-US.json b/locales/en-US.json index b0aa57f2..57c6790e 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -62,7 +62,7 @@ "needsOxlint": { "message": "Oxlint (experimental)" }, - "needExperimenttal": { + "needsExperimental": { "message": "Enable experimental features" }, "needsExperimentalFeatures": { diff --git a/locales/fr-FR.json b/locales/fr-FR.json index eceeab3c..a8b6d1be 100644 --- a/locales/fr-FR.json +++ b/locales/fr-FR.json @@ -62,11 +62,11 @@ "needsOxlint": { "message": "Oxlint (expérimental)" }, - "needExperimenttal": { + "needsExperimental": { "message": "Activer les fonctionnalités expérimentales" }, "needsExperimentalFeatures": { - "message": "Sélectionnez les fonctionnalités expérimentales à inclure:", + "message": "Sélectionnez les fonctionnalités expérimentales à inclure\u00a0:", "hint": "(↑/↓ pour naviguer, espace pour sélectionner, a pour tout sélectionner, entrée pour confirmer)" }, "needsRolldownVite": { diff --git a/locales/tr-TR.json b/locales/tr-TR.json index bfd41c39..c42b6823 100644 --- a/locales/tr-TR.json +++ b/locales/tr-TR.json @@ -62,7 +62,7 @@ "needsOxlint": { "message": "Oxlint (deneysel)" }, - "needExperimenttal": { + "needsExperimental": { "message": "Deneysel özellikleri etkinleştir" }, "needsExperimentalFeatures": { diff --git a/locales/zh-Hans.json b/locales/zh-Hans.json index f2cfbab3..db41975c 100644 --- a/locales/zh-Hans.json +++ b/locales/zh-Hans.json @@ -62,7 +62,7 @@ "needsOxlint": { "message": "Oxlint(试验阶段)" }, - "needExperimenttal": { + "needsExperimental": { "message": "启用试验特性" }, "needsExperimentalFeatures": { diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json index 82f229ac..53046101 100644 --- a/locales/zh-Hant.json +++ b/locales/zh-Hant.json @@ -62,7 +62,7 @@ "needsOxlint": { "message": "Oxlint(試驗性功能)" }, - "needExperimenttal": { + "needsExperimental": { "message": "启用試驗性功能" }, "needsExperimentalFeatures": { diff --git a/utils/getLanguage.ts b/utils/getLanguage.ts index 9a95429b..ade2c606 100644 --- a/utils/getLanguage.ts +++ b/utils/getLanguage.ts @@ -37,7 +37,7 @@ interface Language { [key: string]: { title: string; desc?: string; hintOnComponentTesting?: string } } } - needExperimenttal: LanguageItem + needsExperimental: LanguageItem needsExperimentalFeatures: LanguageItem needsOxlint: LanguageItem needsRolldownVite: LanguageItem