From 0596fdce57ad3b8038214782ded4f30a4efceaf5 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Tue, 2 Aug 2022 10:05:22 +1000 Subject: [PATCH] Use `repro-next` in the example script! --- scripts/example.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/example.ts b/scripts/example.ts index 27f83b1d751b..43536cd6fe02 100644 --- a/scripts/example.ts +++ b/scripts/example.ts @@ -9,17 +9,19 @@ import type { Parameters } from '../code/lib/cli/src/repro-generators/configs'; import { getInterpretedFile } from '../code/lib/core-common'; import { readConfig, writeConfig } from '../code/lib/csf-tools'; import { babelParse } from '../code/lib/csf-tools/src/babelParse'; +import TEMPLATES from '../code/lib/cli/src/repro-templates'; -const frameworks = ['react', 'angular']; +type Template = keyof typeof TEMPLATES; +const templates: Template[] = Object.keys(TEMPLATES) as any; const addons = ['a11y', 'storysource']; const examplesDir = path.resolve(__dirname, '../examples'); const codeDir = path.resolve(__dirname, '../code'); async function getOptions() { return getOptionsOrPrompt('yarn example', { - framework: { - description: 'Which framework would you like to use?', - values: frameworks, + template: { + description: 'Which template would you like to use?', + values: templates, required: true as const, }, addon: { @@ -64,13 +66,15 @@ async function getOptions() { const steps = { repro: { - command: 'repro', + command: 'repro-next', description: 'Bootstrapping example', icon: '👷', hasArgument: true, options: { - template: { values: frameworks }, - e2e: {}, + // TODO allow string valued options without fixed values + output: { values: [] as string[] }, + // TODO allow default values for strings + branch: { values: ['next'] }, }, }, add: { @@ -144,8 +148,8 @@ const addPackageScripts = async ({ async function main() { const optionValues = await getOptions(); - const { framework, forceDelete, forceReuse, link, dryRun } = optionValues; - const cwd = path.join(examplesDir, framework as string); + const { template, forceDelete, forceReuse, link, dryRun } = optionValues; + const cwd = path.join(examplesDir, template.replace('/', '-')); const exists = await pathExists(cwd); let shouldDelete = exists && !forceReuse; @@ -165,8 +169,8 @@ async function main() { if (!exists || shouldDelete) { await executeCLIStep(steps.repro, { - argument: cwd, - optionValues: { template: framework }, + argument: template, + optionValues: { output: cwd, branch: 'next' }, cwd: examplesDir, dryRun, }); @@ -186,6 +190,10 @@ async function main() { // TODO copy stories if (link) { + await exec('yarn set version berry', { cwd }, { dryRun }); + await exec('yarn config set enableGlobalCache true', { cwd }, { dryRun }); + await exec('yarn config set nodeLinker node-modules', { cwd }, { dryRun }); + await executeCLIStep(steps.link, { argument: cwd, cwd: codeDir,