Skip to content

Commit

Permalink
feat: add buildTargetName option to init generator
Browse files Browse the repository at this point in the history
  • Loading branch information
khalilou88 committed Oct 18, 2024
1 parent c7499e8 commit 1694991
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
31 changes: 27 additions & 4 deletions packages/nx-gradle/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,42 @@ export async function initGenerator(
}

function updateNxJson(tree: Tree, options: NormalizedSchema) {
let plugin: string | object;
let pluginOptions = {};

if (options.gradleRootDirectory) {
pluginOptions = {
...pluginOptions,
gradleRootDirectory: options.gradleRootDirectory,
};
}

if (options.buildTargetName && options.buildTargetName !== 'build') {
pluginOptions = {
...pluginOptions,
buildTargetName: options.buildTargetName,
};
}

let plugin: string | object;
if (pluginOptions) {
plugin = {
plugin: '@jnxplus/nx-gradle',
options: {
gradleRootDirectory: options.gradleRootDirectory,
},
options: pluginOptions,
};
} else {
plugin = '@jnxplus/nx-gradle';
}

updateJson(tree, 'nx.json', (nxJson) => {
nxJson.targetDefaults = {
...nxJson.targetDefaults,
[options.buildTargetName]: {
cache: true,
dependsOn: [`^${options.buildTargetName}`],
inputs: ['production', '^production'],
},
};

// if plugins is undefined, set it to an empty array
nxJson.plugins = nxJson.plugins ?? [];
// add plugin
Expand Down
1 change: 1 addition & 0 deletions packages/nx-gradle/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface NxGradleInitGeneratorSchema {
versionManagement: VersionManagementType;
skipFormat?: boolean;
formatter?: 'none' | 'prettier';
buildTargetName: string;
}
5 changes: 5 additions & 0 deletions packages/nx-gradle/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
}
]
}
},
"buildTargetName": {
"type": "string",
"description": "Build target name",
"default": "build"
}
},
"required": [
Expand Down

0 comments on commit 1694991

Please sign in to comment.