feat(storybook): update Angular Storybook to use new Storybook v6 syntax (#5398)

This commit is contained in:
Katerina Skroumpelou 2021-04-29 12:02:04 +03:00 committed by GitHub
parent 0ac5b27749
commit 6b7b6815c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 139 additions and 81 deletions

View File

@ -32,6 +32,8 @@ The Cypress project to generate the stories under. This is inferred from 'name'
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator

View File

@ -26,6 +26,8 @@ nx g storybook-configuration ... --dry-run
### configureCypress ### configureCypress
Default: `true`
Type: `boolean` Type: `boolean`
Run the cypress-configure generator Run the cypress-configure generator
@ -38,15 +40,19 @@ A directory where the Cypress project will be placed. Placed at the root by defa
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator
### generateStories ### generateStories
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.stories.ts files for components declared in this library/application? Automatically generate \*.stories.ts files for components declared in this project?
### linter ### linter
@ -62,4 +68,4 @@ The tool to use for running lint checks.
Type: `string` Type: `string`
Library or application name Project name

View File

@ -32,6 +32,8 @@ The Cypress project to generate the stories under. This is inferred from 'projec
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator. Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator.

View File

@ -26,6 +26,8 @@ nx g storybook-configuration ... --dry-run
### configureCypress ### configureCypress
Default: `true`
Type: `boolean` Type: `boolean`
Run the cypress-configure generator. Run the cypress-configure generator.
@ -38,15 +40,19 @@ A directory where the Cypress project will be placed. Placed at the root by defa
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator
### generateStories ### generateStories
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.stories.ts files for components declared in this library. Automatically generate \*.stories.ts files for components declared in this project?
### js ### js
@ -70,4 +76,4 @@ The tool to use for running lint checks.
Type: `string` Type: `string`
Library or application name Project name

View File

@ -32,6 +32,8 @@ The Cypress project to generate the stories under. This is inferred from 'name'
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator

View File

@ -26,6 +26,8 @@ nx g storybook-configuration ... --dry-run
### configureCypress ### configureCypress
Default: `true`
Type: `boolean` Type: `boolean`
Run the cypress-configure generator Run the cypress-configure generator
@ -38,15 +40,19 @@ A directory where the Cypress project will be placed. Placed at the root by defa
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator
### generateStories ### generateStories
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.stories.ts files for components declared in this library/application? Automatically generate \*.stories.ts files for components declared in this project?
### linter ### linter
@ -62,4 +68,4 @@ The tool to use for running lint checks.
Type: `string` Type: `string`
Library or application name Project name

View File

@ -32,6 +32,8 @@ The Cypress project to generate the stories under. This is inferred from 'projec
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator. Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator.

View File

@ -26,6 +26,8 @@ nx g storybook-configuration ... --dry-run
### configureCypress ### configureCypress
Default: `true`
Type: `boolean` Type: `boolean`
Run the cypress-configure generator. Run the cypress-configure generator.
@ -38,15 +40,19 @@ A directory where the Cypress project will be placed. Placed at the root by defa
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator
### generateStories ### generateStories
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.stories.ts files for components declared in this library. Automatically generate \*.stories.ts files for components declared in this project?
### js ### js
@ -70,4 +76,4 @@ The tool to use for running lint checks.
Type: `string` Type: `string`
Library or application name Project name

View File

@ -32,6 +32,8 @@ The Cypress project to generate the stories under. This is inferred from 'name'
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator

View File

@ -26,6 +26,8 @@ nx g storybook-configuration ... --dry-run
### configureCypress ### configureCypress
Default: `true`
Type: `boolean` Type: `boolean`
Run the cypress-configure generator Run the cypress-configure generator
@ -38,15 +40,19 @@ A directory where the Cypress project will be placed. Placed at the root by defa
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator
### generateStories ### generateStories
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.stories.ts files for components declared in this library/application? Automatically generate \*.stories.ts files for components declared in this project?
### linter ### linter
@ -62,4 +68,4 @@ The tool to use for running lint checks.
Type: `string` Type: `string`
Library or application name Project name

View File

@ -32,6 +32,8 @@ The Cypress project to generate the stories under. This is inferred from 'projec
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator. Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator.

View File

@ -26,6 +26,8 @@ nx g storybook-configuration ... --dry-run
### configureCypress ### configureCypress
Default: `true`
Type: `boolean` Type: `boolean`
Run the cypress-configure generator. Run the cypress-configure generator.
@ -38,15 +40,19 @@ A directory where the Cypress project will be placed. Placed at the root by defa
### generateCypressSpecs ### generateCypressSpecs
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator Automatically generate \*.spec.ts files in the cypress e2e app generated by the cypress-configure generator
### generateStories ### generateStories
Default: `true`
Type: `boolean` Type: `boolean`
Automatically generate \*.stories.ts files for components declared in this library. Automatically generate \*.stories.ts files for components declared in this project?
### js ### js
@ -70,4 +76,4 @@ The tool to use for running lint checks.
Type: `string` Type: `string`
Library or application name Project name

View File

@ -10,7 +10,7 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
import { mkdirSync, writeFileSync } from 'fs'; import { writeFileSync } from 'fs';
describe('Storybook schematics', () => { describe('Storybook schematics', () => {
let proj: string; let proj: string;
@ -60,15 +60,15 @@ describe('Storybook schematics', () => {
const myapp = uniq('myapp'); const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --no-interactive`); runCLI(`generate @nrwl/angular:app ${myapp} --no-interactive`);
const mylib = uniq('test-ui-lib'); const myAngularLib = uniq('test-ui-lib');
createTestUILib(mylib); createTestUILib(myAngularLib);
const mylib2 = uniq('test-ui-lib-react'); const myReactLib = uniq('test-ui-lib-react');
runCLI(`generate @nrwl/react:lib ${mylib2} --no-interactive`); runCLI(`generate @nrwl/react:lib ${myReactLib} --no-interactive`);
runCLI( runCLI(
`generate @nrwl/react:component Button --project=${mylib2} --no-interactive` `generate @nrwl/react:component Button --project=${myReactLib} --no-interactive`
); );
writeFileSync( writeFileSync(
tmpProjPath(`libs/${mylib2}/src/lib/button.tsx`), tmpProjPath(`libs/${myReactLib}/src/lib/button.tsx`),
` `
import React from 'react'; import React from 'react';
@ -95,7 +95,7 @@ describe('Storybook schematics', () => {
` `
); );
writeFileSync( writeFileSync(
tmpProjPath(`libs/${mylib2}/src/lib/button.stories.tsx`), tmpProjPath(`libs/${myReactLib}/src/lib/button.stories.tsx`),
` `
import React from 'react'; import React from 'react';
import { Button, ButtonStyle } from './button'; import { Button, ButtonStyle } from './button';
@ -117,18 +117,18 @@ describe('Storybook schematics', () => {
); );
runCLI( runCLI(
`generate @nrwl/angular:storybook-configuration ${mylib} --configureCypress --generateStories --generateCypressSpecs --no-interactive` `generate @nrwl/angular:storybook-configuration ${myAngularLib} --configureCypress --generateStories --generateCypressSpecs --no-interactive`
); );
runCLI( runCLI(
`generate @nrwl/angular:stories ${mylib} --generateCypressSpecs --no-interactive` `generate @nrwl/angular:stories ${myAngularLib} --generateCypressSpecs --no-interactive`
); );
writeFileSync( writeFileSync(
tmpProjPath( tmpProjPath(
`apps/${mylib}-e2e/src/integration/test-button/test-button.component.spec.ts` `apps/${myAngularLib}-e2e/src/integration/test-button/test-button.component.spec.ts`
), ),
` `
describe('test-ui-lib3726865', () => { describe('${myAngularLib}', () => {
it('should render the component', () => { it('should render the component', () => {
cy.visit('/iframe.html?id=testbuttoncomponent--primary&knob-buttonType=button&knob-style=default&knob-age&knob-isDisabled=false'); cy.visit('/iframe.html?id=testbuttoncomponent--primary&knob-buttonType=button&knob-style=default&knob-age&knob-isDisabled=false');
@ -148,12 +148,17 @@ describe('Storybook schematics', () => {
); );
runCLI( runCLI(
`generate @nrwl/react:storybook-configuration ${mylib2} --configureCypress --no-interactive` `generate @nrwl/react:storybook-configuration ${myReactLib} --configureCypress --no-interactive`
); );
mkdirSync(tmpProjPath(`apps/${mylib2}-e2e/src/integration`)); // The following line (mkdirSync...) is not needed,
// since the above schematic creates this directory.
// So, if we leave it there, there's an error saying the directory exists.
// I am not sure how it worked as it was :/
// mkdirSync(tmpProjPath(`apps/${myReactLib}-e2e/src/integration`));
writeFileSync( writeFileSync(
tmpProjPath(`apps/${mylib2}-e2e/src/integration/button.spec.ts`), tmpProjPath(`apps/${myReactLib}-e2e/src/integration/button.spec.ts`),
` `
describe('react-ui', () => { describe('react-ui', () => {
it('should render the component', () => { it('should render the component', () => {
@ -174,15 +179,15 @@ describe('Storybook schematics', () => {
); );
if (runCypressTests()) { if (runCypressTests()) {
expect(runCLI(`run ${mylib}-e2e:e2e --no-watch`)).toContain( expect(runCLI(`run ${myAngularLib}-e2e:e2e --no-watch`)).toContain(
'All specs passed!' 'All specs passed!'
); );
} }
runCLI(`run ${mylib}:build-storybook`); runCLI(`run ${myAngularLib}:build-storybook`);
checkFilesExist(`dist/storybook/${mylib}/index.html`); checkFilesExist(`dist/storybook/${myAngularLib}/index.html`);
expect(readFile(`dist/storybook/${mylib}/index.html`)).toContain( expect(readFile(`dist/storybook/${myAngularLib}/index.html`)).toContain(
`<title>Storybook</title>` `<title>Storybook</title>`
); );
}, 1000000); }, 1000000);
@ -234,6 +239,7 @@ describe('Storybook schematics', () => {
export default { export default {
title: 'My Test Cmp', title: 'My Test Cmp',
component: MyTestCmpComponent,
}; };
let x = 'hi'; let x = 'hi';
@ -242,7 +248,6 @@ describe('Storybook schematics', () => {
moduleMetadata: { moduleMetadata: {
imports: [], imports: [],
}, },
component: MyTestCmpComponent,
props: {}, props: {},
}); });
` `

View File

@ -29,7 +29,7 @@ export default function (schema: CreateComponentSpecFileSchema): Rule {
export interface CreateComponentSpecFileSchema { export interface CreateComponentSpecFileSchema {
projectName: string; projectName: string;
libPath: string; projectPath: string;
componentName: string; componentName: string;
componentPath: string; componentPath: string;
componentFileName: string; componentFileName: string;
@ -38,7 +38,7 @@ export interface CreateComponentSpecFileSchema {
export function createComponentSpecFile({ export function createComponentSpecFile({
projectName, projectName,
libPath, projectPath,
componentName, componentName,
componentPath, componentPath,
componentFileName, componentFileName,
@ -50,7 +50,7 @@ export function createComponentSpecFile({
getProjectConfig(tree, e2eProjectName).sourceRoot getProjectConfig(tree, e2eProjectName).sourceRoot
}/integration`; }/integration`;
const fullComponentPath = join( const fullComponentPath = join(
normalize(libPath), normalize(projectPath),
componentPath, componentPath,
`${componentFileName}.ts` `${componentFileName}.ts`
); );

View File

@ -5,12 +5,12 @@
"properties": { "properties": {
"projectName": { "projectName": {
"type": "string", "type": "string",
"description": "Name of the library from angular.json", "description": "Name of the project from angular.json",
"examples": ["ui-samples"] "examples": ["ui-samples"]
}, },
"libPath": { "projectPath": {
"type": "string", "type": "string",
"description": "Path to the library", "description": "Path to the project",
"examples": ["libs/ui-samples"] "examples": ["libs/ui-samples"]
}, },
"componentName": { "componentName": {
@ -20,7 +20,7 @@
}, },
"componentPath": { "componentPath": {
"type": "string", "type": "string",
"description": "Relative path to the component file from the library root", "description": "Relative path to the component file from the project root",
"examples": ["awesome"] "examples": ["awesome"]
}, },
"componentFileName": { "componentFileName": {
@ -35,7 +35,7 @@
}, },
"required": [ "required": [
"projectName", "projectName",
"libPath", "projectPath",
"componentName", "componentName",
"componentPath", "componentPath",
"componentFileName" "componentFileName"

View File

@ -18,7 +18,7 @@ import { join, normalize } from '@angular-devkit/core';
import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter';
export interface CreateComponentStoriesFileSchema { export interface CreateComponentStoriesFileSchema {
libPath: string; projectPath: string;
componentName: string; componentName: string;
componentPath: string; componentPath: string;
componentFileName: string; componentFileName: string;
@ -29,7 +29,7 @@ export default function (schema: CreateComponentStoriesFileSchema): Rule {
} }
export function createComponentStoriesFile({ export function createComponentStoriesFile({
libPath, projectPath,
componentName, componentName,
componentPath, componentPath,
componentFileName, componentFileName,
@ -37,7 +37,7 @@ export function createComponentStoriesFile({
return (tree: Tree, context: SchematicContext): Rule => { return (tree: Tree, context: SchematicContext): Rule => {
const props = getInputDescriptors( const props = getInputDescriptors(
tree, tree,
join(normalize(libPath), componentPath, `${componentFileName}.ts`) join(normalize(projectPath), componentPath, `${componentFileName}.ts`)
); );
return applyWithSkipExisting(url('./files'), [ return applyWithSkipExisting(url('./files'), [
template({ template({
@ -46,7 +46,7 @@ export function createComponentStoriesFile({
props, props,
tmpl: '', tmpl: '',
}), }),
move(`${libPath}/${componentPath}`), move(`${projectPath}/${componentPath}`),
]); ]);
}; };
} }

View File

@ -2,14 +2,14 @@
import { <%=componentName%> } from './<%=componentFileName%>'; import { <%=componentName%> } from './<%=componentFileName%>';
export default { export default {
title: '<%=componentName%>' title: '<%=componentName%>',
component: <%=componentName%>
} }
export const primary = () => ({ export const primary = () => ({
moduleMetadata: { moduleMetadata: {
imports: [] imports: []
}, },
component: <%=componentName%>,
props: {<% for (let prop of props) { %> props: {<% for (let prop of props) { %>
<%=prop.name%>: <%=prop.type%>('<%=prop.name%>', <%=prop.defaultValue%>),<% } %> <%=prop.name%>: <%=prop.type%>('<%=prop.name%>', <%=prop.defaultValue%>),<% } %>
} }

View File

@ -3,9 +3,9 @@
"id": "component-story", "id": "component-story",
"type": "object", "type": "object",
"properties": { "properties": {
"libPath": { "projectPath": {
"type": "string", "type": "string",
"description": "Path to the library", "description": "Path to the project",
"examples": ["libs/ui-samples"] "examples": ["libs/ui-samples"]
}, },
"moduleFileName": { "moduleFileName": {
@ -27,7 +27,7 @@
}, },
"componentPath": { "componentPath": {
"type": "string", "type": "string",
"description": "Relative path to the component file from the library root", "description": "Relative path to the component file from the project root",
"examples": ["awesome"] "examples": ["awesome"]
}, },
"componentFileName": { "componentFileName": {
@ -36,5 +36,10 @@
"examples": ["awesome.component"] "examples": ["awesome.component"]
} }
}, },
"required": ["libPath", "componentName", "componentPath", "componentFileName"] "required": [
"projectPath",
"componentName",
"componentPath",
"componentFileName"
]
} }

View File

@ -14,7 +14,8 @@
}, },
"generateCypressSpecs": { "generateCypressSpecs": {
"type": "boolean", "type": "boolean",
"description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator" "description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator",
"default": true
}, },
"cypressProject": { "cypressProject": {
"type": "string", "type": "string",

View File

@ -39,12 +39,12 @@ export function createAllStories(
cypressProject?: string cypressProject?: string
): Rule { ): Rule {
return (tree: Tree, context: SchematicContext) => { return (tree: Tree, context: SchematicContext) => {
context.logger.debug('adding .storybook folder to lib'); context.logger.debug('adding .storybook folder to project');
const libPath = projectRootPath(tree, projectName); const projectPath = projectRootPath(tree, projectName);
let moduleFilePaths = [] as string[]; let moduleFilePaths = [] as string[];
tree.getDir(libPath).visit((filePath) => { tree.getDir(projectPath).visit((filePath) => {
if (!filePath.endsWith('.module.ts')) { if (!filePath.endsWith('.module.ts')) {
return; return;
} }
@ -221,7 +221,7 @@ export function createAllStories(
.map((info) => .map((info) =>
chain([ chain([
schematic<CreateComponentStoriesFileSchema>('component-story', { schematic<CreateComponentStoriesFileSchema>('component-story', {
libPath: modulePath, projectPath: modulePath,
componentName: info.name, componentName: info.name,
componentPath: info.path, componentPath: info.path,
componentFileName: info.componentFileName, componentFileName: info.componentFileName,
@ -231,7 +231,7 @@ export function createAllStories(
'component-cypress-spec', 'component-cypress-spec',
{ {
projectName, projectName,
libPath: modulePath, projectPath: modulePath,
cypressProject, cypressProject,
componentName: info.name, componentName: info.name,
componentPath: info.path, componentPath: info.path,

View File

@ -5,7 +5,7 @@
"properties": { "properties": {
"name": { "name": {
"type": "string", "type": "string",
"description": "Library or application name", "description": "Project name",
"$default": { "$default": {
"$source": "argv", "$source": "argv",
"index": 0 "index": 0
@ -14,17 +14,20 @@
"configureCypress": { "configureCypress": {
"type": "boolean", "type": "boolean",
"description": "Run the cypress-configure generator", "description": "Run the cypress-configure generator",
"x-prompt": "Configure a cypress e2e app to run against the storybook instance?" "x-prompt": "Configure a cypress e2e app to run against the storybook instance?",
"default": true
}, },
"generateStories": { "generateStories": {
"type": "boolean", "type": "boolean",
"description": "Automatically generate *.stories.ts files for components declared in this library/application?", "description": "Automatically generate *.stories.ts files for components declared in this project?",
"x-prompt": "Automatically generate *.stories.ts files for components declared in this library/application?" "x-prompt": "Automatically generate *.stories.ts files for components declared in this project?",
"default": true
}, },
"generateCypressSpecs": { "generateCypressSpecs": {
"type": "boolean", "type": "boolean",
"description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator", "description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator",
"x-prompt": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator?" "x-prompt": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator?",
"default": true
}, },
"cypressDirectory": { "cypressDirectory": {
"type": "string", "type": "string",

View File

@ -16,7 +16,8 @@
"generateCypressSpecs": { "generateCypressSpecs": {
"type": "boolean", "type": "boolean",
"description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator.", "description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator.",
"x-prompt": "Do you want to generate Cypress specs as well?" "x-prompt": "Do you want to generate Cypress specs as well?",
"default": true
}, },
"cypressProject": { "cypressProject": {
"type": "string", "type": "string",

View File

@ -66,10 +66,10 @@ export async function createAllStories(
const project = projects.get(projectName); const project = projects.get(projectName);
const { sourceRoot, projectType } = project; const { sourceRoot, projectType } = project;
const libPath = projectRootPath(tree, sourceRoot, projectType); const projectPath = projectRootPath(tree, sourceRoot, projectType);
let componentPaths: string[] = []; let componentPaths: string[] = [];
visitNotIgnoredFiles(tree, libPath, (path) => { visitNotIgnoredFiles(tree, projectPath, (path) => {
if ( if (
(path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) || (path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
(path.endsWith('.js') && !path.endsWith('.spec.js')) || (path.endsWith('.js') && !path.endsWith('.spec.js')) ||

View File

@ -6,7 +6,7 @@
"properties": { "properties": {
"name": { "name": {
"type": "string", "type": "string",
"description": "Library or application name", "description": "Project name",
"$default": { "$default": {
"$source": "argv", "$source": "argv",
"index": 0 "index": 0
@ -15,17 +15,20 @@
"configureCypress": { "configureCypress": {
"type": "boolean", "type": "boolean",
"description": "Run the cypress-configure generator.", "description": "Run the cypress-configure generator.",
"x-prompt": "Configure a cypress e2e app to run against the storybook instance?" "x-prompt": "Configure a cypress e2e app to run against the storybook instance?",
"default": true
}, },
"generateStories": { "generateStories": {
"type": "boolean", "type": "boolean",
"description": "Automatically generate *.stories.ts files for components declared in this library.", "description": "Automatically generate *.stories.ts files for components declared in this project?",
"x-prompt": "Automatically generate story files for components declared in this library?" "x-prompt": "Automatically generate *.stories.ts files for components declared in this project?",
"default": true
}, },
"generateCypressSpecs": { "generateCypressSpecs": {
"type": "boolean", "type": "boolean",
"description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator", "description": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator",
"x-prompt": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator?" "x-prompt": "Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure generator?",
"default": true
}, },
"cypressDirectory": { "cypressDirectory": {
"type": "string", "type": "string",

View File

@ -42,12 +42,7 @@ export async function configurationGenerator(
}); });
tasks.push(initTask); tasks.push(initTask);
createRootStorybookDir( createRootStorybookDir(tree, schema.js, workspaceStorybookVersion);
tree,
schema.name,
schema.js,
workspaceStorybookVersion
);
createProjectStorybookDir( createProjectStorybookDir(
tree, tree,
schema.name, schema.name,
@ -90,18 +85,15 @@ function normalizeSchema(schema: StorybookConfigureSchema) {
function createRootStorybookDir( function createRootStorybookDir(
tree: Tree, tree: Tree,
projectName: string,
js: boolean, js: boolean,
workspaceStorybookVersion: string workspaceStorybookVersion: string
) { ) {
if (tree.exists('.storybook')) { if (tree.exists('.storybook')) {
return; return;
} }
const { projectType } = readProjectConfiguration(tree, projectName);
const projectDirectory = projectType === 'application' ? 'app' : 'lib';
logger.debug( logger.debug(
`adding .storybook folder to ${projectDirectory} -\n `adding .storybook folder to the root directory -
based on the Storybook version installed: ${workspaceStorybookVersion}, we'll bootstrap a scaffold for that particular version.` based on the Storybook version installed (v${workspaceStorybookVersion}), we'll bootstrap a scaffold for that particular version.`
); );
const templatePath = join( const templatePath = join(
__dirname, __dirname,

View File

@ -74,7 +74,7 @@ export function migrateDefaultsGenerator(
} }
export function migrateAllStorybookInstances(tree: Tree, keepOld: boolean) { export function migrateAllStorybookInstances(tree: Tree, keepOld: boolean) {
logger.debug('adding .storybook folder to lib'); logger.debug('adding .storybook folder to project');
const projects = getProjects(tree); const projects = getProjects(tree);
const projectsThatHaveStorybookConfiguration: { const projectsThatHaveStorybookConfiguration: {
name: string; name: string;