From 6a63138b08ed6ab5689f95bcffb953340fed82eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Tue, 5 Jul 2022 09:11:44 +0100 Subject: [PATCH] fix(angular): generate stories for secondary entrypoints (#11005) --- docs/generated/packages/angular.json | 4 + .../component-cypress-spec.ts | 3 +- .../component-cypress-spec/schema.d.ts | 1 + .../component-cypress-spec/schema.json | 4 + .../__snapshots__/stories-lib.spec.ts.snap | 26 +++- .../generators/stories/lib/component-info.ts | 64 ++++++++-- .../src/generators/stories/lib/entry-point.ts | 117 ++++++++++++++++++ .../src/generators/stories/lib/module-info.ts | 33 ++++- .../generators/stories/stories-lib.spec.ts | 49 +++++++- .../angular/src/generators/stories/stories.ts | 22 ++-- .../storybook-configuration.spec.ts.snap | 46 +++++++ .../storybook-configuration.spec.ts | 60 ++++++++- 12 files changed, 401 insertions(+), 28 deletions(-) create mode 100644 packages/angular/src/generators/stories/lib/entry-point.ts diff --git a/docs/generated/packages/angular.json b/docs/generated/packages/angular.json index 8c78133c60..7b7c7b7480 100644 --- a/docs/generated/packages/angular.json +++ b/docs/generated/packages/angular.json @@ -412,6 +412,10 @@ "type": "string", "description": "The Cypress project to generate the stories under. By default, inferred from `projectName`." }, + "specDirectory": { + "type": "string", + "description": "Directory where to place the generated spec file. By default matches the value of the `componentPath` option." + }, "skipFormat": { "description": "Skip formatting files.", "type": "boolean", diff --git a/packages/angular/src/generators/component-cypress-spec/component-cypress-spec.ts b/packages/angular/src/generators/component-cypress-spec/component-cypress-spec.ts index 7c37876141..d542e69c23 100644 --- a/packages/angular/src/generators/component-cypress-spec/component-cypress-spec.ts +++ b/packages/angular/src/generators/component-cypress-spec/component-cypress-spec.ts @@ -21,6 +21,7 @@ export function componentCypressSpecGenerator( componentPath, componentFileName, componentName, + specDirectory, } = options; const e2eProjectName = cypressProject || `${projectName}-e2e`; const e2eProjectRoot = readProjectConfiguration( @@ -35,7 +36,7 @@ export function componentCypressSpecGenerator( const templatesDir = joinPathFragments(__dirname, 'files'); const destinationDir = joinPathFragments( e2eLibIntegrationFolderPath, - componentPath + specDirectory ?? componentPath ); const storyFile = joinPathFragments( destinationDir, diff --git a/packages/angular/src/generators/component-cypress-spec/schema.d.ts b/packages/angular/src/generators/component-cypress-spec/schema.d.ts index 0ca850e13f..6f86faee5f 100644 --- a/packages/angular/src/generators/component-cypress-spec/schema.d.ts +++ b/packages/angular/src/generators/component-cypress-spec/schema.d.ts @@ -5,5 +5,6 @@ export interface ComponentCypressSpecGeneratorOptions { componentPath: string; componentFileName: string; cypressProject?: string; + specDirectory?: string; skipFormat?: boolean; } diff --git a/packages/angular/src/generators/component-cypress-spec/schema.json b/packages/angular/src/generators/component-cypress-spec/schema.json index 4fab80e646..494fe50c34 100644 --- a/packages/angular/src/generators/component-cypress-spec/schema.json +++ b/packages/angular/src/generators/component-cypress-spec/schema.json @@ -34,6 +34,10 @@ "type": "string", "description": "The Cypress project to generate the stories under. By default, inferred from `projectName`." }, + "specDirectory": { + "type": "string", + "description": "Directory where to place the generated spec file. By default matches the value of the `componentPath` option." + }, "skipFormat": { "description": "Skip formatting files.", "type": "boolean", diff --git a/packages/angular/src/generators/stories/__snapshots__/stories-lib.spec.ts.snap b/packages/angular/src/generators/stories/__snapshots__/stories-lib.spec.ts.snap index 1f88bb8fae..737b257736 100644 --- a/packages/angular/src/generators/stories/__snapshots__/stories-lib.spec.ts.snap +++ b/packages/angular/src/generators/stories/__snapshots__/stories-lib.spec.ts.snap @@ -9,7 +9,7 @@ exports[`angularStories generator: libraries Stories for non-empty Angular libra });" `; -exports[`angularStories generator: libraries Stories for non-empty Angular library should generate stories file for standalone component 1`] = ` +exports[`angularStories generator: libraries Stories for non-empty Angular library should generate stories file for standalone components 1`] = ` "import { moduleMetadata, Story, Meta } from '@storybook/angular'; import { StandaloneComponent } from './standalone.component'; @@ -28,6 +28,30 @@ const Template: Story = (args: StandaloneComponent) => ({ }); +export const Primary = Template.bind({}); +Primary.args = { +}" +`; + +exports[`angularStories generator: libraries Stories for non-empty Angular library should generate stories file for standalone components 2`] = ` +"import { moduleMetadata, Story, Meta } from '@storybook/angular'; +import { SecondaryStandaloneComponent } from './secondary-standalone.component'; + +export default { + title: 'SecondaryStandaloneComponent', + component: SecondaryStandaloneComponent, + decorators: [ + moduleMetadata({ + imports: [], + }) + ], +} as Meta; + +const Template: Story = (args: SecondaryStandaloneComponent) => ({ + props: args, +}); + + export const Primary = Template.bind({}); Primary.args = { }" diff --git a/packages/angular/src/generators/stories/lib/component-info.ts b/packages/angular/src/generators/stories/lib/component-info.ts index 66f31ca1bf..085c6ea84b 100644 --- a/packages/angular/src/generators/stories/lib/component-info.ts +++ b/packages/angular/src/generators/stories/lib/component-info.ts @@ -1,6 +1,7 @@ import { joinPathFragments, logger, + normalizePath, Tree, visitNotIgnoredFiles, } from '@nrwl/devkit'; @@ -9,6 +10,7 @@ import { basename, dirname, extname, relative } from 'path'; import type { Identifier, SourceFile, Statement } from 'typescript'; import { SyntaxKind } from 'typescript'; import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils'; +import type { EntryPoint } from './entry-point'; import { getModuleDeclaredComponents } from './module-info'; import { getAllFilesRecursivelyFromDir } from './tree-utilities'; @@ -17,10 +19,12 @@ export interface ComponentInfo { moduleFolderPath: string; name: string; path: string; + entryPointName: string; } export function getComponentsInfo( tree: Tree, + entryPoint: EntryPoint, moduleFilePaths: string[], projectName: string ): ComponentInfo[] { @@ -40,7 +44,14 @@ export function getComponentsInfo( ); const componentsInfo = declaredComponents.map((componentName) => - getComponentInfo(tree, file, imports, moduleFilePath, componentName) + getComponentInfo( + tree, + entryPoint, + file, + imports, + moduleFilePath, + componentName + ) ); return componentsInfo; @@ -49,26 +60,43 @@ export function getComponentsInfo( export function getStandaloneComponentsInfo( tree: Tree, - projectPath: string + entryPoint: EntryPoint ): ComponentInfo[] { const componentsInfo: ComponentInfo[] = []; - visitNotIgnoredFiles(tree, projectPath, (filePath: string) => { - if (extname(filePath) !== '.ts') { + visitNotIgnoredFiles(tree, entryPoint.path, (filePath: string) => { + const normalizedFilePath = normalizePath(filePath); + + if ( + entryPoint.excludeDirs?.some((excludeDir) => + normalizedFilePath.startsWith(excludeDir) + ) + ) { return; } - const standaloneComponents = getStandaloneComponents(tree, filePath); + if ( + extname(normalizedFilePath) !== '.ts' || + normalizedFilePath.includes('.storybook') + ) { + return; + } + + const standaloneComponents = getStandaloneComponents( + tree, + normalizedFilePath + ); if (!standaloneComponents.length) { return; } standaloneComponents.forEach((componentName) => { componentsInfo.push({ - componentFileName: basename(filePath, '.ts'), - moduleFolderPath: projectPath, + componentFileName: basename(normalizedFilePath, '.ts'), + moduleFolderPath: entryPoint.path, name: componentName, - path: dirname(relative(projectPath, filePath)), + path: dirname(relative(entryPoint.path, normalizedFilePath)), + entryPointName: entryPoint.name, }); }); }); @@ -122,6 +150,7 @@ function getComponentImportPath( function getComponentInfo( tree: Tree, + entryPoint: EntryPoint, sourceFile: SourceFile, imports: Statement[], moduleFilePath: string, @@ -143,6 +172,7 @@ function getComponentInfo( moduleFolderPath, name: componentName, path: '.', + entryPointName: entryPoint.name, }; } @@ -159,6 +189,7 @@ function getComponentInfo( if (tree.exists(componentImportPath) && !tree.isFile(componentImportPath)) { return getComponentInfoFromDir( tree, + entryPoint, componentImportPath, componentName, moduleFolderPath @@ -168,7 +199,13 @@ function getComponentInfo( const path = dirname(componentFilePathRelativeToModule); const componentFileName = basename(componentFilePathRelativeToModule); - return { componentFileName, moduleFolderPath, name: componentName, path }; + return { + componentFileName, + moduleFolderPath, + name: componentName, + path, + entryPointName: entryPoint.name, + }; } catch (ex) { logger.warn( `Could not generate a story for ${componentName}. Error: ${ex}` @@ -179,6 +216,7 @@ function getComponentInfo( function getComponentInfoFromDir( tree: Tree, + entryPoint: EntryPoint, dir: string, componentName: string, moduleFolderPath: string @@ -212,7 +250,13 @@ function getComponentInfoFromDir( ); } - return { componentFileName, moduleFolderPath, name: componentName, path }; + return { + componentFileName, + moduleFolderPath, + name: componentName, + path, + entryPointName: entryPoint.name, + }; } function getFullComponentFilePath( diff --git a/packages/angular/src/generators/stories/lib/entry-point.ts b/packages/angular/src/generators/stories/lib/entry-point.ts new file mode 100644 index 0000000000..a4c60b3881 --- /dev/null +++ b/packages/angular/src/generators/stories/lib/entry-point.ts @@ -0,0 +1,117 @@ +import type { ProjectType, Tree } from '@nrwl/devkit'; +import { + joinPathFragments, + normalizePath, + readJson, + readProjectConfiguration, + visitNotIgnoredFiles, +} from '@nrwl/devkit'; +import { basename, dirname } from 'path'; + +export type EntryPoint = { name: string; path: string; excludeDirs?: string[] }; + +export function getProjectEntryPoints( + tree: Tree, + projectName: string +): EntryPoint[] { + const { root, sourceRoot, projectType } = readProjectConfiguration( + tree, + projectName + ); + + const rootEntryPoint: EntryPoint = { + name: '', + path: normalizeMainEntryPointSourceRoot( + tree, + root, + sourceRoot, + projectType + ), + }; + const entryPointRootPaths = [rootEntryPoint]; + + if (projectType === 'application') { + return entryPointRootPaths; + } + + collectLibrarySecondaryEntryPoints(tree, root, entryPointRootPaths); + + // since the root includes some secondary entry points, we need to ignore + // them when processing the main entry point + if (rootEntryPoint.path === root && entryPointRootPaths.length > 1) { + rootEntryPoint.excludeDirs = entryPointRootPaths + .slice(1) + .map((entryPoint) => entryPoint.path); + } + + return entryPointRootPaths; +} + +function collectLibrarySecondaryEntryPoints( + tree: Tree, + root: string, + entryPointPaths: EntryPoint[] +): void { + const exclude = new Set([`${root}/ng-package.json`, `${root}/package.json`]); + + visitNotIgnoredFiles(tree, root, (path) => { + const normalizedPath = normalizePath(path); + + if (!tree.isFile(normalizedPath) || exclude.has(normalizedPath)) { + return; + } + + const fileName = basename(normalizedPath); + if ( + fileName !== 'ng-package.json' && + (fileName !== 'package.json' || + (fileName === 'package.json' && + !readJson(tree, normalizedPath).ngPackage)) + ) { + return; + } + + const entryPointPath = getSourcePath( + tree, + normalizePath(dirname(normalizedPath)), + 'lib' + ); + + entryPointPaths.push({ + name: basename(dirname(normalizedPath)), + path: entryPointPath, + }); + }); +} + +function normalizeMainEntryPointSourceRoot( + tree: Tree, + root: string, + sourceRoot: string, + projectType: ProjectType +): string { + const projectTypeDir = projectType === 'application' ? 'app' : 'lib'; + + if (sourceRoot) { + return [joinPathFragments(sourceRoot, projectTypeDir), sourceRoot].find( + (path) => tree.exists(path) + ); + } + + return getSourcePath(tree, root, projectTypeDir) ?? root; +} + +function getSourcePath( + tree: Tree, + basePath: string, + projectTypeDir: string +): string | undefined { + const candidatePaths = [ + joinPathFragments(basePath, 'src', projectTypeDir), + joinPathFragments(basePath, 'src'), + joinPathFragments(basePath, projectTypeDir), + basePath, + ]; + + return candidatePaths.find((candidatePath) => tree.exists(candidatePath)); +} diff --git a/packages/angular/src/generators/stories/lib/module-info.ts b/packages/angular/src/generators/stories/lib/module-info.ts index 6dfcfb3d05..c4abf3d1ef 100644 --- a/packages/angular/src/generators/stories/lib/module-info.ts +++ b/packages/angular/src/generators/stories/lib/module-info.ts @@ -1,5 +1,10 @@ import type { Tree } from '@nrwl/devkit'; -import { logger, stripIndents, visitNotIgnoredFiles } from '@nrwl/devkit'; +import { + logger, + normalizePath, + stripIndents, + visitNotIgnoredFiles, +} from '@nrwl/devkit'; import { findNodes } from '@nrwl/workspace/src/utilities/typescript'; import { tsquery } from '@phenomnomnominal/tsquery'; import { extname } from 'path'; @@ -11,6 +16,7 @@ import type { } from 'typescript'; import { SyntaxKind } from 'typescript'; import { getDecoratorMetadata } from '../../../utils/nx-devkit/ast-utils'; +import type { EntryPoint } from './entry-point'; export function getModuleDeclaredComponents( file: SourceFile, @@ -43,12 +49,29 @@ export function getModuleDeclaredComponents( return getDeclaredComponentsInDeclarations(declarationsArray); } -export function getModuleFilePaths(tree: Tree, projectPath: string): string[] { +export function getModuleFilePaths( + tree: Tree, + entryPoint: EntryPoint +): string[] { let moduleFilePaths = [] as string[]; - visitNotIgnoredFiles(tree, projectPath, (filePath: string) => { - if (extname(filePath) === '.ts' && hasNgModule(tree, filePath)) { - moduleFilePaths.push(filePath); + visitNotIgnoredFiles(tree, entryPoint.path, (filePath: string) => { + const normalizedFilePath = normalizePath(filePath); + + if ( + entryPoint.excludeDirs?.some((excludeDir) => + normalizedFilePath.startsWith(excludeDir) + ) + ) { + return; + } + + if ( + extname(normalizedFilePath) === '.ts' && + !normalizedFilePath.includes('.storybook') && + hasNgModule(tree, normalizedFilePath) + ) { + moduleFilePaths.push(normalizedFilePath); } }); diff --git a/packages/angular/src/generators/stories/stories-lib.spec.ts b/packages/angular/src/generators/stories/stories-lib.spec.ts index 6fa11940fc..f4baa49620 100644 --- a/packages/angular/src/generators/stories/stories-lib.spec.ts +++ b/packages/angular/src/generators/stories/stories-lib.spec.ts @@ -1,8 +1,10 @@ import type { Tree } from '@nrwl/devkit'; +import { writeJson } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; import { cypressProjectGenerator } from '@nrwl/storybook'; import { componentGenerator } from '../component/component'; +import { librarySecondaryEntryPointGenerator } from '../library-secondary-entry-point/library-secondary-entry-point'; import { libraryGenerator } from '../library/library'; import { scamGenerator } from '../scam/scam'; import { createStorybookTestWorkspaceForLib } from '../utils/testing'; @@ -36,7 +38,20 @@ describe('angularStories generator: libraries', () => { tree = await createStorybookTestWorkspaceForLib(libName); }); - it('should generate stories.ts files', () => { + it('should generate stories.ts files', async () => { + // add secondary entrypoint + writeJson(tree, `libs/${libName}/package.json`, { name: libName }); + await librarySecondaryEntryPointGenerator(tree, { + library: libName, + name: 'secondary-entry-point', + }); + // add a standalone component to the secondary entrypoint + await componentGenerator(tree, { + name: 'secondary-button', + project: libName, + path: `libs/${libName}/secondary-entry-point/src/lib`, + }); + angularStoriesGenerator(tree, { name: libName }); expect( @@ -65,6 +80,11 @@ describe('angularStories generator: libraries', () => { 'utf-8' ) ).toMatchSnapshot(); + expect( + tree.exists( + `libs/${libName}/secondary-entry-point/src/lib/secondary-button/secondary-button.component.stories.ts` + ) + ).toBeTruthy(); }); it('should generate cypress spec files', async () => { @@ -261,12 +281,26 @@ describe('angularStories generator: libraries', () => { ).toBeTruthy(); }); - it('should generate stories file for standalone component', async () => { + it('should generate stories file for standalone components', async () => { + // add standalone component await componentGenerator(tree, { name: 'standalone', project: libName, standalone: true, }); + // add secondary entrypoint + writeJson(tree, `libs/${libName}/package.json`, { name: libName }); + await librarySecondaryEntryPointGenerator(tree, { + library: libName, + name: 'secondary-entry-point', + }); + // add a standalone component to the secondary entrypoint + await componentGenerator(tree, { + name: 'secondary-standalone', + project: libName, + path: `libs/${libName}/secondary-entry-point/src/lib`, + standalone: true, + }); angularStoriesGenerator(tree, { name: libName }); @@ -281,6 +315,17 @@ describe('angularStories generator: libraries', () => { 'utf-8' ) ).toMatchSnapshot(); + expect( + tree.exists( + `libs/${libName}/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.stories.ts` + ) + ).toBeTruthy(); + expect( + tree.read( + `libs/${libName}/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.stories.ts`, + 'utf-8' + ) + ).toMatchSnapshot(); }); }); }); diff --git a/packages/angular/src/generators/stories/stories.ts b/packages/angular/src/generators/stories/stories.ts index ebe86d8c6c..7531c8e0f1 100644 --- a/packages/angular/src/generators/stories/stories.ts +++ b/packages/angular/src/generators/stories/stories.ts @@ -1,12 +1,13 @@ import type { Tree } from '@nrwl/devkit'; -import { formatFiles, logger } from '@nrwl/devkit'; -import { getProjectRootPath } from '@nrwl/workspace/src/utilities/project-type'; +import { formatFiles, joinPathFragments, logger } from '@nrwl/devkit'; import componentCypressSpecGenerator from '../component-cypress-spec/component-cypress-spec'; import componentStoryGenerator from '../component-story/component-story'; +import type { ComponentInfo } from './lib/component-info'; import { getComponentsInfo, getStandaloneComponentsInfo, } from './lib/component-info'; +import { getProjectEntryPoints } from './lib/entry-point'; import { getE2EProject } from './lib/get-e2e-project'; import { getModuleFilePaths } from './lib/module-info'; import type { StoriesGeneratorOptions } from './schema'; @@ -17,12 +18,16 @@ export function angularStoriesGenerator( ): void { const e2eProjectName = options.cypressProject ?? `${options.name}-e2e`; const e2eProject = getE2EProject(tree, e2eProjectName); - const projectPath = getProjectRootPath(tree, options.name); - const moduleFilePaths = getModuleFilePaths(tree, projectPath); - const componentsInfo = [ - ...getComponentsInfo(tree, moduleFilePaths, options.name), - ...getStandaloneComponentsInfo(tree, projectPath), - ]; + const entryPoints = getProjectEntryPoints(tree, options.name); + + const componentsInfo: ComponentInfo[] = []; + for (const entryPoint of entryPoints) { + const moduleFilePaths = getModuleFilePaths(tree, entryPoint); + componentsInfo.push( + ...getComponentsInfo(tree, entryPoint, moduleFilePaths, options.name), + ...getStandaloneComponentsInfo(tree, entryPoint) + ); + } if (options.generateCypressSpecs && !e2eProject) { logger.info( @@ -51,6 +56,7 @@ export function angularStoriesGenerator( componentName: info.name, componentPath: info.path, componentFileName: info.componentFileName, + specDirectory: joinPathFragments(info.entryPointName, info.path), skipFormat: false, }); } diff --git a/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap b/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap index 4224398ace..830dba849f 100644 --- a/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap +++ b/packages/angular/src/generators/storybook-configuration/__snapshots__/storybook-configuration.spec.ts.snap @@ -48,6 +48,9 @@ Array [ "apps/one/two/test-ui-lib-e2e/src/integration/cmp1/cmp1.component.spec.ts", "apps/one/two/test-ui-lib-e2e/src/integration/cmp2/cmp2.component.spec.ts", "apps/one/two/test-ui-lib-e2e/src/integration/nested-button/nested-button.component.spec.ts", + "apps/one/two/test-ui-lib-e2e/src/integration/secondary-entry-point/secondary-button/secondary-button.component.spec.ts", + "apps/one/two/test-ui-lib-e2e/src/integration/secondary-entry-point/secondary-standalone/secondary-standalone.component.spec.ts", + "apps/one/two/test-ui-lib-e2e/src/integration/standalone/standalone.component.spec.ts", "apps/one/two/test-ui-lib-e2e/src/integration/test-button/test-button.component.spec.ts", "apps/one/two/test-ui-lib-e2e/src/integration/test-other/test-other.component.spec.ts", "apps/one/two/test-ui-lib-e2e/src/integration/variable-declare-button/variable-declare-button.component.spec.ts", @@ -65,7 +68,22 @@ Array [ "libs/test-ui-lib/.storybook/preview.js", "libs/test-ui-lib/.storybook/tsconfig.json", "libs/test-ui-lib/jest.config.ts", + "libs/test-ui-lib/package.json", "libs/test-ui-lib/README.md", + "libs/test-ui-lib/secondary-entry-point/ng-package.json", + "libs/test-ui-lib/secondary-entry-point/README.md", + "libs/test-ui-lib/secondary-entry-point/src/index.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.css", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.html", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.spec.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.stories.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-entry-point.module.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.css", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.html", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.spec.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.stories.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.ts", "libs/test-ui-lib/src/index.ts", "libs/test-ui-lib/src/lib/barrel/barrel-button/barrel-button.component.css", "libs/test-ui-lib/src/lib/barrel/barrel-button/barrel-button.component.html", @@ -80,6 +98,11 @@ Array [ "libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.stories.ts", "libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.ts", "libs/test-ui-lib/src/lib/nested/nested.module.ts", + "libs/test-ui-lib/src/lib/standalone/standalone.component.css", + "libs/test-ui-lib/src/lib/standalone/standalone.component.html", + "libs/test-ui-lib/src/lib/standalone/standalone.component.spec.ts", + "libs/test-ui-lib/src/lib/standalone/standalone.component.stories.ts", + "libs/test-ui-lib/src/lib/standalone/standalone.component.ts", "libs/test-ui-lib/src/lib/static-member-declarations/cmp1/cmp1.component.css", "libs/test-ui-lib/src/lib/static-member-declarations/cmp1/cmp1.component.html", "libs/test-ui-lib/src/lib/static-member-declarations/cmp1/cmp1.component.spec.ts", @@ -153,6 +176,9 @@ Array [ "apps/test-ui-lib-e2e/src/integration/cmp1/cmp1.component.spec.ts", "apps/test-ui-lib-e2e/src/integration/cmp2/cmp2.component.spec.ts", "apps/test-ui-lib-e2e/src/integration/nested-button/nested-button.component.spec.ts", + "apps/test-ui-lib-e2e/src/integration/secondary-entry-point/secondary-button/secondary-button.component.spec.ts", + "apps/test-ui-lib-e2e/src/integration/secondary-entry-point/secondary-standalone/secondary-standalone.component.spec.ts", + "apps/test-ui-lib-e2e/src/integration/standalone/standalone.component.spec.ts", "apps/test-ui-lib-e2e/src/integration/test-button/test-button.component.spec.ts", "apps/test-ui-lib-e2e/src/integration/test-other/test-other.component.spec.ts", "apps/test-ui-lib-e2e/src/integration/variable-declare-button/variable-declare-button.component.spec.ts", @@ -170,7 +196,22 @@ Array [ "libs/test-ui-lib/.storybook/preview.js", "libs/test-ui-lib/.storybook/tsconfig.json", "libs/test-ui-lib/jest.config.ts", + "libs/test-ui-lib/package.json", "libs/test-ui-lib/README.md", + "libs/test-ui-lib/secondary-entry-point/ng-package.json", + "libs/test-ui-lib/secondary-entry-point/README.md", + "libs/test-ui-lib/secondary-entry-point/src/index.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.css", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.html", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.spec.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.stories.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-button/secondary-button.component.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-entry-point.module.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.css", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.html", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.spec.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.stories.ts", + "libs/test-ui-lib/secondary-entry-point/src/lib/secondary-standalone/secondary-standalone.component.ts", "libs/test-ui-lib/src/index.ts", "libs/test-ui-lib/src/lib/barrel/barrel-button/barrel-button.component.css", "libs/test-ui-lib/src/lib/barrel/barrel-button/barrel-button.component.html", @@ -185,6 +226,11 @@ Array [ "libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.stories.ts", "libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.ts", "libs/test-ui-lib/src/lib/nested/nested.module.ts", + "libs/test-ui-lib/src/lib/standalone/standalone.component.css", + "libs/test-ui-lib/src/lib/standalone/standalone.component.html", + "libs/test-ui-lib/src/lib/standalone/standalone.component.spec.ts", + "libs/test-ui-lib/src/lib/standalone/standalone.component.stories.ts", + "libs/test-ui-lib/src/lib/standalone/standalone.component.ts", "libs/test-ui-lib/src/lib/static-member-declarations/cmp1/cmp1.component.css", "libs/test-ui-lib/src/lib/static-member-declarations/cmp1/cmp1.component.html", "libs/test-ui-lib/src/lib/static-member-declarations/cmp1/cmp1.component.spec.ts", diff --git a/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts b/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts index 3ae16426bf..38163aeb04 100644 --- a/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts +++ b/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts @@ -1,7 +1,9 @@ import type { Tree } from '@nrwl/devkit'; -import { joinPathFragments } from '@nrwl/devkit'; +import { joinPathFragments, writeJson } from '@nrwl/devkit'; import { overrideCollectionResolutionForTesting } from '@nrwl/devkit/ngcli-adapter'; import { Linter } from 'packages/linter/src/generators/utils/linter'; +import { componentGenerator } from '../component/component'; +import { librarySecondaryEntryPointGenerator } from '../library-secondary-entry-point/library-secondary-entry-point'; import { createStorybookTestWorkspaceForLib } from '../utils/testing'; import type { StorybookConfigurationOptions } from './schema'; import { storybookConfigurationGenerator } from './storybook-configuration'; @@ -147,6 +149,34 @@ describe('StorybookConfiguration generator', () => { }); it('should generate the right files', async () => { + // add standalone component + await componentGenerator(tree, { + name: 'standalone', + project: libName, + standalone: true, + }); + // add secondary entrypoint + writeJson(tree, `libs/${libName}/package.json`, { name: libName }); + await librarySecondaryEntryPointGenerator(tree, { + library: libName, + name: 'secondary-entry-point', + }); + // add a regular component to the secondary entrypoint + await componentGenerator(tree, { + name: 'secondary-button', + project: libName, + path: `libs/${libName}/secondary-entry-point/src/lib`, + export: true, + }); + // add a standalone component to the secondary entrypoint + await componentGenerator(tree, { + name: 'secondary-standalone', + project: libName, + path: `libs/${libName}/secondary-entry-point/src/lib`, + standalone: true, + export: true, + }); + await storybookConfigurationGenerator(tree, { name: libName, configureCypress: true, @@ -158,6 +188,34 @@ describe('StorybookConfiguration generator', () => { }); it('should generate in the correct folder', async () => { + // add standalone component + await componentGenerator(tree, { + name: 'standalone', + project: libName, + standalone: true, + }); + // add secondary entrypoint + writeJson(tree, `libs/${libName}/package.json`, { name: libName }); + await librarySecondaryEntryPointGenerator(tree, { + library: libName, + name: 'secondary-entry-point', + }); + // add a regular component to the secondary entrypoint + await componentGenerator(tree, { + name: 'secondary-button', + project: libName, + path: `libs/${libName}/secondary-entry-point/src/lib`, + export: true, + }); + // add a standalone component to the secondary entrypoint + await componentGenerator(tree, { + name: 'secondary-standalone', + project: libName, + path: `libs/${libName}/secondary-entry-point/src/lib`, + standalone: true, + export: true, + }); + await storybookConfigurationGenerator(tree, { name: libName, configureCypress: true,