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

CLI: add --no-init to repro-next command #18866

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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