diff --git a/src/node/init/init.ts b/src/node/init/init.ts index a1ec8b5ca81c..2f38bc44c952 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -43,9 +43,17 @@ export async function init(root: string | undefined) { return text({ message: 'Where should VitePress initialize the config?', + defaultValue: './', initialValue: './', validate(value) { - // TODO make sure directory is inside + const inputRoot = path.resolve(value) + const currentRoot = path.resolve() + if (!inputRoot.startsWith(currentRoot)) { + return 'Please make sure directory is inside' + } + if (inputRoot != currentRoot && fs.pathExistsSync(inputRoot)) { + return `${value} already exists` + } } }) },