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(plugins): add nx-micronaut-gradle plugin #241

Merged
merged 34 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f30fbe4
feat: add new plugin
khalilou88 May 29, 2023
c81c5da
fix: fix plugin name [skip ci]
khalilou88 May 29, 2023
c0bf3f7
fix: fix plugin tests [skip ci]
khalilou88 May 29, 2023
0b3da06
fix: fix plugin tests [skip ci]
khalilou88 May 29, 2023
2bc4e22
build: work in progress [skip ci]
khalilou88 May 29, 2023
c105ab9
build: work in progress [skip ci]
khalilou88 May 29, 2023
01f897f
build: work in progress [skip ci]
khalilou88 May 29, 2023
809f0fc
build: work in progress [skip ci]
khalilou88 May 29, 2023
37f7781
build: work in progress [skip ci]
khalilou88 May 29, 2023
a691f13
build: work in progress [skip ci]
khalilou88 May 29, 2023
b1951f2
build: work in progress [skip ci]
khalilou88 May 29, 2023
88c2272
build: work in progress [skip ci]
khalilou88 May 29, 2023
8124909
build: work in progress [skip ci]
khalilou88 May 29, 2023
8f71ae3
build: work in progress [skip ci]
khalilou88 May 29, 2023
e3e86b7
build: work in progress [skip ci]
khalilou88 May 29, 2023
4c41548
build: work in progress [skip ci]
khalilou88 May 29, 2023
753ad54
build: work in progress [skip ci]
khalilou88 May 29, 2023
ceb9b6c
build: work in progress [skip ci]
khalilou88 May 29, 2023
3cb95ef
build: work in progress [skip ci]
khalilou88 May 29, 2023
94d28cf
build: work in progress [skip ci]
khalilou88 May 29, 2023
84f9a59
build: work in progress [skip ci]
khalilou88 May 29, 2023
bee117b
build: work in progress [skip ci]
khalilou88 May 30, 2023
33a511c
build: work in progress [skip ci]
khalilou88 May 30, 2023
b48d223
build: work in progress [skip ci]
khalilou88 May 31, 2023
e0069be
build: work in progress [skip ci]
khalilou88 May 31, 2023
b7481ea
build: work in progress [skip ci]
khalilou88 May 31, 2023
de15a38
build: work in progress [skip ci]
khalilou88 May 31, 2023
fd70e48
build: work in progress [skip ci]
khalilou88 May 31, 2023
9b692f5
build: work in progress [skip ci]
khalilou88 May 31, 2023
3fb36c5
build: work in progress [skip ci]
khalilou88 May 31, 2023
f72009d
build: work in progress [skip ci]
khalilou88 May 31, 2023
679ce40
build: work in progress [skip ci]
khalilou88 May 31, 2023
898224e
build: work in progress [skip ci]
khalilou88 May 31, 2023
9ab6626
build: work in progress [skip ci]
khalilou88 May 31, 2023
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
1 change: 1 addition & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
2,
"always",
[
"plugins",
"generators",
"executors",
"graph",
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/check-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Unit tests
run: npm run test nx-${{ github.event.inputs.framework }}-${{ github.event.inputs.buildTool }}

- name: Build
run: npm run build nx-${{ github.event.inputs.framework }}-${{ github.event.inputs.buildTool }}

- name: E2E tests
run: npm run e2e nx-${{ github.event.inputs.framework }}-${{ github.event.inputs.buildTool }}-e2e
env:
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/lib/versions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const springKotlinVersion = '1.8.21';
export const quarkusPlatformVersion = '3.0.4.Final';
export const quarkusKotlinVersion = '1.8.10';

//Micronaut
export const micronautVersion = '4.0.0-M2';
export const micronautKotlinVersion = '1.8.20';

//Linters
export const checkstyleVersion = '10.11.0';
export const ktlintVersion = '0.49.1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ExecutorContext } from '@nx/devkit';
import { runCommand } from '@jnxplus/common';
import executor from './executor';
import { BuildImageExecutorSchema } from './schema';
jest.mock('@jnxplus/common');

const options: BuildImageExecutorSchema = {
useDocker: true,
native: true,
optimized: true,
};
const context: ExecutorContext = {
root: '/root',
cwd: '/root',
projectName: 'my-app',
targetName: 'build',
workspace: {
version: 2,
projects: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'my-app': <any>{
root: 'apps/wibble',
sourceRoot: 'apps/wibble',
},
},
npmScope: 'test',
},
isVerbose: false,
};

describe('Build Image Executor', () => {
beforeEach(async () => {
(runCommand as jest.Mock).mockReturnValue({ success: true });
});

xit('can run', async () => {
const output = await executor(options, context);
expect(output.success).toBe(true);
});
});
43 changes: 43 additions & 0 deletions packages/gradle/src/executors/build-image/micronaut/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ExecutorContext, logger } from '@nx/devkit';
import { getExecutable, getProjectPath } from '../../../.';
import { runCommand } from '@jnxplus/common';
import { BuildImageExecutorSchema } from './schema';

export default async function runExecutor(
options: BuildImageExecutorSchema,
context: ExecutorContext
) {
logger.info(`Executor ran for Build Image: ${JSON.stringify(options)}`);

if (options.useDocker && options.native && options.optimized) {
return runCommand(
`${getExecutable()} ${getProjectPath(context)}:optimizedDockerBuildNative`
);
}

if (options.useDocker && !options.native && options.optimized) {
return runCommand(
`${getExecutable()} ${getProjectPath(context)}:optimizedDockerBuild`
);
}

if (options.useDocker && options.native && !options.optimized) {
return runCommand(
`${getExecutable()} ${getProjectPath(context)}:dockerBuildNative`
);
}

if (options.useDocker && !options.native && !options.optimized) {
return runCommand(
`${getExecutable()} ${getProjectPath(context)}:dockerBuild`
);
}

if (!options.useDocker) {
return runCommand(
`${getExecutable()} ${getProjectPath(context)}:nativeCompile`
);
}

throw new Error(`Case not handled`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface BuildImageExecutorSchema {
useDocker: boolean;
native: boolean;
optimized: boolean;
}
20 changes: 20 additions & 0 deletions packages/gradle/src/executors/build-image/micronaut/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 2,
"outputCapture": "pipe",
"$schema": "http://json-schema.org/schema",
"title": "Build Image executor",
"description": "",
"type": "object",
"properties": {
"useDocker": {
"type": "boolean"
},
"native": {
"type": "boolean"
},
"optimized": {
"type": "boolean"
}
},
"required": []
}
46 changes: 46 additions & 0 deletions packages/gradle/src/executors/build/micronaut/executor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ExecutorContext } from '@nx/devkit';
import { runCommand } from '@jnxplus/common';
import executor from './executor';
import { BuildExecutorSchema } from './schema';
jest.mock('@jnxplus/common');

const options: BuildExecutorSchema = {};
const context: ExecutorContext = {
root: '/root',
cwd: '/root',
projectName: 'my-app',
targetName: 'build',
workspace: {
version: 2,
projects: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'my-app': <any>{
root: 'apps/wibble',
sourceRoot: 'apps/wibble',
},
},
npmScope: 'test',
},
projectsConfigurations: {
version: 2,
projects: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'my-app': <any>{
root: 'apps/wibble',
sourceRoot: 'apps/wibble',
},
},
},
isVerbose: false,
};

describe('Build Executor', () => {
beforeEach(async () => {
(runCommand as jest.Mock).mockReturnValue({ success: true });
});

xit('can run', async () => {
const output = await executor(options, context);
expect(output.success).toBe(true);
});
});
14 changes: 14 additions & 0 deletions packages/gradle/src/executors/build/micronaut/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { runCommand } from '@jnxplus/common';
import { ExecutorContext, logger } from '@nx/devkit';
import { getExecutable, getProjectPath } from '../../../.';
import { BuildExecutorSchema } from './schema';

export default async function runExecutor(
options: BuildExecutorSchema,
context: ExecutorContext
) {
logger.info(`Executor ran for Build: ${JSON.stringify(options)}`);
return runCommand(
`${getExecutable()} ${getProjectPath(context)}:build -x test`
);
}
1 change: 1 addition & 0 deletions packages/gradle/src/executors/build/micronaut/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface BuildExecutorSchema {} // eslint-disable-line
10 changes: 10 additions & 0 deletions packages/gradle/src/executors/build/micronaut/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 2,
"outputCapture": "pipe",
"$schema": "http://json-schema.org/schema",
"title": "Build executor",
"description": "",
"type": "object",
"properties": {},
"required": []
}
38 changes: 38 additions & 0 deletions packages/gradle/src/executors/serve/micronaut/executor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ExecutorContext } from '@nx/devkit';
import { runCommand } from '@jnxplus/common';
import executor from './executor';
import { ServeExecutorSchema } from './schema';
jest.mock('@jnxplus/common');

const options: ServeExecutorSchema = {
args: 'args',
};
const context: ExecutorContext = {
root: '/root',
cwd: '/root',
projectName: 'my-app',
targetName: 'serve',
workspace: {
version: 2,
projects: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'my-app': <any>{
root: 'apps/wibble',
sourceRoot: 'apps/wibble',
},
},
npmScope: 'test',
},
isVerbose: false,
};

describe('Serve Executor', () => {
beforeEach(async () => {
(runCommand as jest.Mock).mockReturnValue({ success: true });
});

xit('can run', async () => {
const output = await executor(options, context);
expect(output.success).toBe(true);
});
});
27 changes: 27 additions & 0 deletions packages/gradle/src/executors/serve/micronaut/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { runCommand, waitForever } from '@jnxplus/common';
import { ExecutorContext, logger } from '@nx/devkit';

import { getExecutable, getProjectPath } from '../../../.';
import { ServeExecutorSchema } from './schema';

export default async function runExecutor(
options: ServeExecutorSchema,
context: ExecutorContext
) {
logger.info(`Executor ran for serve: ${JSON.stringify(options)}`);

let command = `${getExecutable()} ${getProjectPath(context)}:run`;

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

const result = runCommand(command);

if (!result.success) {
return { success: false };
}

await waitForever();
return { success: true };
}
3 changes: 3 additions & 0 deletions packages/gradle/src/executors/serve/micronaut/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ServeExecutorSchema {
args: string;
}
14 changes: 14 additions & 0 deletions packages/gradle/src/executors/serve/micronaut/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 2,
"outputCapture": "pipe",
"$schema": "http://json-schema.org/schema",
"title": "Serve executor",
"description": "",
"type": "object",
"properties": {
"args": {
"type": "string"
}
},
"required": []
}
10 changes: 10 additions & 0 deletions packages/nx-micronaut-gradle/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nx/js/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions packages/nx-micronaut-gradle/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Empty file.
55 changes: 55 additions & 0 deletions packages/nx-micronaut-gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# @jnxplus/nx-micronaut-gradle

[![npm version](https://badge.fury.io/js/@jnxplus%2Fnx-micronaut-gradle.svg)](https://badge.fury.io/js/@jnxplus%2Fnx-micronaut-gradle)

This plugin adds Spring micronaut and Gradle multi-project builds capabilities to Nx workspace.

Here is a quick overview of the plugin, to know more, please visit [the documentation](https://khalilou88.github.io/jnxplus/).

## Supported versions

| @jnxplus/nx-micronaut-gradle | Nx | Spring micronaut |
| ---------------------------- | ------ | ---------------- |
| 6.x.x | 16.x.x | 3.x.x |
| 5.x.x | 15.x.x | 3.x.x |

## Getting Started

### 0. Prerequisites

`@jnxplus/nx-micronaut-gradle` requires a Java 17 or higher Runtime Environment and the current Long Term Support (LTS) version of node.js.

### 1. Install the plugin

In the Nx workspace root folder, run this command to install the plugin :

```bash
npm install --save-dev @jnxplus/nx-micronaut-gradle
```

### 2. Add Spring micronaut and Gradle wrapper support

The following command adds Spring micronaut and Gradle support (Gradle wrapper and config files) to the workspace. This only needs to be performed once per workspace.

```bash
nx generate @jnxplus/nx-micronaut-gradle:init
```

### 3. Usage

| Action | Command |
| ------------------------------------ | ------------------------------------------------------------------ |
| Generate an application | `nx generate @jnxplus/nx-micronaut-gradle:application my-app-name` |
| Generate a library | `nx generate @jnxplus/nx-micronaut-gradle:library my-lib-name` |
| Build a project | `nx build my-project-name` |
| Serve an application | `nx serve my-app-name` |
| Test a project | `nx test my-project-name` |
| Lint a project | `nx lint my-project-name` |
| Format a java project | `nx format --projects my-project-name` |
| Format a kotlin project | `nx ktformat my-project-name` |
| Run a custom task | `nx run-task my-project-name --task="test"` |
| Visualize project's dependency graph | `nx dep-graph` |

## License

MIT © 2021-2023 Khalil LAGRIDA
Loading