Skip to content

Commit

Permalink
feat(nx-quarkus): add link generator to link projects implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Jun 21, 2022
1 parent 1142d04 commit 2655b4f
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 2 deletions.
38 changes: 37 additions & 1 deletion packages/nx-quarkus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ npm install @nxrocks/nx-quarkus --save-dev
yarn add @nxrocks/nx-quarkus --dev
```

### Generating Project
### Generating Project (`new` generator)

Simply run the `project` generator with the following command:

Expand Down Expand Up @@ -93,6 +93,42 @@ Option | Value | Description
`tags` | `string` | Tags to use for linting (comma-separated)
`directory` | `string` | Directory where the project is placed

### Linking Projects (`link` generator)

This generator is used to link a Quarkus project inside the workspace (the *source* project) with another project (the _*target* project), by adding the source project as an **implicit dependency** of the later.

Simply run the `link` generator with the following command:

```
nx g @nxrocks/nx-spring-boot:link
```

> you can also use the following aliases to call the generator: `link-project`
You will be prompted for entering the most commonly customized generation options (`sourceProjectName`, `targetProjectName`).

To skip the interactive prompt, you can pass options along directly when running the command, as such:

```
nx g @nxrocks/nx-spring-boot:link --sourceProjectName <your-quarkus-app> --targetProjectName <your-other-app>
```

or even simpler:

```
nx g @nxrocks/nx-spring-boot:link <your-quarkus-app> <your-other-app>
```


#### Generation Options

Here the list of available generation options :

| Arguments | Description |
| --------- | ------------------------ |
| `<sourceProjectName>` | The name of the source(Spring-Boot) project to link from. 1st argument of the `link` generator. Can also be provided as option `--sourceProjectName`|
| `<targetProjectName>` | The name of the target project to link to. 2nd argument of the `link` generator. Can also be provided as option `--targetProjectName`|

## Plugin Usage

Once your app is generated, you can now use buidlers to manage it.
Expand Down
14 changes: 13 additions & 1 deletion packages/nx-quarkus/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
"factory": "./src/generators/project/generator",
"schema": "./src/generators/project/schema.json",
"description": "Generator to generate an application or a library",
"aliases": [ "proj", "new", "gen", "init", "create", "generate"]
"aliases": [
"proj",
"new",
"gen",
"init",
"create",
"generate"
]
},
"link": {
"factory": "./src/generators/link/generator",
"schema": "./src/generators/link/schema.json",
"description": "Generator to add an implicit dependency between a source (Quarkus) project in the workspace and another project"
}
}
}
30 changes: 30 additions & 0 deletions packages/nx-quarkus/src/generators/link/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Tree, readProjectConfiguration, addProjectConfiguration } from '@nrwl/devkit';

import generator from './generator';
import { LinkGeneratorSchema } from './schema';

describe('link generator', () => {
let tree: Tree;
const options: LinkGeneratorSchema = { sourceProjectName: 'quarkusapp', targetProjectName: 'ngapp' };

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
addProjectConfiguration(tree, options.sourceProjectName, {
projectType: 'application',
sourceRoot: `apps/${options.sourceProjectName}/src`,
root: `apps/${options.sourceProjectName}`,
});
addProjectConfiguration(tree, options.targetProjectName, {
projectType: 'application',
sourceRoot: `apps/${options.targetProjectName}/src`,
root: `apps/${options.targetProjectName}`,
});
});

it('should run successfully', async () => {
await generator(tree, options);
const targetProject = readProjectConfiguration(tree, options.targetProjectName);
expect(targetProject.implicitDependencies).toEqual([options.sourceProjectName]);
})
});
22 changes: 22 additions & 0 deletions packages/nx-quarkus/src/generators/link/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { LinkGeneratorSchema } from './schema';


export default async function (tree: Tree, options: LinkGeneratorSchema) {

readProjectConfiguration(tree, options.sourceProjectName);
const targetProject = readProjectConfiguration(tree, options.targetProjectName);

const targetProjectImplicitDependencies = targetProject.implicitDependencies || [];

if(!targetProjectImplicitDependencies.includes(options.sourceProjectName)) {
targetProjectImplicitDependencies.push(options.sourceProjectName);
targetProject.implicitDependencies = targetProjectImplicitDependencies;
updateProjectConfiguration(tree, options.targetProjectName, targetProject);
}

}
4 changes: 4 additions & 0 deletions packages/nx-quarkus/src/generators/link/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LinkGeneratorSchema {
sourceProjectName: string;
targetProjectName: string;
}
28 changes: 28 additions & 0 deletions packages/nx-quarkus/src/generators/link/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Link",
"title": "",
"type": "object",
"properties": {
"sourceProjectName": {
"type": "string",
"description": "The name of the source(Quarkus) project to link from ",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name of the source (Quarkus) project to link from?"
},
"targetProjectName": {
"type": "string",
"description": "The name of the target project to link to ",
"$default": {
"$source": "argv",
"index": 1
},
"x-prompt": "What name of the target project to link to?"
}
},
"required": ["sourceProjectName", "targetProjectName"]
}

0 comments on commit 2655b4f

Please sign in to comment.