diff --git a/src/node/init/init.ts b/src/node/init/init.ts index 5b62eeafa0d1..cd8bea82e06c 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -41,9 +41,17 @@ export async function init() { root: () => 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` + } } }),