Skip to content

Commit

Permalink
Merge pull request #18866 from storybookjs/fix/no-init-on-repro
Browse files Browse the repository at this point in the history
CLI: add --no-init to repro-next command
  • Loading branch information
yannbf authored Aug 4, 2022
2 parents 85db984 + ac9606c commit 67102c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ program
.description('Create a reproduction from a set of possible templates')
.option('-o --output <outDir>', 'Define an output directory')
.option('-b --branch <branch>', 'Define the branch to degit from', 'next')
.option('--no-init', 'Whether to download a template without an initialized Storybook', false)
.action((filterValue, options) =>
reproNext({ filterValue, ...options }).catch((e) => {
logger.error(e);
Expand Down
17 changes: 14 additions & 3 deletions code/lib/cli/src/repro-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ interface ReproOptions {
filterValue?: string;
output?: string;
branch?: string;
init?: boolean;
}
type Choice = keyof typeof TEMPLATES;

const toChoices = (c: Choice): prompts.Choice => ({ title: TEMPLATES[c].name, value: c });

export const reproNext = async ({ output: outputDirectory, filterValue, branch }: ReproOptions) => {
export const reproNext = async ({
output: outputDirectory,
filterValue,
branch,
init,
}: ReproOptions) => {
const keys = Object.keys(TEMPLATES) as Choice[];
// get value from template and reduce through TEMPLATES to filter out the correct template
const choices = keys.reduce<Choice[]>((acc, group) => {
Expand Down Expand Up @@ -123,9 +129,10 @@ export const reproNext = async ({ output: outputDirectory, filterValue, branch }

logger.log('📦 Downloading repro template...');
try {
const templateType = init ? 'after-storybook' : 'before-storybook';
// Download the repro based on subfolder "after-storybook" and selected branch
await degit(
`storybookjs/repro-templates-temp/${selectedTemplate}/after-storybook#${branch}`,
`storybookjs/repro-templates-temp/${selectedTemplate}/${templateType}#${branch}`,
{
force: true,
}
Expand All @@ -135,13 +142,17 @@ export const reproNext = async ({ output: outputDirectory, filterValue, branch }
return;
}

const initMessage = init
? chalk.yellow(`yarn storybook`)
: `Recreate your setup, then ${chalk.yellow(`run npx storybook init`)}`;

logger.info(
boxen(
dedent`
🎉 Your Storybook reproduction project is ready to use! 🎉
${chalk.yellow(`cd ${selectedDirectory}`)}
${chalk.yellow(`yarn storybook`)}
${initMessage}
Once you've recreated the problem you're experiencing, please:
Expand Down

0 comments on commit 67102c8

Please sign in to comment.