From 66303b11821820c997f6e8389f98ba1813407431 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 14 May 2024 01:04:36 +0530 Subject: [PATCH] feat(cli/init): allow passing target dir as command argument --- src/node/cli.ts | 2 +- src/node/init/init.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index 7c452138..4c72a27c 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -54,7 +54,7 @@ if (!command || command === 'dev') { }) } else if (command === 'init') { createLogger().info('', { clear: true }) - init() + init(argv.root) } else { logVersion() if (command === 'build') { diff --git a/src/node/init/init.ts b/src/node/init/init.ts index 5b62eeaf..a1ec8b5c 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -33,19 +33,22 @@ const getPackageManger = () => { return name.split('/')[0] } -export async function init() { +export async function init(root: string | undefined) { intro(bold(cyan('Welcome to VitePress!'))) const options: ScaffoldOptions = await group( { - root: () => - text({ + root: async () => { + if (root) return root + + return text({ message: 'Where should VitePress initialize the config?', initialValue: './', validate(value) { // TODO make sure directory is inside } - }), + }) + }, title: () => text({