Skip to content
Open
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
5 changes: 5 additions & 0 deletions packages/cta-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,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
18 changes: 17 additions & 1 deletion 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 Down Expand Up @@ -42,6 +43,21 @@ export async function promptForCreateOptions(
options.framework = getFrameworkById(cliOptions.framework || 'react-cra')!

options.projectName = cliOptions.projectName || (await getProjectName())
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) {
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 @@ -21,4 +21,5 @@ export interface CliOptions {
interactive?: boolean
ui?: 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 @@ -16,7 +16,6 @@ import {
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'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not part of the main change, but I removed an unused import.


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