From fc1c04918b7f71520c22546723a5c20d2236ee71 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 12 Jul 2024 11:28:28 -0700 Subject: [PATCH] feat(gradle): add help metadata (#26810) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- .../target-configuration-details.tsx | 56 ++++++++--------- packages/gradle/src/plugin/nodes.spec.ts | 60 +++++++++++++++++++ packages/gradle/src/plugin/nodes.ts | 24 ++++++++ packages/nx/src/command-line/graph/graph.ts | 2 +- 4 files changed, 114 insertions(+), 28 deletions(-) diff --git a/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx b/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx index 1f8d1e195b76f..640708eb3a6e9 100644 --- a/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx +++ b/graph/ui-project-details/src/lib/target-configuration-details/target-configuration-details.tsx @@ -74,9 +74,9 @@ export default function TargetConfigurationDetails({ getDisplayHeaderFromTargetConfiguration(targetConfiguration); const configurations = targetConfiguration.configurations; - const shouldRenderOptions = + const shouldRenderOptions: boolean = options && - (typeof options === 'object' ? Object.keys(options).length : true); + (typeof options === 'object' ? Object.keys(options).length > 0 : true); const shouldRenderConfigurations = configurations && @@ -137,7 +137,7 @@ export default function TargetConfigurationDetails({ )} - {shouldRenderOptions ? ( + {shouldRenderOptions || targetConfiguration.metadata?.help ? ( <>

-
- - ( - - )} + {shouldRenderOptions ? ( +
+ + ( + + )} + /> + +
+ ) : null} + {targetConfiguration.metadata?.help && ( +
+ - -
-
- -
+
+ )} - ) : ( - '' - )} + ) : null} {targetConfiguration.inputs && (
diff --git a/packages/gradle/src/plugin/nodes.spec.ts b/packages/gradle/src/plugin/nodes.spec.ts index 609e4cb67b0ef..b6d19b43e83a9 100644 --- a/packages/gradle/src/plugin/nodes.spec.ts +++ b/packages/gradle/src/plugin/nodes.spec.ts @@ -98,6 +98,16 @@ describe('@nx/gradle/plugin', () => { "^production", ], "metadata": { + "help": { + "command": "./gradlew help --task proj:test", + "example": { + "options": { + "args": [ + "--rerun", + ], + }, + }, + }, "technologies": [ "gradle", ], @@ -168,6 +178,16 @@ describe('@nx/gradle/plugin', () => { "^production", ], "metadata": { + "help": { + "command": "./gradlew help --task proj:test", + "example": { + "options": { + "args": [ + "--rerun", + ], + }, + }, + }, "technologies": [ "gradle", ], @@ -256,6 +276,16 @@ describe('@nx/gradle/plugin', () => { "^production", ], "metadata": { + "help": { + "command": "./gradlew help --task proj:test", + "example": { + "options": { + "args": [ + "--rerun", + ], + }, + }, + }, "technologies": [ "gradle", ], @@ -282,6 +312,16 @@ describe('@nx/gradle/plugin', () => { ], "metadata": { "description": "Runs Gradle Tests in CI", + "help": { + "command": "./gradlew help --task proj:test", + "example": { + "options": { + "args": [ + "--rerun", + ], + }, + }, + }, "nonAtomizedTarget": "test", "technologies": [ "gradle", @@ -300,6 +340,16 @@ describe('@nx/gradle/plugin', () => { ], "metadata": { "description": "Runs Gradle test nested/nested/proj/src/test/java/test/test.java in CI", + "help": { + "command": "./gradlew help --task proj:test", + "example": { + "options": { + "args": [ + "--rerun", + ], + }, + }, + }, "technologies": [ "gradle", ], @@ -317,6 +367,16 @@ describe('@nx/gradle/plugin', () => { ], "metadata": { "description": "Runs Gradle test nested/nested/proj/src/test/java/test/test1.java in CI", + "help": { + "command": "./gradlew help --task proj:test", + "example": { + "options": { + "args": [ + "--rerun", + ], + }, + }, + }, "technologies": [ "gradle", ], diff --git a/packages/gradle/src/plugin/nodes.ts b/packages/gradle/src/plugin/nodes.ts index a42bdd9ac0f5d..8abf3dc4212ff 100644 --- a/packages/gradle/src/plugin/nodes.ts +++ b/packages/gradle/src/plugin/nodes.ts @@ -275,6 +275,14 @@ async function createGradleTargets( dependsOn: dependsOnMap[task.name], metadata: { technologies: ['gradle'], + help: { + command: `${getGradleExecFile()} help --task ${taskCommandToRun}`, + example: { + options: { + args: ['--rerun'], + }, + }, + }, }, ...(outputs && outputs.length ? { outputs } : {}), }; @@ -335,6 +343,14 @@ function getTestCiTargets( metadata: { technologies: ['gradle'], description: `Runs Gradle test ${testFile} in CI`, + help: { + command: `${getGradleExecFile()} help --task ${taskCommandToRun}`, + example: { + options: { + args: ['--rerun'], + }, + }, + }, }, ...(outputs && outputs.length > 0 ? { outputs } : {}), }; @@ -356,6 +372,14 @@ function getTestCiTargets( technologies: ['gradle'], description: 'Runs Gradle Tests in CI', nonAtomizedTarget: testTargetName, + help: { + command: `${getGradleExecFile()} help --task ${taskCommandToRun}`, + example: { + options: { + args: ['--rerun'], + }, + }, + }, }, }; targetGroups[targetGroupName].push(ciTargetName); diff --git a/packages/nx/src/command-line/graph/graph.ts b/packages/nx/src/command-line/graph/graph.ts index 6a9e04a3ec56c..9f994085e2fca 100644 --- a/packages/nx/src/command-line/graph/graph.ts +++ b/packages/nx/src/command-line/graph/graph.ts @@ -1220,6 +1220,6 @@ function getHelpTextFromTarget( throw new Error(`No help command found for ${projectName}:${targetName}`); return execSync(command, { - cwd: join(workspaceRoot, project.data.root), + cwd: target.options?.cwd ?? workspaceRoot, }).toString(); }