Skip to content

Commit ceb8b69

Browse files
committed
chore: better console output when building with UI
1 parent f85f6b6 commit ceb8b69

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

packages/cta-cli/src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { launchUI } from '@tanstack/cta-ui'
2222

2323
import { runMCPServer } from './mcp.js'
2424

25-
import { promptForCreateOptions, promptForAddOns } from './options.js'
25+
import { promptForAddOns, promptForCreateOptions } from './options.js'
2626
import { normalizeOptions } from './command-line.js'
2727

2828
import { createUIEnvironment } from './ui-environment.js'
@@ -112,6 +112,7 @@ export function cli({
112112
projectPath: process.cwd(),
113113
forcedRouterMode: forcedMode,
114114
forcedAddOns,
115+
environmentFactory: () => createUIEnvironment(appName, false),
115116
})
116117
} else if (parsedAddOns.length < 1) {
117118
const addOns = await promptForAddOns()
@@ -301,6 +302,7 @@ export function cli({
301302
},
302303
forcedRouterMode: forcedMode,
303304
forcedAddOns,
305+
environmentFactory: () => createUIEnvironment(appName, false),
304306
})
305307
return
306308
}

packages/cta-ui/lib/engine-handling/add-to-app-wrapper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function addToAppWrapper(
2424
opts: {
2525
dryRun?: boolean
2626
response?: Response
27+
environmentFactory?: () => Environment
2728
},
2829
) {
2930
const projectPath = getProjectPath()
@@ -66,7 +67,7 @@ export async function addToAppWrapper(
6667
return { environment, output }
6768
}
6869
return {
69-
environment: createDefaultEnvironment(),
70+
environment: opts.environmentFactory?.() ?? createDefaultEnvironment(),
7071
output: { files: {}, deletedFiles: [], commands: [] },
7172
}
7273
}

packages/cta-ui/lib/engine-handling/create-app-wrapper.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@ import { registerFrameworks } from './framework-registration.js'
1414
import { cleanUpFileArray, cleanUpFiles } from './file-helpers.js'
1515
import { getApplicationMode, getProjectPath } from './server-environment.js'
1616

17-
import type { Options, SerializedOptions, Starter } from '@tanstack/cta-engine'
17+
import type {
18+
Environment,
19+
Options,
20+
SerializedOptions,
21+
Starter,
22+
} from '@tanstack/cta-engine'
1823

1924
import type { Response } from 'express'
2025

2126
export async function createAppWrapper(
2227
projectOptions: SerializedOptions,
23-
opts: { dryRun?: boolean; response?: Response },
28+
opts: {
29+
dryRun?: boolean
30+
response?: Response
31+
environmentFactory?: () => Environment
32+
},
2433
) {
2534
registerFrameworks()
2635

2736
const framework = getFrameworkById(projectOptions.framework)!
2837

2938
let starter: Starter | undefined
30-
const addOns: Array<string> = [...(projectOptions.chosenAddOns || [])]
39+
const addOns: Array<string> = [...projectOptions.chosenAddOns]
3140
if (projectOptions.starter) {
3241
starter = await loadStarter(projectOptions.starter)
33-
for (const addOn of starter?.dependsOn ?? []) {
34-
addOns.push(addOn)
42+
if (starter) {
43+
for (const addOn of starter.dependsOn ?? []) {
44+
addOns.push(addOn)
45+
}
3546
}
3647
}
3748
const chosenAddOns = await finalizeAddOns(
@@ -59,7 +70,7 @@ export async function createAppWrapper(
5970
return createMemoryEnvironment(targetDir)
6071
}
6172
return {
62-
environment: createDefaultEnvironment(),
73+
environment: opts.environmentFactory?.() ?? createDefaultEnvironment(),
6374
output: { files: {}, deletedFiles: [], commands: [] },
6475
}
6576
}

packages/cta-ui/lib/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import { generateInitialPayload } from './engine-handling/generate-initial-paylo
1515
import { setServerEnvironment } from './engine-handling/server-environment.js'
1616

1717
import type { ServerEnvironment } from './engine-handling/server-environment.js'
18+
import type { Environment } from '@tanstack/cta-engine'
1819

1920
export function launchUI(
2021
options: Partial<ServerEnvironment> & {
2122
port?: number
23+
environmentFactory?: () => Environment
2224
},
2325
) {
2426
const { port: requestedPort, ...rest } = options
@@ -39,19 +41,22 @@ export function launchUI(
3941
app.post('/api/add-to-app', async (req, res) => {
4042
await addToAppWrapper(req.body.addOns, {
4143
response: res,
44+
environmentFactory: options.environmentFactory,
4245
})
4346
})
4447

4548
app.post('/api/create-app', async (req, res) => {
4649
await createAppWrapper(req.body.options, {
4750
response: res,
51+
environmentFactory: options.environmentFactory,
4852
})
4953
})
5054

5155
app.post('/api/dry-run-add-to-app', async (req, res) => {
5256
res.send(
5357
await addToAppWrapper(req.body.addOns, {
5458
dryRun: true,
59+
environmentFactory: options.environmentFactory,
5560
}),
5661
)
5762
})
@@ -60,6 +65,7 @@ export function launchUI(
6065
res.send(
6166
await createAppWrapper(req.body.options, {
6267
dryRun: true,
68+
environmentFactory: options.environmentFactory,
6369
}),
6470
)
6571
})

0 commit comments

Comments
 (0)