From 13f7b9dbc95b31b9d1ab004f6e29fff02d4c54a0 Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 23 Sep 2022 15:32:36 +0800 Subject: [PATCH 1/3] feat(create-vite): support create-vite-extra --- packages/create-vite/src/index.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index 799ca93a75cd47..56c3f4ff1d61a3 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -29,7 +29,8 @@ type Framework = { name: string display: string color: ColorFunc - variants: FrameworkVariant[] + customCommand?: string + variants?: FrameworkVariant[] } type FrameworkVariant = { name: string @@ -158,6 +159,12 @@ const FRAMEWORKS: Framework[] = [ customCommand: 'npm create svelte@latest TARGET_DIR' } ] + }, + { + name: 'others', + display: 'Others', + color: reset, + customCommand: 'npm create vite-extra@latest TARGET_DIR' } ] @@ -247,7 +254,7 @@ async function init() { name: 'variant', message: reset('Select a variant:'), choices: (framework: Framework) => - framework.variants.map((variant) => { + framework.variants?.map((variant) => { const variantColor = variant.color return { title: variantColor(variant.display || variant.name), @@ -279,14 +286,17 @@ async function init() { } // determine template - const template: string = variant || framework || argTemplate + const template: string = variant || framework?.name || argTemplate const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent) const pkgManager = pkgInfo ? pkgInfo.name : 'npm' const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.') - const { customCommand } = - FRAMEWORKS.flatMap((f) => f.variants).find((v) => v.name === template) ?? {} + const customCommand = + FRAMEWORKS.find((f) => f.name === template)?.customCommand ?? + FRAMEWORKS.flatMap((f) => f.variants).find((v) => v?.name === template) + ?.customCommand + if (customCommand) { const fullCustomCommand = customCommand .replace('TARGET_DIR', targetDir) From a567995aa1d5c4992729c81e78c2d9dc98db521b Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 23 Sep 2022 21:57:43 +0800 Subject: [PATCH 2/3] chore: move under others --- packages/create-vite/src/index.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index 56c3f4ff1d61a3..3c4a96146cdeba 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -29,8 +29,7 @@ type Framework = { name: string display: string color: ColorFunc - customCommand?: string - variants?: FrameworkVariant[] + variants: FrameworkVariant[] } type FrameworkVariant = { name: string @@ -164,7 +163,14 @@ const FRAMEWORKS: Framework[] = [ name: 'others', display: 'Others', color: reset, - customCommand: 'npm create vite-extra@latest TARGET_DIR' + variants: [ + { + name: 'create-vite-extra', + display: 'create-vite-extra', + color: reset, + customCommand: 'npm create vite-extra@latest TARGET_DIR' + } + ] } ] @@ -254,7 +260,7 @@ async function init() { name: 'variant', message: reset('Select a variant:'), choices: (framework: Framework) => - framework.variants?.map((variant) => { + framework.variants.map((variant) => { const variantColor = variant.color return { title: variantColor(variant.display || variant.name), @@ -292,10 +298,8 @@ async function init() { const pkgManager = pkgInfo ? pkgInfo.name : 'npm' const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.') - const customCommand = - FRAMEWORKS.find((f) => f.name === template)?.customCommand ?? - FRAMEWORKS.flatMap((f) => f.variants).find((v) => v?.name === template) - ?.customCommand + const { customCommand } = + FRAMEWORKS.flatMap((f) => f.variants).find((v) => v.name === template) ?? {} if (customCommand) { const fullCustomCommand = customCommand From 502665c9e3d517f50e218b29d941de17e9d6b87d Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 23 Sep 2022 22:55:02 +0800 Subject: [PATCH 3/3] feat: add arrows for external cli --- packages/create-vite/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index 3c4a96146cdeba..d6407b8b3b4c17 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -73,13 +73,13 @@ const FRAMEWORKS: Framework[] = [ }, { name: 'custom-create-vue', - display: 'Customize with create-vue', + display: 'Customize with create-vue ↗', color: green, customCommand: 'npm create vue@latest TARGET_DIR' }, { name: 'custom-nuxt', - display: 'Nuxt', + display: 'Nuxt ↗', color: lightGreen, customCommand: 'npm exec nuxi init TARGET_DIR' } @@ -153,7 +153,7 @@ const FRAMEWORKS: Framework[] = [ }, { name: 'custom-svelte-kit', - display: 'SvelteKit', + display: 'SvelteKit ↗', color: red, customCommand: 'npm create svelte@latest TARGET_DIR' } @@ -166,7 +166,7 @@ const FRAMEWORKS: Framework[] = [ variants: [ { name: 'create-vite-extra', - display: 'create-vite-extra', + display: 'create-vite-extra ↗', color: reset, customCommand: 'npm create vite-extra@latest TARGET_DIR' }