Skip to content

Commit

Permalink
feat(executors): use run-task instead of others executors
Browse files Browse the repository at this point in the history
  • Loading branch information
khalilou88 committed Jul 27, 2023
1 parent 85a1f5d commit ea31aeb
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 265 deletions.
71 changes: 45 additions & 26 deletions packages/gradle/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,31 @@ export default async function (
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: `${plugin}:build`,
executor: `${plugin}:run-task`,
outputs: [`${normalizedOptions.projectRoot}/build`],
options: {
task: 'build',
},
},
'build-image': {},
serve: {},
serve: {
executor: `${plugin}:run-task`,
options: {
task: 'run',
keepItRunning: true,
},
},
lint: {
executor: `${plugin}:lint`,
options: {
linter: `${normalizedOptions.linter}`,
},
},
test: {
executor: `${plugin}:test`,
executor: `${plugin}:run-task`,
options: {
task: 'test',
},
},
ktformat: {},
},
Expand All @@ -416,43 +428,50 @@ export default async function (
) {
targets['build'].options = {
...targets['build'].options,
packaging: `${normalizedOptions.packaging}`,
task: normalizedOptions.packaging === 'war' ? 'bootWar' : 'bootJar',
};
}

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

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

targets['serve'] = {
executor: `${plugin}:serve`,
executor: `${plugin}:run-task`,
options: {
task: 'bootBuildImage',
},
};
}

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,
task: 'quarkusBuild',
};

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

targets['build-image'] = {
executor: `${plugin}:quarkus-build-image`,
};
}

if (
plugin === '@jnxplus/nx-micronaut-gradle' ||
options.framework === 'micronaut'
) {
targets['build-image'] = {
executor: `${plugin}:run-task`,
options: {
task: 'dockerBuild',
},
};
}

Expand Down
18 changes: 13 additions & 5 deletions packages/gradle/src/generators/library/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ export default async function (
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: `${plugin}:build`,
executor: `${plugin}:run-task`,
options: {
command: 'build',
},
outputs: [`${normalizedOptions.projectRoot}/build`],
},
lint: {
Expand All @@ -331,19 +334,24 @@ export default async function (
},
},
test: {
executor: `${plugin}:test`,
executor: `${plugin}:run-task`,
options: {
task: 'test',
},
},
},
tags: normalizedOptions.parsedTags,
};

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,
task: 'jar',
};
}

Expand Down
72 changes: 50 additions & 22 deletions packages/maven/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,32 @@ export default async function (
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: `${plugin}:build`,
executor: `${plugin}:run-task`,
outputs: [`${normalizedOptions.projectRoot}/target`],
options: {
task: 'compile',
},
},
'build-image': {},
serve: {},
serve: {
executor: `${plugin}:run-task`,
options: {
task: 'exec:java',
keepItRunning: true,
},
dependsOn: ['build'],
},
lint: {
executor: `${plugin}:lint`,
options: {
linter: `${normalizedOptions.linter}`,
},
},
test: {
executor: `${plugin}:test`,
executor: `${plugin}:run-task`,
options: {
task: 'test',
},
dependsOn: ['build'],
},
ktformat: {},
Expand All @@ -425,41 +438,56 @@ export default async function (

const targets = projectConfiguration.targets ?? {};

if (options.framework === 'none') {
targets['serve'] = {
if (
plugin === '@jnxplus/nx-boot-maven' ||
options.framework === 'spring-boot'
) {
targets['build'].options = {
...targets['build'].options,
task: 'package spring-boot:repackage',
};

targets['build-image'] = {
executor: `${plugin}:run-task`,
options: {
task: 'exec:java',
task: 'spring-boot:build-image',
},
dependsOn: ['build'],
};

targets['serve'].options = {
...targets['serve'].options,
task: 'spring-boot:run',
};
}

if (options.framework !== 'none') {
if (
plugin === '@jnxplus/nx-quarkus-maven' ||
options.framework === 'quarkus'
) {
targets['build-image'] = {
executor: `${plugin}:build-image`,
executor: `${plugin}:quarkus-build-image`,
};

targets['serve'] = {
executor: `${plugin}:serve`,
dependsOn: ['build'],
targets['serve'].options = {
...targets['serve'].options,
task: 'quarkus:dev',
};
}

if (options.framework && options.framework !== 'none') {
targets['build'].options = {
...targets['build'].options,
framework: options.framework,
};

targets['build-image'].options = {
...targets['build-image'].options,
framework: options.framework,
if (
plugin === '@jnxplus/nx-micronaut-maven' ||
options.framework === 'micronaut'
) {
targets['build-image'] = {
executor: `${plugin}:run-task`,
options: {
task: 'package -Dpackaging=docker',
},
};

targets['serve'].options = {
...targets['serve'].options,
framework: options.framework,
task: 'mn:run',
};
}

Expand Down
17 changes: 8 additions & 9 deletions packages/maven/src/generators/library/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,11 @@ export default async function (
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: `${plugin}:build`,
executor: `${plugin}:run-task`,
outputs: [`${normalizedOptions.projectRoot}/target`],
options: {
command: 'install',
},
},
lint: {
executor: `${plugin}:lint`,
Expand All @@ -356,21 +359,17 @@ export default async function (
},
},
test: {
executor: `${plugin}:test`,
executor: `${plugin}:run-task`,
options: {
task: 'test',
},
},
},
tags: normalizedOptions.parsedTags,
};

const targets = projectConfiguration.targets ?? {};

if (options.framework && options.framework !== 'none') {
targets['build'].options = {
...targets['build'].options,
framework: options.framework,
};
}

if (options.language === 'kotlin') {
targets['ktformat'] = {
executor: `${plugin}:ktformat`,
Expand Down
5 changes: 4 additions & 1 deletion packages/maven/src/generators/parent-project/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export default async function (
projectType: normalizedOptions.projectType,
targets: {
build: {
executor: `${plugin}:build`,
executor: `${plugin}:run-task`,
options: {
task: 'install',
},
},
},
tags: normalizedOptions.parsedTags,
Expand Down
20 changes: 19 additions & 1 deletion packages/maven/src/lib/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ function addProjects(
projectType: projectGraphNodeType === 'app' ? 'application' : 'library',
targets: {
build: {
executor: `${pluginName}:build`,
executor: `${pluginName}:run-task`,
options: {
task: getTask(projectRoot, projectGraphNodeType),
},
},
'run-task': {
executor: `${pluginName}:run-task`,
Expand Down Expand Up @@ -208,3 +211,18 @@ function getDependencyProjects(
) {
return projects.filter((p) => project.dependencies.includes(p.artifactId));
}

function getTask(
projectRoot: string,
projectGraphNodeType: 'app' | 'e2e' | 'lib'
) {
if (!projectRoot) {
return 'install -N';
}

if (projectGraphNodeType === 'app') {
return 'compile';
}

return 'install';
}
Loading

0 comments on commit ea31aeb

Please sign in to comment.