Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): allow initializing non-empty directory #15272

Merged
merged 3 commits into from
Dec 12, 2023
Merged
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
25 changes: 20 additions & 5 deletions packages/create-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,32 @@ async function init() {
},
{
type: () =>
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'select',
name: 'overwrite',
message: () =>
(targetDir === '.'
? 'Current directory'
: `Target directory "${targetDir}"`) +
` is not empty. Remove existing files and continue?`,
` is not empty. Please choose how to proceed:`,
initial: 0,
choices: [
{
title: 'Remove existing files and continue',
value: 'yes',
},
{
title: 'Cancel operation',
value: 'no',
},
{
title: 'Ignore files and continue',
value: 'ignore',
},
],
},
{
type: (_, { overwrite }: { overwrite?: boolean }) => {
if (overwrite === false) {
type: (_, { overwrite }: { overwrite?: string }) => {
if (overwrite === 'no') {
throw new Error(red('✖') + ' Operation cancelled')
}
return null
Expand Down Expand Up @@ -342,7 +357,7 @@ async function init() {

const root = path.join(cwd, targetDir)

if (overwrite) {
if (overwrite === 'yes') {
emptyDir(root)
} else if (!fs.existsSync(root)) {
fs.mkdirSync(root, { recursive: true })
Expand Down