Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/cold-rings-show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@tanstack/cta-cli': minor
'create-start-app': minor
'create-tanstack': minor
'create-tanstack-app': minor
'create-tsrouter-app': minor
'@tanstack/create-start': minor
'@tanstack/cta-framework-react-cra': minor
'@tanstack/cta-framework-solid': minor
'@tanstack/cta-engine': minor
'@tanstack/cta-ui': minor
'@tanstack/cta-ui-base': minor
---

no will prompt about overriding a directory that has contents
5 changes: 5 additions & 0 deletions packages/cta-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ Remove your node_modules directory and package lock file and re-install.`,
'--add-on-config <config>',
'JSON string with add-on configuration options',
)
.option(
'-f, --force',
'force project creation even if the target directory is not empty',
false,
)

program.action(async (projectName: string, options: CliOptions) => {
if (options.listAddOns) {
Expand Down
23 changes: 21 additions & 2 deletions packages/cta-cli/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { intro } from '@clack/prompts'
import fs from 'node:fs'
import { cancel, confirm, intro, isCancel } from '@clack/prompts'

import {
finalizeAddOns,
Expand All @@ -12,8 +13,8 @@ import {
getProjectName,
promptForAddOnOptions,
selectAddOns,
selectGit,
selectDeployment,
selectGit,
selectPackageManager,
selectRouterType,
selectTailwind,
Expand Down Expand Up @@ -46,6 +47,7 @@ export async function promptForCreateOptions(

options.framework = getFrameworkById(cliOptions.framework || 'react-cra')!

// Validate project name
if (cliOptions.projectName) {
// Handle "." as project name - use sanitized current directory name
if (cliOptions.projectName === '.') {
Expand All @@ -62,6 +64,23 @@ export async function promptForCreateOptions(
options.projectName = await getProjectName()
}

// Check if target directory is empty
if (
!cliOptions.force &&
fs.existsSync(options.projectName) &&
fs.readdirSync(options.projectName).length > 0
) {
const shouldContinue = await confirm({
message: `Target directory ${options.projectName} is not empty. Do you want to continue?`,
initialValue: true,
})

if (isCancel(shouldContinue) || !shouldContinue) {
cancel('Operation cancelled.')
process.exit(0)
}
}

// Router type selection
if (forcedMode) {
options.mode = forcedMode
Expand Down
1 change: 1 addition & 0 deletions packages/cta-cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export interface CliOptions {
devWatch?: string
install?: boolean
addOnConfig?: string
force?: boolean
}
1 change: 0 additions & 1 deletion packages/cta-cli/src/ui-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { validateProjectName } from './utils.js'
import type { AddOn, PackageManager } from '@tanstack/cta-engine'

import type { Framework } from '@tanstack/cta-engine/dist/types/types.js'
import { InitialData } from '../../cta-ui/src/types'

export async function getProjectName(): Promise<string> {
const value = await text({
Expand Down