Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(init): add validation when initializing VitePress configuration #3640

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
10 changes: 9 additions & 1 deletion src/node/init/init.ts
Expand Up @@ -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`
}
}
}),

Expand Down