fix(storybook): find any module file

This commit is contained in:
Isaac Mann 2020-02-28 16:12:19 -05:00 committed by Victor Savkin
parent e2b8406692
commit c2bac02420
2 changed files with 128 additions and 105 deletions

View File

@ -32,6 +32,11 @@ describe('schematic:stories', () => {
'libs/test-ui-lib/src/lib/test-other/test-other.component.stories.ts' 'libs/test-ui-lib/src/lib/test-other/test-other.component.stories.ts'
) )
).toBeTruthy(); ).toBeTruthy();
expect(
tree.exists(
'libs/test-ui-lib/src/lib/nested/nested-button/nested-button.component.stories.ts'
)
).toBeTruthy();
const propLines = [ const propLines = [
`buttonType: text('buttonType', 'button'),`, `buttonType: text('buttonType', 'button'),`,
`style: text('style', 'default'),`, `style: text('style', 'default'),`,
@ -137,6 +142,23 @@ export async function createTestUILib(libName: string): Promise<Tree> {
`import * as ButtonExports from './test-button/test-button.component'; `import * as ButtonExports from './test-button/test-button.component';
${appTree.read(modulePath)}` ${appTree.read(modulePath)}`
); );
appTree = await callRule(
externalSchematic('@schematics/angular', 'module', {
name: 'nested',
project: libName,
path: `libs/${libName}/src/lib`
}),
appTree
);
appTree = await callRule(
externalSchematic('@schematics/angular', 'component', {
name: 'nested-button',
project: libName,
module: 'nested',
path: `libs/${libName}/src/lib/nested`
}),
appTree
);
appTree.overwrite( appTree.overwrite(
`libs/${libName}/src/lib/test-button/test-button.component.ts`, `libs/${libName}/src/lib/test-button/test-button.component.ts`,
` `

View File

@ -29,12 +29,15 @@ export function createAllStories(
context.logger.debug('adding .storybook folder to lib'); context.logger.debug('adding .storybook folder to lib');
const libPath = getProjectConfig(tree, projectName).sourceRoot + '/lib'; const libPath = getProjectConfig(tree, projectName).sourceRoot + '/lib';
let moduleFilePaths = [] as string[];
tree.getDir(libPath).visit(filePath => {
if (!filePath.endsWith('.module.ts')) {
return;
}
moduleFilePaths.push(filePath);
});
return chain( return chain(
tree moduleFilePaths.map(filePath => {
.getDir(libPath)
.subfiles.filter(fileName => fileName.endsWith('.module.ts'))
.map(fileName => {
const filePath = libPath + '/' + fileName;
const file = getTsSourceFile(tree, filePath); const file = getTsSourceFile(tree, filePath);
const ngModuleDecorators = getDecoratorMetadata( const ngModuleDecorators = getDecoratorMetadata(
@ -113,26 +116,24 @@ export function createAllStories(
} }
}); });
const modulePath = filePath.substr(0, filePath.lastIndexOf('/'));
return chain( return chain(
componentInfo componentInfo
.filter(info => info !== undefined) .filter(info => info !== undefined)
.map(info => .map(info =>
chain([ chain([
schematic<CreateComponentStoriesFileSchema>( schematic<CreateComponentStoriesFileSchema>('component-story', {
'component-story', libPath: modulePath,
{
libPath,
componentName: info.name, componentName: info.name,
componentPath: info.path, componentPath: info.path,
componentFileName: info.componentFileName componentFileName: info.componentFileName
} }),
),
generateCypressSpecs generateCypressSpecs
? schematic<CreateComponentSpecFileSchema>( ? schematic<CreateComponentSpecFileSchema>(
'component-cypress-spec', 'component-cypress-spec',
{ {
projectName, projectName,
libPath, libPath: modulePath,
componentName: info.name, componentName: info.name,
componentPath: info.path, componentPath: info.path,
componentFileName: info.componentFileName componentFileName: info.componentFileName