Skip to content

Commit 00669e1

Browse files
authored
feat(cli): allow initializing non-empty directory (vitejs#15272)
1 parent ea6a7a6 commit 00669e1

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/create-vite/src/index.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,32 @@ async function init() {
267267
},
268268
{
269269
type: () =>
270-
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
270+
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'select',
271271
name: 'overwrite',
272272
message: () =>
273273
(targetDir === '.'
274274
? 'Current directory'
275275
: `Target directory "${targetDir}"`) +
276-
` is not empty. Remove existing files and continue?`,
276+
` is not empty. Please choose how to proceed:`,
277+
initial: 0,
278+
choices: [
279+
{
280+
title: 'Remove existing files and continue',
281+
value: 'yes',
282+
},
283+
{
284+
title: 'Cancel operation',
285+
value: 'no',
286+
},
287+
{
288+
title: 'Ignore files and continue',
289+
value: 'ignore',
290+
},
291+
],
277292
},
278293
{
279-
type: (_, { overwrite }: { overwrite?: boolean }) => {
280-
if (overwrite === false) {
294+
type: (_, { overwrite }: { overwrite?: string }) => {
295+
if (overwrite === 'no') {
281296
throw new Error(red('✖') + ' Operation cancelled')
282297
}
283298
return null
@@ -342,7 +357,7 @@ async function init() {
342357

343358
const root = path.join(cwd, targetDir)
344359

345-
if (overwrite) {
360+
if (overwrite === 'yes') {
346361
emptyDir(root)
347362
} else if (!fs.existsSync(root)) {
348363
fs.mkdirSync(root, { recursive: true })

0 commit comments

Comments
 (0)