-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
stories.ts
58 lines (52 loc) · 2 KB
/
stories.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { Tree } from '@nrwl/devkit';
import { logger } from '@nrwl/devkit';
import { getProjectRootPath } from '@nrwl/workspace/src/utilities/project-type';
import componentCypressSpecGenerator from '../component-cypress-spec/component-cypress-spec';
import componentStoryGenerator from '../component-story/component-story';
import {
getComponentsInfo,
getStandaloneComponentsInfo,
} from './lib/component-info';
import { getE2EProject } from './lib/get-e2e-project';
import { getModuleFilePaths } from './lib/module-info';
import type { StoriesGeneratorOptions } from './schema';
export function angularStoriesGenerator(
tree: Tree,
options: StoriesGeneratorOptions
): 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),
];
if (options.generateCypressSpecs && !e2eProject) {
logger.info(
`There was no e2e project "${e2eProjectName}" found, so cypress specs will not be generated. Pass "--cypressProject" to specify a different e2e project name.`
);
}
componentsInfo.forEach((info) => {
if (info === undefined) {
return;
}
componentStoryGenerator(tree, {
projectPath: info.moduleFolderPath,
componentName: info.name,
componentPath: info.path,
componentFileName: info.componentFileName,
});
if (options.generateCypressSpecs && e2eProject) {
componentCypressSpecGenerator(tree, {
projectName: options.name,
projectPath: info.moduleFolderPath,
cypressProject: options.cypressProject,
componentName: info.name,
componentPath: info.path,
componentFileName: info.componentFileName,
});
}
});
}
export default angularStoriesGenerator;