fix(storybook): proper detection of e2e project existence (#13635)
This commit is contained in:
parent
4196ad3758
commit
b959109390
@ -1,10 +1,4 @@
|
||||
import {
|
||||
formatFiles,
|
||||
joinPathFragments,
|
||||
logger,
|
||||
readProjectConfiguration,
|
||||
Tree,
|
||||
} from '@nrwl/devkit';
|
||||
import { formatFiles, joinPathFragments, logger, Tree } from '@nrwl/devkit';
|
||||
import componentCypressSpecGenerator from '../component-cypress-spec/component-cypress-spec';
|
||||
import componentStoryGenerator from '../component-story/component-story';
|
||||
import type { ComponentInfo } from '../utils/storybook-ast/component-info';
|
||||
@ -25,7 +19,6 @@ export function angularStoriesGenerator(
|
||||
const e2eProjectName = options.cypressProject ?? `${options.name}-e2e`;
|
||||
const e2eProject = getE2EProject(tree, e2eProjectName);
|
||||
const entryPoints = getProjectEntryPoints(tree, options.name);
|
||||
const { root } = readProjectConfiguration(tree, options.name);
|
||||
const componentsInfo: ComponentInfo[] = [];
|
||||
for (const entryPoint of entryPoints) {
|
||||
const moduleFilePaths = getModuleFilePaths(tree, entryPoint);
|
||||
|
||||
@ -22,6 +22,7 @@ import {
|
||||
createProjectStorybookDir,
|
||||
createRootStorybookDir,
|
||||
createRootStorybookDirForRootProject,
|
||||
getE2EProjectName,
|
||||
projectIsRootProjectInNestedWorkspace,
|
||||
updateLintConfig,
|
||||
} from './util-functions';
|
||||
@ -106,19 +107,20 @@ export async function configurationGenerator(
|
||||
);
|
||||
}
|
||||
|
||||
if (schema.configureCypress) {
|
||||
if (projectType !== 'application') {
|
||||
const cypressTask = await cypressProjectGenerator(tree, {
|
||||
name: schema.name,
|
||||
js: schema.js,
|
||||
linter: schema.linter,
|
||||
directory: schema.cypressDirectory,
|
||||
standaloneConfig: schema.standaloneConfig,
|
||||
});
|
||||
tasks.push(cypressTask);
|
||||
} else {
|
||||
logger.warn('There is already an e2e project setup');
|
||||
}
|
||||
const e2eProject = getE2EProjectName(tree, schema.name);
|
||||
if (schema.configureCypress && !e2eProject) {
|
||||
const cypressTask = await cypressProjectGenerator(tree, {
|
||||
name: schema.name,
|
||||
js: schema.js,
|
||||
linter: schema.linter,
|
||||
directory: schema.cypressDirectory,
|
||||
standaloneConfig: schema.standaloneConfig,
|
||||
});
|
||||
tasks.push(cypressTask);
|
||||
} else {
|
||||
logger.warn(
|
||||
`There is already an e2e project setup for ${schema.name}, called ${e2eProject}.`
|
||||
);
|
||||
}
|
||||
|
||||
if (nextBuildTarget && projectType === 'application') {
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import {
|
||||
generateFiles,
|
||||
getProjects,
|
||||
joinPathFragments,
|
||||
logger,
|
||||
offsetFromRoot,
|
||||
parseTargetString,
|
||||
readJson,
|
||||
readProjectConfiguration,
|
||||
readWorkspaceConfiguration,
|
||||
@ -24,6 +26,7 @@ import {
|
||||
} from '../../utils/utilities';
|
||||
import { StorybookConfigureSchema } from './schema';
|
||||
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
|
||||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
|
||||
|
||||
const DEFAULT_PORT = 4400;
|
||||
|
||||
@ -533,3 +536,31 @@ export function rootFileIsTs(
|
||||
return tsConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
export function getE2EProjectName(
|
||||
tree: Tree,
|
||||
mainProject: string
|
||||
): string | undefined {
|
||||
let e2eProject: string;
|
||||
forEachExecutorOptions(
|
||||
tree,
|
||||
'@nrwl/cypress:cypress',
|
||||
(options, projectName) => {
|
||||
if (e2eProject) {
|
||||
return;
|
||||
}
|
||||
if (options['devServerTarget']) {
|
||||
const { project, target } = parseTargetString(
|
||||
options['devServerTarget']
|
||||
);
|
||||
if (
|
||||
(project === mainProject && target === 'serve') ||
|
||||
(project === mainProject && target === 'storybook')
|
||||
) {
|
||||
e2eProject = projectName;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
return e2eProject;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user