@@ -5,14 +5,11 @@ import { create } from 'zustand'
55import { Tabs , type TabDefinition } from './Tabs'
66import { CodeBlock } from './CodeBlock'
77import type { Framework } from '~/libraries/types'
8-
9- type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn'
10- type InstallMode =
11- | 'install'
12- | 'dev-install'
13- | 'local-install'
14- | 'create'
15- | 'custom'
8+ import {
9+ getInstallCommand ,
10+ type PackageManager ,
11+ type InstallMode ,
12+ } from '~/utils/markdown/installCommand'
1613
1714// Use zustand for cross-component synchronization
1815// This ensures all PackageManagerTabs instances on the page stay in sync
@@ -38,117 +35,6 @@ type PackageManagerTabsProps = {
3835
3936const PACKAGE_MANAGERS : PackageManager [ ] = [ 'npm' , 'pnpm' , 'yarn' , 'bun' ]
4037
41- function getInstallCommand (
42- packageManager : PackageManager ,
43- packageGroups : string [ ] [ ] ,
44- mode : InstallMode ,
45- ) : string [ ] {
46- const commands : string [ ] = [ ]
47-
48- if ( mode === 'custom' ) {
49- for ( const packages of packageGroups ) {
50- const pkgStr = packages . join ( ' ' )
51- switch ( packageManager ) {
52- case 'npm' :
53- commands . push ( `npm ${ pkgStr } ` )
54- break
55- case 'pnpm' :
56- commands . push ( `pnpm ${ pkgStr } ` )
57- break
58- case 'yarn' :
59- commands . push ( `yarn ${ pkgStr } ` )
60- break
61- case 'bun' :
62- commands . push ( `bun ${ pkgStr } ` )
63- break
64- }
65- }
66- }
67-
68- if ( mode === 'create' ) {
69- for ( const packages of packageGroups ) {
70- const pkgStr = packages . join ( ' ' )
71- switch ( packageManager ) {
72- case 'npm' :
73- commands . push ( `npm create ${ pkgStr } ` )
74- break
75- case 'pnpm' :
76- commands . push ( `pnpm create ${ pkgStr } ` )
77- break
78- case 'yarn' :
79- commands . push ( `yarn create ${ pkgStr } ` )
80- break
81- case 'bun' :
82- commands . push ( `bun create ${ pkgStr } ` )
83- break
84- }
85- }
86- }
87-
88- if ( mode === 'local-install' ) {
89- // Each group becomes one command line
90- for ( const packages of packageGroups ) {
91- const pkgStr = packages . join ( ' ' )
92- switch ( packageManager ) {
93- case 'npm' :
94- commands . push ( `npx ${ pkgStr } ` )
95- break
96- case 'pnpm' :
97- commands . push ( `pnpx ${ pkgStr } ` )
98- break
99- case 'yarn' :
100- commands . push ( `yarn dlx ${ pkgStr } ` )
101- break
102- case 'bun' :
103- commands . push ( `bunx ${ pkgStr } ` )
104- break
105- }
106- }
107- return commands
108- }
109-
110- if ( mode === 'dev-install' ) {
111- for ( const packages of packageGroups ) {
112- const pkgStr = packages . join ( ' ' )
113- switch ( packageManager ) {
114- case 'npm' :
115- commands . push ( `npm i -D ${ pkgStr } ` )
116- break
117- case 'pnpm' :
118- commands . push ( `pnpm add -D ${ pkgStr } ` )
119- break
120- case 'yarn' :
121- commands . push ( `yarn add -D ${ pkgStr } ` )
122- break
123- case 'bun' :
124- commands . push ( `bun add -d ${ pkgStr } ` )
125- break
126- }
127- }
128- return commands
129- }
130-
131- // install mode
132- for ( const packages of packageGroups ) {
133- const pkgStr = packages . join ( ' ' )
134- switch ( packageManager ) {
135- case 'npm' :
136- commands . push ( `npm i ${ pkgStr } ` )
137- break
138- case 'pnpm' :
139- commands . push ( `pnpm add ${ pkgStr } ` )
140- break
141- case 'yarn' :
142- commands . push ( `yarn add ${ pkgStr } ` )
143- break
144- case 'bun' :
145- commands . push ( `bun add ${ pkgStr } ` )
146- break
147- }
148- }
149- return commands
150- }
151-
15238export function PackageManagerTabs ( {
15339 packagesByFramework,
15440 mode,
0 commit comments