Skip to content

Commit

Permalink
feat(gradle): add help metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jul 3, 2024
1 parent 1cebb11 commit 1b3dee5
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,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 &&
Expand Down Expand Up @@ -148,7 +148,7 @@ export default function TargetConfigurationDetails({
</div>
)}

{shouldRenderOptions ? (
{shouldRenderOptions || !!targetConfiguration.metadata?.help ? (
<>
<h4 className="mb-4">
<Tooltip
Expand All @@ -160,31 +160,33 @@ export default function TargetConfigurationDetails({
</span>
</Tooltip>
</h4>
<div className="mb-4">
<FadingCollapsible>
<JsonCodeBlock
data={options}
renderSource={(propertyName: string) => (
<TargetSourceInfo
className="flex min-w-0 pl-4"
propertyKey={`targets.${targetName}.options.${propertyName}`}
sourceMap={sourceMap}
/>
)}
{shouldRenderOptions ? (
<div className="mb-4">
<FadingCollapsible>
<JsonCodeBlock
data={options}
renderSource={(propertyName: string) => (
<TargetSourceInfo
className="flex min-w-0 pl-4"
propertyKey={`targets.${targetName}.options.${propertyName}`}
sourceMap={sourceMap}
/>
)}
/>
</FadingCollapsible>
</div>
) : null}
{targetConfiguration.metadata?.help && (
<div className="mb-4">
<ShowOptionsHelp
targetConfiguration={targetConfiguration}
projectName={projectName}
targetName={targetName}
/>
</FadingCollapsible>
</div>
<div className="mb-4">
<ShowOptionsHelp
targetConfiguration={targetConfiguration}
projectName={projectName}
targetName={targetName}
/>
</div>
</div>
)}
</>
) : (
''
)}
) : null}

{targetConfiguration.inputs && (
<div className="group">
Expand Down
60 changes: 60 additions & 0 deletions packages/gradle/src/plugin/nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ describe('@nx/gradle/plugin', () => {
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand Down Expand Up @@ -172,6 +182,16 @@ describe('@nx/gradle/plugin', () => {
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand Down Expand Up @@ -254,6 +274,16 @@ describe('@nx/gradle/plugin', () => {
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand All @@ -280,6 +310,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",
Expand All @@ -298,6 +338,16 @@ describe('@nx/gradle/plugin', () => {
],
"metadata": {
"description": "Runs Gradle Tests test in CI",
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand All @@ -315,6 +365,16 @@ describe('@nx/gradle/plugin', () => {
],
"metadata": {
"description": "Runs Gradle Tests test1 in CI",
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
Expand Down
32 changes: 32 additions & 0 deletions packages/gradle/src/plugin/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ async function createGradleTargets(
dependsOn: dependsOnMap[task.name],
metadata: {
technologies: ['gradle'],
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
...(output ? { outputs: [output] } : {}),
};
Expand Down Expand Up @@ -312,6 +320,14 @@ function getTestTargets(
dependsOn: dependsOnMap['test'],
metadata: {
technologies: ['gradle'],
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
...(outputs.length > 0 ? { outputs } : {}),
};
Expand All @@ -338,6 +354,14 @@ function getTestTargets(
metadata: {
technologies: ['gradle'],
description: `Runs Gradle Tests ${testName} in CI`,
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
...(outputs && outputs.length > 0 ? { outputs } : {}),
};
Expand All @@ -359,6 +383,14 @@ function getTestTargets(
technologies: ['gradle'],
description: 'Runs Gradle Tests in CI',
nonAtomizedTarget: testTargetName,
help: {
command: `${getGradleExecFile()} help --task ${taskCommandToRun}`,
example: {
options: {
args: ['--rerun'],
},
},
},
},
};
targetGroups[taskType].push(ciTargetName);
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,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();
}

0 comments on commit 1b3dee5

Please sign in to comment.