fix: Fix directory validation logic and error message

pull/3640/head
Timothy Lau 2 years ago
parent b2dff54dc9
commit 8695c27315

@ -44,6 +44,7 @@ export async function init() {
root: () => root: () =>
text({ text({
message: 'Where should VitePress initialize the config?', message: 'Where should VitePress initialize the config?',
defaultValue: './',
initialValue: './', initialValue: './',
validate(value) { validate(value) {
const inputRoot = path.resolve(value) const inputRoot = path.resolve(value)
@ -51,7 +52,7 @@ export async function init() {
if (!inputRoot.startsWith(currentRoot)) { if (!inputRoot.startsWith(currentRoot)) {
return 'Please make sure directory is inside' return 'Please make sure directory is inside'
} }
if (fs.pathExistsSync(inputRoot)) { if (inputRoot != currentRoot && fs.pathExistsSync(inputRoot)) {
return `${value} already exists` return `${value} already exists`
} }
} }

Loading…
Cancel
Save