From: Haoqun Jiang Date: Wed, 19 Jan 2022 08:07:29 +0000 (+0800) Subject: fix: fix `--force` feature when targetDir doesn't exist yet X-Git-Tag: v3.1.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bee76a06b626e1780772d689b4840af1920fb3a1;p=thirdparty%2Fvuejs%2Fcreate-vue.git fix: fix `--force` feature when targetDir doesn't exist yet --- diff --git a/index.js b/index.js index 4097b021..e94d742c 100755 --- 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)