]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
fix: fix `--force` feature when targetDir doesn't exist yet
authorHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 19 Jan 2022 08:07:29 +0000 (16:07 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 19 Jan 2022 08:08:15 +0000 (16:08 +0800)
index.js

index 4097b021b3dc5789672b5d8eb949026fa9b40e01..e94d742cc3c13af9ccbd35243eb8663d297d04f5 100755 (executable)
--- a/index.js
+++ b/index.js
@@ -33,6 +33,10 @@ function canSafelyOverwrite(dir) {
 }
 
 function emptyDir(dir) {
+  if (!fs.existsSync(dir)) {
+    return
+  }
+
   postOrderDirectoryTraverse(
     dir,
     (dir) => fs.rmdirSync(dir),
@@ -237,7 +241,7 @@ async function init() {
   const needsCypressCT = needsCypress && !needsVitest
   const root = path.join(cwd, targetDir)
 
-  if (shouldOverwrite) {
+  if (fs.existsSync(root) && shouldOverwrite) {
     emptyDir(root)
   } else if (!fs.existsSync(root)) {
     fs.mkdirSync(root)