From 2a6ab96588c4847aef532eb72c4274afa9549596 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 4 Nov 2024 17:56:56 +0100 Subject: [PATCH] feat(scripts-executors): add inferred projects support to start experience (#33198) --- .github/workflows/check-tooling.yml | 3 ++ scripts/executors/src/start.ts | 47 ++++++++++++------- .../src/executors/generate-api/executor.ts | 3 +- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index 49a6353341bfd..d43b425484aa1 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -35,6 +35,9 @@ jobs: - run: yarn nx list @fluentui/workspace-plugin + # pre-build react-jsx-runtime - as generate-api executor doesn't provide copy assets capability + - run: yarn nx run react-jsx-runtime:build + - run: yarn nx g @fluentui/workspace-plugin:react-library --name hello-world --owner '@microsoft/fluentui-react-build' --kind standard --no-interactive - run: yarn nx g @fluentui/workspace-plugin:react-component --project hello-world-preview --name Aiur --no-interactive - run: yarn nx g @fluentui/workspace-plugin:cypress-component-configuration --project hello-world-preview --no-interactive diff --git a/scripts/executors/src/start.ts b/scripts/executors/src/start.ts index 7c70d9a4da872..7ba69f0ecf1f1 100644 --- a/scripts/executors/src/start.ts +++ b/scripts/executors/src/start.ts @@ -210,8 +210,19 @@ async function getSelectedTarget( .filter(targetName => { return omitTargets.includes(targetName) ? false : true; }) + .map(targetName => { + const targetConfigurations = Object.keys(projectTargets[targetName].configurations || {}); + + if (targetConfigurations) { + return [targetName, ...targetConfigurations.map(target => `${targetName}:${target}`)]; + } + + return targetName; + }) + .flat() .sort() .concat('help'); + const preselectedTargetChoice = preselectedTarget && availableTargets.indexOf(preselectedTarget) !== -1 ? availableTargets.indexOf(preselectedTarget) @@ -269,39 +280,43 @@ function createTargetDescription( targetName: string, targetsDescription: Record, ) { - const description = targetsDescription[targetName]; + const manualConfigDrivenDescription = targetsDescription[targetName]; const nxTargetConfiguration = projectConfig.data.targets?.[targetName]; + const nxMetadataDescription = nxTargetConfiguration?.metadata?.description; + const scriptContent: string | undefined = nxTargetConfiguration?.metadata?.scriptContent; + const command = scriptContent || nxTargetConfiguration?.options.command || nxTargetConfiguration?.command; + // special case for non existent targets that we add artificially like `help` if (!nxTargetConfiguration) { - return description; + return manualConfigDrivenDescription; + } + + if (nxMetadataDescription) { + return nxMetadataDescription; } if (targetName === 'start') { - const scriptContent = nxTargetConfiguration.metadata?.scriptContent; - if (scriptContent.includes('storybook')) { + if (command && command.includes('storybook')) { return `Start the project (Alias of "storybook" target)`; } - return description; + + return manualConfigDrivenDescription; } if (targetName === 'e2e') { - const scriptContent = nxTargetConfiguration.metadata?.scriptContent; - const runnerType = getRunnerType(scriptContent); - - if (!runnerType) { - return scriptContent; - } + const runnerType = command && getRunnerType(command); + console.log({ runnerType, command }); - return description + ` (using ${runnerType})`; + return runnerType ? manualConfigDrivenDescription + ` (using ${runnerType})` : manualConfigDrivenDescription; } - return description ?? nxTargetConfiguration.metadata?.scriptContent; + return manualConfigDrivenDescription ?? command; - function getRunnerType(scriptContent: string): 'cypress' | 'playwright' | null { - if (scriptContent.includes('cypress')) { + function getRunnerType(value: string): 'cypress' | 'playwright' | null { + if (value.includes('cypress')) { return 'cypress'; } - if (scriptContent.includes('playwright')) { + if (value.includes('playwright')) { return 'playwright'; } diff --git a/tools/workspace-plugin/src/executors/generate-api/executor.ts b/tools/workspace-plugin/src/executors/generate-api/executor.ts index 03bbd6d4a67c1..0549d5d688844 100644 --- a/tools/workspace-plugin/src/executors/generate-api/executor.ts +++ b/tools/workspace-plugin/src/executors/generate-api/executor.ts @@ -46,7 +46,8 @@ function normalizeOptions(schema: GenerateApiExecutorSchema, context: ExecutorCo const project = context.projectsConfigurations!.projects[context.projectName!]; - const resolveLocalFlag = Boolean(process.env.__FORCE_API_MD_UPDATE__) || isCI() ? false : resolvedSchema.local; + const resolveLocalFlag = Boolean(process.env.__FORCE_API_MD_UPDATE__) || (isCI() ? false : resolvedSchema.local); + const projectAbsolutePath = join(context.root, project.root); const resolveConfig = getApiExtractorConfigPath(resolvedSchema, projectAbsolutePath); const tsConfigPathForCompilation = getTsConfigPathUsedForProduction(projectAbsolutePath);