fix(angular): generate stories for secondary entrypoints (#11005)
This commit is contained in:
parent
2753c11fe9
commit
6a63138b08
@ -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",
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -5,5 +5,6 @@ export interface ComponentCypressSpecGeneratorOptions {
|
||||
componentPath: string;
|
||||
componentFileName: string;
|
||||
cypressProject?: string;
|
||||
specDirectory?: string;
|
||||
skipFormat?: boolean;
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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<StandaloneComponent> = (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<SecondaryStandaloneComponent>;
|
||||
|
||||
const Template: Story<SecondaryStandaloneComponent> = (args: SecondaryStandaloneComponent) => ({
|
||||
props: args,
|
||||
});
|
||||
|
||||
|
||||
export const Primary = Template.bind({});
|
||||
Primary.args = {
|
||||
}"
|
||||
|
||||
@ -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(
|
||||
|
||||
117
packages/angular/src/generators/stories/lib/entry-point.ts
Normal file
117
packages/angular/src/generators/stories/lib/entry-point.ts
Normal file
@ -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));
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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, <StorybookConfigurationOptions>{
|
||||
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, <StorybookConfigurationOptions>{
|
||||
name: libName,
|
||||
configureCypress: true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user