From f72a4dbab8daba113303da3cbd4aebba22597663 Mon Sep 17 00:00:00 2001 From: Shaun Lloyd Date: Thu, 31 Aug 2023 11:47:56 -0400 Subject: [PATCH] Catch "no git" error --- src/@storybook/addon-styling-webpack/index.ts | 13 +++++++---- src/@storybook/addon-themes/index.ts | 13 +++++++---- src/utils/prompts.utils.ts | 22 +++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/@storybook/addon-styling-webpack/index.ts b/src/@storybook/addon-styling-webpack/index.ts index dc9951d..815a95c 100644 --- a/src/@storybook/addon-styling-webpack/index.ts +++ b/src/@storybook/addon-styling-webpack/index.ts @@ -23,10 +23,15 @@ export interface Options {} const autoConfigure = async ({}: Options = {}) => { printWelcome('@storybook/addon-styling-webpack'); - const isGitDirty = (await isGitClean()) === false; - - if (isGitDirty) { - const shouldQuit = await commonQuestions.shouldQuitWithDirtyGit(); + try { + const isGitDirty = (await isGitClean()) === false; + + if (isGitDirty) { + const shouldQuit = await commonQuestions.shouldQuitWithDirtyGit(); + if (shouldQuit) return; + } + } catch (e) { + const shouldQuit = await commonQuestions.shouldQuitWithoutGit(); if (shouldQuit) return; } diff --git a/src/@storybook/addon-themes/index.ts b/src/@storybook/addon-themes/index.ts index c1a78bb..2993ce2 100644 --- a/src/@storybook/addon-themes/index.ts +++ b/src/@storybook/addon-themes/index.ts @@ -23,10 +23,15 @@ export interface Options {} const autoConfigure = async ({}: Options = {}) => { printWelcome('@storybook/addon-themes'); - const isGitDirty = (await isGitClean()) === false; - - if (isGitDirty) { - const shouldQuit = await commonQuestions.shouldQuitWithDirtyGit(); + try { + const isGitDirty = (await isGitClean()) === false; + + if (isGitDirty) { + const shouldQuit = await commonQuestions.shouldQuitWithDirtyGit(); + if (shouldQuit) return; + } + } catch (e) { + const shouldQuit = await commonQuestions.shouldQuitWithoutGit(); if (shouldQuit) return; } diff --git a/src/utils/prompts.utils.ts b/src/utils/prompts.utils.ts index 8f3bfe5..16fa3eb 100644 --- a/src/utils/prompts.utils.ts +++ b/src/utils/prompts.utils.ts @@ -25,6 +25,28 @@ const shouldQuitWithDirtyGit = async (): Promise => { return shouldQuit; }; +const shouldQuitWithoutGit = async (): Promise => { + printWarning( + '💬 Before we continue', + dedent`I was unable to detect a git repository in your project. + + I recommend that you initialize one and make an initial commit before running this command.`, + ); + + const { shouldQuit } = await prompts( + { + type: 'confirm', + name: 'shouldQuit', + message: 'Do you want to quit?', + initial: true, + }, + { onCancel: () => process.exit(0) }, + ); + + return shouldQuit; +}; + export const commonQuestions = { shouldQuitWithDirtyGit, + shouldQuitWithoutGit, };