Skip to content

Commit

Permalink
Changes from #18695
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegach committed Aug 19, 2022
1 parent 65e222d commit 79ab632
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
26 changes: 20 additions & 6 deletions code/lib/cli/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const getFrameworkDetails = (
builder?: string;
framework?: string;
renderer?: string;
rendererId: SupportedRenderers;
} => {
const frameworkPackage = `@storybook/${renderer}-${builder}`;
const frameworkPackagePath = pnp ? wrapForPnp(frameworkPackage) : frameworkPackage;
Expand All @@ -68,6 +69,16 @@ const getFrameworkDetails = (
return {
packages: [rendererPackage],
framework: rendererPackagePath,
rendererId: 'angular',
type: 'framework',
};
}

if (renderer === 'cra') {
return {
packages: [rendererPackage],
framework: rendererPackagePath,
rendererId: 'react',
type: 'framework',
};
}
Expand All @@ -76,6 +87,7 @@ const getFrameworkDetails = (
return {
packages: [frameworkPackage],
framework: frameworkPackagePath,
rendererId: renderer,
type: 'framework',
};
}
Expand All @@ -85,6 +97,7 @@ const getFrameworkDetails = (
packages: [rendererPackage, builderPackage],
builder: builderPackagePath,
renderer: rendererPackagePath,
rendererId: renderer,
type: 'renderer',
};
}
Expand All @@ -97,13 +110,13 @@ const getFrameworkDetails = (
const stripVersions = (addons: string[]) => addons.map((addon) => getPackageDetails(addon)[0]);

const hasInteractiveStories = (framework: SupportedRenderers) =>
['react', 'angular', 'preact', 'svelte', 'vue', 'vue3', 'html'].includes(framework);
['cra', 'react', 'angular', 'preact', 'svelte', 'vue', 'vue3', 'html'].includes(framework);

export async function baseGenerator(
packageManager: JsPackageManager,
npmOptions: NpmOptions,
{ language, builder = CoreBuilder.Webpack5, pnp, commonJs }: GeneratorOptions,
renderer: SupportedRenderers,
input: SupportedRenderers,
options: FrameworkOptions = defaultOptions
) {
const {
Expand Down Expand Up @@ -134,7 +147,7 @@ export async function baseGenerator(
...extraAddonPackages,
];

if (hasInteractiveStories(renderer)) {
if (hasInteractiveStories(input)) {
addons.push('@storybook/addon-interactions');
addonPackages.push('@storybook/addon-interactions', '@storybook/testing-library');
}
Expand All @@ -151,11 +164,12 @@ export async function baseGenerator(
const {
packages: frameworkPackages,
type,
rendererId,
// @ts-ignore
renderer: rendererInclude, // deepscan-disable-line UNUSED_DECL
framework: frameworkInclude,
builder: builderInclude,
} = getFrameworkDetails(renderer, builder, pnp);
} = getFrameworkDetails(input, builder, pnp);

// TODO: We need to start supporting this at some point
if (type === 'renderer') {
Expand Down Expand Up @@ -199,10 +213,10 @@ export async function baseGenerator(
: {}),
});

await configurePreview(renderer, options.commonJs);
await configurePreview(input, options.commonJs);

if (addComponents) {
copyComponents(renderer, language);
copyComponents(rendererId, language);
}

// FIXME: temporary workaround for https://github.com/storybookjs/storybook/issues/17516
Expand Down
7 changes: 5 additions & 2 deletions code/lib/cli/src/project_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function eqMajor(versionRange: string, major: number) {
// Should match @storybook/<renderer>
export type SupportedRenderers =
| 'react'
| 'cra'
| 'react-native'
| 'vue'
| 'vue3'
Expand All @@ -32,6 +33,7 @@ export type SupportedRenderers =

export const SUPPORTED_RENDERERS: SupportedRenderers[] = [
'react',
'cra',
'react-native',
'vue',
'vue3',
Expand All @@ -50,7 +52,8 @@ export const SUPPORTED_RENDERERS: SupportedRenderers[] = [
export enum ProjectType {
UNDETECTED = 'UNDETECTED',
UNSUPPORTED = 'UNSUPPORTED',
REACT_SCRIPTS = 'REACT_SCRIPTS',
CRA = 'CRA',
REACT_SCRIPTS = 'CRA',
REACT = 'REACT',
REACT_NATIVE = 'REACT_NATIVE',
REACT_PROJECT = 'REACT_PROJECT',
Expand Down Expand Up @@ -163,7 +166,7 @@ export const supportedTemplates: TemplateConfiguration[] = [
},
},
{
preset: ProjectType.REACT_SCRIPTS,
preset: ProjectType.CRA,
// For projects using a custom/forked `react-scripts` package.
files: ['/node_modules/.bin/react-scripts'],
// For standard CRA projects
Expand Down

0 comments on commit 79ab632

Please sign in to comment.