@@ -7,7 +7,12 @@ import { CodeBlock } from './CodeBlock'
77import type { Framework } from '~/libraries/types'
88
99type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn'
10- type InstallMode = 'install' | 'dev-install'
10+ type InstallMode =
11+ | 'install'
12+ | 'dev-install'
13+ | 'local-install'
14+ | 'create'
15+ | 'custom'
1116
1217// Use zustand for cross-component synchronization
1318// This ensures all PackageManagerTabs instances on the page stay in sync
@@ -27,7 +32,7 @@ const usePackageManagerStore = create<{
2732
2833type PackageManagerTabsProps = {
2934 id : string
30- packagesByFramework : Record < string , string [ ] >
35+ packagesByFramework : Record < string , string [ ] [ ] >
3136 mode : InstallMode
3237 frameworks : Framework [ ]
3338}
@@ -36,45 +41,109 @@ const PACKAGE_MANAGERS: PackageManager[] = ['npm', 'pnpm', 'yarn', 'bun']
3641
3742function getInstallCommand (
3843 packageManager : PackageManager ,
39- packages : string [ ] ,
44+ packageGroups : string [ ] [ ] ,
4045 mode : InstallMode ,
4146) : string [ ] {
4247 const commands : string [ ] = [ ]
4348
49+ if ( mode === 'custom' ) {
50+ for ( const packages of packageGroups ) {
51+ const pkgStr = packages . join ( ' ' )
52+ switch ( packageManager ) {
53+ case 'npm' :
54+ commands . push ( `npm ${ pkgStr } ` )
55+ break
56+ case 'pnpm' :
57+ commands . push ( `pnpm ${ pkgStr } ` )
58+ break
59+ case 'yarn' :
60+ commands . push ( `yarn ${ pkgStr } ` )
61+ break
62+ case 'bun' :
63+ commands . push ( `bun ${ pkgStr } ` )
64+ break
65+ }
66+ }
67+ }
68+
69+ if ( mode === 'create' ) {
70+ for ( const packages of packageGroups ) {
71+ const pkgStr = packages . join ( ' ' )
72+ switch ( packageManager ) {
73+ case 'npm' :
74+ commands . push ( `npm create ${ pkgStr } ` )
75+ break
76+ case 'pnpm' :
77+ commands . push ( `pnpm create ${ pkgStr } ` )
78+ break
79+ case 'yarn' :
80+ commands . push ( `yarn create ${ pkgStr } ` )
81+ break
82+ case 'bun' :
83+ commands . push ( `bun create ${ pkgStr } ` )
84+ break
85+ }
86+ }
87+ }
88+
89+ if ( mode === 'local-install' ) {
90+ // Each group becomes one command line
91+ for ( const packages of packageGroups ) {
92+ const pkgStr = packages . join ( ' ' )
93+ switch ( packageManager ) {
94+ case 'npm' :
95+ commands . push ( `npx ${ pkgStr } ` )
96+ break
97+ case 'pnpm' :
98+ commands . push ( `pnpx ${ pkgStr } ` )
99+ break
100+ case 'yarn' :
101+ commands . push ( `yarn dlx ${ pkgStr } ` )
102+ break
103+ case 'bun' :
104+ commands . push ( `bunx ${ pkgStr } ` )
105+ break
106+ }
107+ }
108+ return commands
109+ }
110+
44111 if ( mode === 'dev-install' ) {
45- for ( const pkg of packages ) {
112+ for ( const packages of packageGroups ) {
113+ const pkgStr = packages . join ( ' ' )
46114 switch ( packageManager ) {
47115 case 'npm' :
48- commands . push ( `npm i -D ${ pkg } ` )
116+ commands . push ( `npm i -D ${ pkgStr } ` )
49117 break
50118 case 'pnpm' :
51- commands . push ( `pnpm add -D ${ pkg } ` )
119+ commands . push ( `pnpm add -D ${ pkgStr } ` )
52120 break
53121 case 'yarn' :
54- commands . push ( `yarn add -D ${ pkg } ` )
122+ commands . push ( `yarn add -D ${ pkgStr } ` )
55123 break
56124 case 'bun' :
57- commands . push ( `bun add -d ${ pkg } ` )
125+ commands . push ( `bun add -d ${ pkgStr } ` )
58126 break
59127 }
60128 }
61129 return commands
62130 }
63131
64132 // install mode
65- for ( const pkg of packages ) {
133+ for ( const packages of packageGroups ) {
134+ const pkgStr = packages . join ( ' ' )
66135 switch ( packageManager ) {
67136 case 'npm' :
68- commands . push ( `npm i ${ pkg } ` )
137+ commands . push ( `npm i ${ pkgStr } ` )
69138 break
70139 case 'pnpm' :
71- commands . push ( `pnpm add ${ pkg } ` )
140+ commands . push ( `pnpm add ${ pkgStr } ` )
72141 break
73142 case 'yarn' :
74- commands . push ( `yarn add ${ pkg } ` )
143+ commands . push ( `yarn add ${ pkgStr } ` )
75144 break
76145 case 'bun' :
77- commands . push ( `bun add ${ pkg } ` )
146+ commands . push ( `bun add ${ pkgStr } ` )
78147 break
79148 }
80149 }
@@ -100,10 +169,10 @@ export function PackageManagerTabs({
100169 'react' ) as Framework
101170
102171 const normalizedFramework = actualFramework . toLowerCase ( )
103- const packages = packagesByFramework [ normalizedFramework ]
172+ const packageGroups = packagesByFramework [ normalizedFramework ]
104173
105174 // Hide component if current framework not in package list
106- if ( ! packages || packages . length === 0 ) {
175+ if ( ! packageGroups || packageGroups . length === 0 ) {
107176 return null
108177 }
109178
@@ -121,7 +190,7 @@ export function PackageManagerTabs({
121190
122191 // Generate children (command blocks) for each package manager
123192 const children = PACKAGE_MANAGERS . map ( ( pm ) => {
124- const commands = getInstallCommand ( pm , packages , mode )
193+ const commands = getInstallCommand ( pm , packageGroups , mode )
125194 const commandText = commands . join ( '\n' )
126195 return (
127196 < CodeBlock key = { pm } >
0 commit comments