|
1 | 1 | import { basename, resolve } from 'node:path' |
2 | 2 |
|
3 | 3 | import { |
| 4 | + formatCommand, |
4 | 5 | getBinaryFile, |
5 | | - packageManagerExecute, |
| 6 | + getPackageManagerScriptCommand, |
6 | 7 | packageManagerInstall, |
7 | 8 | writeConfigFile, |
8 | 9 | } from '@tanstack/cta-core' |
9 | 10 |
|
10 | 11 | import { createPackageJSON } from './package-json.js' |
11 | 12 | import { createTemplateFile } from './template-file.js' |
| 13 | +import { installShadcnComponents } from './integrations/shadcn.js' |
12 | 14 |
|
13 | 15 | import type { |
14 | 16 | Environment, |
@@ -91,11 +93,8 @@ export async function createApp( |
91 | 93 |
|
92 | 94 | const s = silent ? null : environment.spinner() |
93 | 95 |
|
94 | | - // Setup the add-ons |
95 | | - const isAddOnEnabled = (id: string) => |
96 | | - options.chosenAddOns.find((a) => a.id === id) |
| 96 | + // Install all the dependencies |
97 | 97 |
|
98 | | - // Copy all the asset files from the addons |
99 | 98 | for (const phase of ['setup', 'add-on', 'example']) { |
100 | 99 | for (const addOn of options.chosenAddOns.filter( |
101 | 100 | (addOn) => |
@@ -142,81 +141,54 @@ export async function createApp( |
142 | 141 | ) |
143 | 142 | s?.stop(`Installed dependencies`) |
144 | 143 |
|
145 | | - // Run all the commands |
146 | | - if (isAddOnEnabled('shadcn')) { |
147 | | - const shadcnComponents = new Set<string>() |
148 | | - for (const addOn of options.chosenAddOns) { |
149 | | - if (addOn.shadcnComponents) { |
150 | | - for (const component of addOn.shadcnComponents) { |
151 | | - shadcnComponents.add(component) |
152 | | - } |
153 | | - } |
154 | | - } |
155 | | - if (options.starter) { |
156 | | - if (options.starter.shadcnComponents) { |
157 | | - for (const component of options.starter.shadcnComponents) { |
158 | | - shadcnComponents.add(component) |
159 | | - } |
160 | | - } |
161 | | - } |
162 | | - |
163 | | - if (shadcnComponents.size > 0) { |
164 | | - s?.start( |
165 | | - `Installing shadcn components (${Array.from(shadcnComponents).join(', ')})...`, |
166 | | - ) |
167 | | - await packageManagerExecute( |
168 | | - environment, |
169 | | - resolve(targetDir), |
170 | | - options.packageManager, |
171 | | - 'shadcn@latest', |
172 | | - [ |
173 | | - 'add', |
174 | | - '--force', |
175 | | - '--silent', |
176 | | - '--yes', |
177 | | - ...Array.from(shadcnComponents), |
178 | | - ], |
179 | | - ) |
180 | | - s?.stop(`Installed additional shadcn components`) |
181 | | - } |
182 | | - } |
| 144 | + await installShadcnComponents(environment, targetDir, options, silent) |
183 | 145 |
|
184 | 146 | environment.finishRun() |
185 | 147 |
|
186 | 148 | if (!silent) { |
187 | | - // Check for warnings |
188 | | - const warnings: Array<string> = [] |
189 | | - for (const addOn of options.chosenAddOns) { |
190 | | - if (addOn.warning) { |
191 | | - warnings.push(addOn.warning) |
192 | | - } |
193 | | - } |
| 149 | + report(environment, options, appName, targetDir) |
| 150 | + } |
| 151 | +} |
194 | 152 |
|
195 | | - if (warnings.length > 0) { |
196 | | - environment.warn('Warnings', warnings.join('\n')) |
| 153 | +function report( |
| 154 | + environment: Environment, |
| 155 | + options: Options, |
| 156 | + appName: string, |
| 157 | + targetDir: string, |
| 158 | +) { |
| 159 | + const warnings: Array<string> = [] |
| 160 | + for (const addOn of options.chosenAddOns) { |
| 161 | + if (addOn.warning) { |
| 162 | + warnings.push(addOn.warning) |
197 | 163 | } |
| 164 | + } |
| 165 | + |
| 166 | + if (warnings.length > 0) { |
| 167 | + environment.warn('Warnings', warnings.join('\n')) |
| 168 | + } |
198 | 169 |
|
199 | | - // Format errors |
200 | | - let errorStatement = '' |
201 | | - if (environment.getErrors().length) { |
202 | | - errorStatement = ` |
| 170 | + // Format errors |
| 171 | + let errorStatement = '' |
| 172 | + if (environment.getErrors().length) { |
| 173 | + errorStatement = ` |
203 | 174 |
|
204 | 175 | Errors were encountered during this process: |
205 | 176 |
|
206 | 177 | ${environment.getErrors().join('\n')}` |
207 | | - } |
| 178 | + } |
208 | 179 |
|
209 | | - let startCommand = `${options.packageManager} ${isAddOnEnabled('start') ? 'dev' : 'start'}` |
210 | | - if (options.packageManager === 'deno') { |
211 | | - startCommand = `deno ${isAddOnEnabled('start') ? 'task dev' : 'start'}` |
212 | | - } |
| 180 | + const start = !!options.chosenAddOns.find((a) => a.id === 'start') |
| 181 | + const { command, args } = getPackageManagerScriptCommand( |
| 182 | + options.packageManager, |
| 183 | + start ? ['dev'] : ['start'], |
| 184 | + ) |
| 185 | + const startCommand = formatCommand(command, args) |
213 | 186 |
|
214 | | - environment.outro(`Your ${appName} app is ready in '${basename(targetDir)}'. |
| 187 | + environment.outro(`Your ${appName} app is ready in '${basename(targetDir)}'. |
215 | 188 |
|
216 | 189 | Use the following commands to start your app: |
217 | 190 | % cd ${options.projectName} |
218 | 191 | % ${startCommand} |
219 | 192 |
|
220 | | -Please check the README.md for more information on testing, styling, adding routes, etc.${errorStatement}`) |
221 | | - } |
| 193 | + Please check the README.md for more information on testing, styling, adding routes, etc.${errorStatement}`) |
222 | 194 | } |
0 commit comments