Skip to content

Commit 24ea6ba

Browse files
committed
fix: reporting errors from command line executions
1 parent c44954b commit 24ea6ba

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/create-app.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ export async function createApp(
275275
environment: Environment
276276
},
277277
) {
278+
environment.startRun()
279+
278280
const templateDirBase = fileURLToPath(
279281
new URL(`../templates/${options.framework}/base`, import.meta.url),
280282
)
@@ -630,14 +632,24 @@ export async function createApp(
630632
s?.stop(`Initialized git repository`)
631633
}
632634

635+
environment.finishRun()
636+
637+
let errorStatement = ''
638+
if (environment.getErrors().length) {
639+
errorStatement = `
640+
641+
${chalk.red('There were errors encountered during this process:')}
642+
643+
${environment.getErrors().join('\n')}`
644+
}
645+
633646
if (!silent) {
634647
outro(`Created your new TanStack app in '${basename(targetDir)}'.
635648
636649
Use the following commands to start your app:
637650
% cd ${options.projectName}
638651
% ${options.packageManager === 'deno' ? 'deno start' : options.packageManager} ${isAddOnEnabled('start') ? 'dev' : 'start'}
639652
640-
Please read README.md for more information on testing, styling, adding routes, react-query, etc.
641-
`)
653+
Please read README.md for more information on testing, styling, adding routes, react-query, etc.${errorStatement}`)
642654
}
643655
}

src/environment.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { dirname } from 'node:path'
1010
import { execa } from 'execa'
1111

1212
export type Environment = {
13+
startRun: () => void
14+
finishRun: () => void
15+
getErrors: () => Array<string>
16+
1317
appendFile: (path: string, contents: string) => Promise<void>
1418
copyFile: (from: string, to: string) => Promise<void>
1519
writeFile: (path: string, contents: string) => Promise<void>
@@ -22,7 +26,14 @@ export type Environment = {
2226
}
2327

2428
export function createDefaultEnvironment(): Environment {
29+
let errors: Array<string> = []
2530
return {
31+
startRun: () => {
32+
errors = []
33+
},
34+
finishRun: () => {},
35+
getErrors: () => errors,
36+
2637
appendFile: async (path: string, contents: string) => {
2738
await mkdir(dirname(path), { recursive: true })
2839
return appendFile(path, contents)
@@ -36,9 +47,15 @@ export function createDefaultEnvironment(): Environment {
3647
return writeFile(path, contents)
3748
},
3849
execute: async (command: string, args: Array<string>, cwd: string) => {
39-
await execa(command, args, {
40-
cwd,
41-
})
50+
try {
51+
await execa(command, args, {
52+
cwd,
53+
})
54+
} catch {
55+
errors.push(
56+
`Command "${command} ${args.join(' ')}" did not run successfully. Please run this manually in your project.`,
57+
)
58+
}
4259
},
4360

4461
readFile: (path: string, encoding?: BufferEncoding) =>

0 commit comments

Comments
 (0)