Skip to content

Commit

Permalink
Use repro-next in the example script!
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Aug 2, 2022
1 parent 4628a28 commit 0596fdc
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions scripts/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
});
Expand All @@ -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,
Expand Down

0 comments on commit 0596fdc

Please sign in to comment.