Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(executors): use run-task instead of others executors #344

Merged
merged 6 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecutorContext, workspaceRoot } from '@nx/devkit';
import { ExecutorContext, logger, workspaceRoot } from '@nx/devkit';
import { join } from 'path';
import { getProjectRoot, runCommand } from '../../../.';
import { QuarkusBuildImageExecutorSchema } from './schema';
Expand All @@ -7,6 +7,8 @@ export default async function runExecutor(
options: QuarkusBuildImageExecutorSchema,
context: ExecutorContext
) {
logger.info(`Executor ran for Build Image: ${JSON.stringify(options)}`);

let imageNameSuffix = '';

if (options.imageNameSuffix) {
Expand Down
25 changes: 25 additions & 0 deletions packages/common/src/executors/build-image/quarkus/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 2,
"outputCapture": "pipe",
"$schema": "http://json-schema.org/schema",
"title": "Build Image executor",
"description": "",
"type": "object",
"properties": {
"imageType": {
"type": "string",
"description": "Image type to build",
"default": "jvm"
},
"imageNamePrefix": {
"type": "string",
"description": "Image name prefix",
"default": "quarkus"
},
"imageNameSuffix": {
"type": "string",
"description": "Image name suffix"
}
},
"required": []
}
17 changes: 17 additions & 0 deletions packages/common/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,20 @@ export function getProjectGraphNodeType(
export function getPluginName(context: ExecutorContext) {
return context.target?.executor?.split(':')[0];
}

function titleCase(str: string) {
return str
.toLowerCase()
.split(' ')
.map(function (word) {
return word.replace(word[0], word[0].toUpperCase());
})
.join(' ');
}

export function getTargetName(context: ExecutorContext) {
if (!context.targetName) {
throw new Error('targetName must set');
}
return titleCase(context.targetName.replace(/-/g, ' '));
}
5 changes: 3 additions & 2 deletions packages/gradle/src/executors/run-task/executor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ExecutorContext, logger } from '@nx/devkit';
import { getExecutable, getProjectPath } from '../../../.';
import { RunTaskExecutorSchema } from './schema';
import { runCommand, waitForever } from '@jnxplus/common';
import { getTargetName, runCommand, waitForever } from '@jnxplus/common';

export default async function runExecutor(
options: RunTaskExecutorSchema,
context: ExecutorContext
) {
logger.info(`Executor ran for Run Task: ${JSON.stringify(options)}`);
const targetName = getTargetName(context);
logger.info(`Executor ran for ${targetName}: ${JSON.stringify(options)}`);

let projectPath = '';
if (options.projectPath) {
Expand Down
69 changes: 47 additions & 22 deletions packages/gradle/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,30 @@ 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',
},
},
lint: {
executor: `${plugin}:lint`,
options: {
linter: `${normalizedOptions.linter}`,
},
},
test: {
executor: `${plugin}:test`,
executor: `${plugin}:run-task`,
options: {
task: 'test',
},
},
ktformat: {},
},
Expand All @@ -416,43 +427,57 @@ 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'] = {
targets['serve'].options = {
...targets['serve'].options,
task: 'bootRun',
keepItRunning: true,
};

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

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

targets['serve'] = {
executor: `${plugin}:serve`,
targets['serve'].options = {
...targets['serve'].options,
task: 'quarkusDev',
keepItRunning: true,
};
}

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

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

targets['serve'].options = {
...targets['serve'].options,
framework: options.framework,
keepItRunning: true,
};
}

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: {
task: '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
5 changes: 3 additions & 2 deletions packages/maven/src/executors/run-task/executor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ExecutorContext, logger } from '@nx/devkit';
import { runCommand, waitForever } from '@jnxplus/common';
import { getTargetName, runCommand, waitForever } from '@jnxplus/common';
import { RunTaskExecutorSchema } from './schema';
import { getExecutable } from '../../lib/utils';

export default async function runExecutor(
options: RunTaskExecutorSchema,
context: ExecutorContext
) {
logger.info(`Executor ran for Run Task: ${JSON.stringify(options)}`);
const targetName = getTargetName(context);
logger.info(`Executor ran for ${targetName}: ${JSON.stringify(options)}`);

const command = `${getExecutable()} ${options.task} -pl :${
context.projectName
Expand Down
74 changes: 52 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,31 @@ export default async function (
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: `${plugin}:build`,
executor: `${plugin}:run-task`,
outputs: [`${normalizedOptions.projectRoot}/target`],
options: {
task: 'compile -DskipTests=true',
},
},
'build-image': {},
serve: {},
serve: {
executor: `${plugin}:run-task`,
options: {
task: 'exec:java',
},
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 +437,59 @@ 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 -DskipTests=true',
};

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',
keepItRunning: true,
};
}

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',
keepItRunning: true,
};
}

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',
keepItRunning: true,
};
}

Expand Down
Loading