Skip to content

Commit

Permalink
Catch "no git" error
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Lloyd committed Aug 31, 2023
1 parent 17ffdcd commit f72a4db
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/@storybook/addon-styling-webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 9 additions & 4 deletions src/@storybook/addon-themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions src/utils/prompts.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ const shouldQuitWithDirtyGit = async (): Promise<boolean> => {
return shouldQuit;
};

const shouldQuitWithoutGit = async (): Promise<boolean> => {
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,
};

0 comments on commit f72a4db

Please sign in to comment.