Skip to content

Commit

Permalink
feat(executors): add command option for better adaption
Browse files Browse the repository at this point in the history
  • Loading branch information
khalilou88 committed Jul 12, 2023
1 parent bb89634 commit 81a0c07
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 77 deletions.
22 changes: 3 additions & 19 deletions packages/gradle/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ export default async function runExecutor(

let target = '';

if (
getPluginName(context) === '@jnxplus/nx-boot-gradle' ||
options.framework === 'spring-boot'
) {
if (options.command) {
target = options.command;
} else if (getPluginName(context) === '@jnxplus/nx-boot-gradle') {
if (getProjectType(context) === 'library') {
target = 'jar';
} else {
Expand All @@ -34,21 +33,6 @@ export default async function runExecutor(
}
}

if (
getPluginName(context) === '@jnxplus/nx-quarkus-gradle' ||
options.framework === 'quarkus'
) {
//use quarkusBuild (instead of build task) to not trigger test
target = 'quarkusBuild';
}

if (
getPluginName(context) === '@jnxplus/nx-micronaut-gradle' ||
options.framework === 'micronaut'
) {
target = 'build -x test';
}

//default build task
if (!target) {
target = 'build -x test';
Expand Down
9 changes: 6 additions & 3 deletions packages/gradle/src/executors/build/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { PackagingType } from '@jnxplus/common';

export interface BuildExecutorSchema {
packaging?: PackagingType;
framework?: 'spring-boot' | 'quarkus' | 'micronaut';
args: string;
projectPath?: string;
//TODO: make command mandatory
command?: string;
args?: string;
//TODO: remove packaging option and make command mandatory
//deprecated, use command to define your build command
packaging?: PackagingType;
}
13 changes: 10 additions & 3 deletions packages/gradle/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
"description": "",
"type": "object",
"properties": {
"projectPath": {
"type": "string"
},
"command": {
"type": "string"
},
"args": {
"type": "string"
},
"packaging": {
"type": "string",
"description": "deprecated, use command to define your build command",
"default": "jar"
},
"projectPath": {
"type": "string"
}
},
"required": []
Expand Down
19 changes: 1 addition & 18 deletions packages/gradle/src/executors/serve/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,14 @@ export default async function runExecutor(

let command = `${getExecutable()} ${projectPath}:`;

if (
getPluginName(context) === '@jnxplus/nx-boot-gradle' ||
options.framework === 'spring-boot'
) {
if (getPluginName(context) === '@jnxplus/nx-boot-gradle') {
command += 'bootRun';

if (options.args) {
command += ` --args='${options.args}'`;
}
}

if (
getPluginName(context) === '@jnxplus/nx-quarkus-gradle' ||
options.framework === 'quarkus'
) {
command += 'quarkusDev';
}

if (
getPluginName(context) === '@jnxplus/nx-micronaut-gradle' ||
options.framework === 'micronaut'
) {
command += 'run';
}

const result = runCommand(command);

if (!result.success) {
Expand Down
6 changes: 4 additions & 2 deletions packages/gradle/src/executors/serve/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export interface ServeExecutorSchema {
framework?: 'spring-boot' | 'quarkus' | 'micronaut';
args: string;
projectPath?: string;
//TODO: make command mandatory
command?: string;
//TODO: remove args and use only command
args?: string;
}
7 changes: 5 additions & 2 deletions packages/gradle/src/executors/serve/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"description": "",
"type": "object",
"properties": {
"args": {
"projectPath": {
"type": "string"
},
"projectPath": {
"command": {
"type": "string"
},
"args": {
"type": "string"
}
},
Expand Down
55 changes: 28 additions & 27 deletions packages/gradle/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,18 @@ export default async function (
targets: {
build: {
executor: `${plugin}:build`,
options: {
command: 'build -x test',
},
outputs: [`${normalizedOptions.projectRoot}/build`],
},
'build-image': {},
serve: {},
serve: {
executor: `${plugin}:serve`,
options: {
command: 'run',
},
},
lint: {
executor: `${plugin}:lint`,
options: {
Expand All @@ -416,43 +424,36 @@ export default async function (
) {
targets['build'].options = {
...targets['build'].options,
packaging: `${normalizedOptions.packaging}`,
command: normalizedOptions.packaging === 'war' ? 'bootWar' : 'bootJar',
};
}

if (options.framework === 'none') {
targets['serve'] = {
executor: `${plugin}:run-task`,
options: {
task: 'run',
},
};
}

if (options.framework !== 'none') {
targets['build-image'] = {
executor: `${plugin}:build-image`,
};

targets['serve'] = {
executor: `${plugin}:serve`,
targets['serve'].options = {
...targets['serve'].options,
command: 'bootRun',
};
}

if (options.framework && options.framework !== 'none') {
if (
plugin === '@jnxplus/nx-quarkus-gradle' ||
options.framework === 'quarkus'
) {
targets['build'].options = {
...targets['build'].options,
framework: options.framework,
};

targets['build-image'].options = {
...targets['build-image'].options,
framework: options.framework,
command: 'quarkusBuild',
};

targets['serve'].options = {
...targets['serve'].options,
framework: options.framework,
command: 'quarkusDev',
};
}

if (options.framework && options.framework !== 'none') {
targets['build-image'] = {
executor: `${plugin}:build-image`,
options: {
framework: options.framework,
},
};
}

Expand Down
11 changes: 8 additions & 3 deletions packages/gradle/src/generators/library/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ export default async function (
targets: {
build: {
executor: `${plugin}:build`,
options: {
command: 'build -x test',
},
outputs: [`${normalizedOptions.projectRoot}/build`],
},
lint: {
Expand All @@ -339,11 +342,13 @@ export default async function (

const targets = projectConfiguration.targets ?? {};

//this is important because in case of spring boot we use jar task to build libraries
if (options.framework && options.framework !== 'none') {
if (
plugin === '@jnxplus/nx-boot-gradle' ||
options.framework === 'spring-boot'
) {
targets['build'].options = {
...targets['build'].options,
framework: options.framework,
command: 'jar',
};
}

Expand Down

0 comments on commit 81a0c07

Please sign in to comment.