From b2dff54dc97e3d4857423f037ba755285aeeca04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E5=B0=8F=E6=98=93?= <237972113@qq.com> Date: Thu, 7 Mar 2024 19:21:57 +0800 Subject: [PATCH] feat(build): add validation when initializing VitePress configuration --- src/node/init/init.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node/init/init.ts b/src/node/init/init.ts index 774e528b..d8d1dd61 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -46,7 +46,14 @@ export async function init() { message: 'Where should VitePress initialize the config?', 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 (fs.pathExistsSync(inputRoot)) { + return `${value} already exists` + } } }),