Skip to content

Commit

Permalink
feat(nx-spring-boot): rename the application generator into project
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the `app` alias has been replaced with one of [`proj`, `new`, `gen`, `init`, `create`, `generate`].
  • Loading branch information
tinesoft committed Apr 1, 2021
1 parent 530186c commit 05b5272
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 45 deletions.
12 changes: 6 additions & 6 deletions e2e/nx-spring-boot-e2e/tests/nx-spring-boot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('nx-spring-boot e2e', () => {
const prjName = uniq('nx-spring-boot');
ensureNxProject('@nxrocks/nx-spring-boot', 'dist/packages/nx-spring-boot');
await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:application ${prjName}`
`generate @nxrocks/nx-spring-boot:new ${prjName}`
);

const resultBuildInfo= await runNxCommandAsync(`buildInfo ${prjName}`);
Expand All @@ -38,7 +38,7 @@ describe('nx-spring-boot e2e', () => {

ensureNxProject('@nxrocks/nx-spring-boot', 'dist/packages/nx-spring-boot');
await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:application ${prjName} --projectType application --buildSystem=${buildSystem} --packageName=${packageName} --groupId=${groupId} --artifactId=${artifactId} --description="${description}" --version=${version}`// --javaVersion="${javaVersion}"`
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType application --buildSystem=${buildSystem} --packageName=${packageName} --groupId=${groupId} --artifactId=${artifactId} --description="${description}" --version=${version}`// --javaVersion="${javaVersion}"`
);

const resultBuildInfo= await runNxCommandAsync(`buildInfo ${prjName}`);
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('nx-spring-boot e2e', () => {
'dist/packages/nx-spring-boot'
);
await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:application ${prjName} --projectType application --buildSystem gradle-project`
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType application --buildSystem gradle-project`
);

const resultBuildInfo= await runNxCommandAsync(`buildInfo ${prjName}`);
Expand All @@ -92,7 +92,7 @@ describe('nx-spring-boot e2e', () => {
'dist/packages/nx-spring-boot'
);
await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:application ${prjName} --projectType application --buildSystem gradle-project --language kotlin`
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType application --buildSystem gradle-project --language kotlin`
);

const resultBuildInfo= await runNxCommandAsync(`buildInfo ${prjName}`);
Expand All @@ -114,7 +114,7 @@ describe('nx-spring-boot e2e', () => {
'dist/packages/nx-spring-boot'
);
await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:application ${prjName} --projectType application --directory subdir`
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType application --directory subdir`
);
expect(() =>
checkFilesExist(`apps/subdir/${prjName}/mvnw`,`apps/subdir/${prjName}/pom.xml`, `apps/subdir/${prjName}/HELP.md`)
Expand All @@ -131,7 +131,7 @@ describe('nx-spring-boot e2e', () => {
'dist/packages/nx-spring-boot'
);
await runNxCommandAsync(
`generate @nxrocks/nx-spring-boot:application ${prjName} --projectType application --tags e2etag,e2ePackage`
`generate @nxrocks/nx-spring-boot:new ${prjName} --projectType application --tags e2etag,e2ePackage`
);
const nxJson = readJson('nx.json');
expect(nxJson.projects[prjName].tags).toEqual(['e2etag', 'e2ePackage']);
Expand Down
43 changes: 23 additions & 20 deletions packages/nx-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,36 @@ npm install @nxrocks/nx-spring-boot --save-dev
yarn add @nxrocks/nx-spring-boot --dev
```

### Generating Application
### Generating Project

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

```
nx g @nxrocks/nx-spring-boot:app <your-app-name>
nx g @nxrocks/nx-spring-boot:new <your-app-name>
```

You will be prompted for entering the most commonly customized generation options (like application's `groupId`, `artifactId`, `packaging`, `dependencies`, etc).
> you can also use the following aliases to call the generator: `proj`, `new`, `gen`, `init`, `create`, or `generate`
You will be prompted for entering the most commonly customized generation options (like project's `groupId`, `artifactId`, `packaging`, `dependencies`, etc).

To skip the interactive prompt, or if you want to customize all non-prompted options, you can pass them along directly when running the command, as such:

```
nx g @nxrocks/nx-spring-boot:app <your-app-name> --optionName1 optionValue1 ... --optionNameN optionValueN
nx g @nxrocks/nx-spring-boot:project <your-app-name> --optionName1 optionValue1 ... --optionNameN optionValueN
```

#### Generation Options

Here the list of available generation options :

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |
| Arguments | Description |
| --------- | ------------------------ |
| `<name>` | The name of your project.|

Option | Value | Description
---------------------- | ----- | ------------
`type` | `maven-project` \| `gradle-project` | Type of project to generate
`projectType` | `application` \| `library` | Type of project to generate
`buildSystem` | `maven-project` \| `gradle-project` | Build system
`packaging` | `jar` \| `war` | Packaging to use
`javaVersion` | `8` \| `11` \| `15`| Java version to use
`language` | `java` \| `groovy` \| `kotlin` | Language to use
Expand All @@ -88,19 +91,19 @@ Here the list of available builders:

| Builder | Arguments | Description |
| --------------- | ------------------------------------------ | ------------------------------------------ |
| `run` \| `serve`| `ignoreWrapper:boolean`, `args: string[]` | Runs the application using either `./mvnw\|mvn spring-boot:run` or `./gradlew\|gradle bootRun` |
| `test` | `ignoreWrapper:boolean`, `args: string[]` | Tests the application using either `./mvnw\|mvn test` or `./gradlew\|gradle test` |
| `test` | `ignoreWrapper:boolean`, `args: string[]` | Cleans the application using either `./mvnw\|mvn clean` or `./gradlew\|gradle clean` |
| `buidlJar` | `ignoreWrapper:boolean`, `args: string[]` | Packages the application into an executable Jar using either `./mvnw\|mvn spring-boot:repackage` or `./gradlew\|gradle bootJar` |
| `buildWar` | `ignoreWrapper:boolean`, `args: string[]` | Packages the application into an executable War using either `./mvnw\|mvn spring-boot:repackage` or `./gradlew\|gradle bootWar` |
| `run` \| `serve`| `ignoreWrapper:boolean`, `args: string[]` | Runs the project using either `./mvnw\|mvn spring-boot:run` or `./gradlew\|gradle bootRun` |
| `test` | `ignoreWrapper:boolean`, `args: string[]` | Tests the project using either `./mvnw\|mvn test` or `./gradlew\|gradle test` |
| `test` | `ignoreWrapper:boolean`, `args: string[]` | Cleans the project using either `./mvnw\|mvn clean` or `./gradlew\|gradle clean` |
| `buidlJar` | `ignoreWrapper:boolean`, `args: string[]` | Packages the project into an executable Jar using either `./mvnw\|mvn spring-boot:repackage` or `./gradlew\|gradle bootJar` |
| `buildWar` | `ignoreWrapper:boolean`, `args: string[]` | Packages the project into an executable War using either `./mvnw\|mvn spring-boot:repackage` or `./gradlew\|gradle bootWar` |
| `buildInfo` | `ignoreWrapper:boolean`, | Generates a `build-info.properties` using either `./mvnw\|mvn spring-boot:build-info` or `./gradlew\|gradle bootBuildInfo` |
| `buildImage` | `ignoreWrapper:boolean`, `args: string[]` | Generates an [OCI Image](https://github.com/opencontainers/image-spec) using either `./mvnw\|mvn spring-boot:build-image` or `./gradlew\|gradle bootBuildImage` |

In order to execute the requested command, each builder will use, by default, the embedded `./mvnw` or `./gradlew` executable, that was generated alongside the application.
In order to execute the requested command, each builder will use, by default, the embedded `./mvnw` or `./gradlew` executable, that was generated alongside the project.
If you want to rely on a globally installed `mvn` or `gradle` executable instead, add the `--ignoreWrapper` option to bypass it.
This can be useful in a CI environment for example, or in a restricted environment where the binary cannot be downloaded (due to proxy/firewall limitations).

### Running the application - ('run' or 'serve' Builders)
### Running the project - ('run' or 'serve' Builders)

```
nx run your-boot-app:run
Expand Down Expand Up @@ -177,13 +180,13 @@ You can pass in additional arguments by editing the related section in the `work
}
```

### Testing the application - ('test' Builder)
### Testing the project - ('test' Builder)

```
nx test your-boot-app
```

### Cleaning the application - ('clean' Builder)
### Cleaning the project - ('clean' Builder)

```
nx clean your-boot-app
Expand All @@ -193,8 +196,8 @@ nx clean your-boot-app

Every Nx plugin relies on the underlying Nx Workspace it runs on. This table provides the compatibility matrix between major versions of Nx workspace and this plugin/

| Plugin Version | Nx Workspace version
| -------------- | ---------------------
| Plugin Version | Nx Workspace version
| -------------- | --------------------
| `>=v2.x.x` | `>=v11.x.x`
| `<=v1.3.1` | `<=v10.x.x`
## License
Expand Down
10 changes: 5 additions & 5 deletions packages/nx-spring-boot/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "nx-spring-boot",
"version": "0.0.1",
"generators": {
"application": {
"factory": "./src/generators/application/generator",
"schema": "./src/generators/application/schema.json",
"description": "Generator to generate the application",
"aliases": ["app"]
"project": {
"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"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { appRootPath } from '@nrwl/workspace/src/utils/app-root';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import each from 'jest-each';

import { applicationGenerator } from './generator';
import { ApplicationGeneratorOptions } from './schema';
import { projectGenerator } from './generator';
import { ProjectGeneratorOptions } from './schema';

import { Readable } from 'stream';

Expand All @@ -18,9 +18,9 @@ const { Response } = jest.requireActual('node-fetch');
jest.mock('fs');
import * as fs from 'fs';

describe('application generator', () => {
describe('project generator', () => {
let tree: Tree;
const options: ApplicationGeneratorOptions = {
const options: ProjectGeneratorOptions = {
name: 'bootapp',
projectType: 'application',
springInitializerUrl: 'https://start.spring.io'
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('application generator', () => {

tree.write(`/${rootDir}/${options.name}/${buildFile}`, '');

await applicationGenerator(tree, { ...options, projectType, buildSystem});
await projectGenerator(tree, { ...options, projectType, buildSystem});

expect(mockedFetch).toHaveBeenCalledWith(
`${options.springInitializerUrl}/starter.zip?type=${buildSystem}&name=${options.name}`,
Expand All @@ -79,7 +79,7 @@ describe('application generator', () => {
});

it('should update workspace.json', async () => {
await applicationGenerator(tree, options);
await projectGenerator(tree, options);
const project = readProjectConfiguration(tree, options.name);
expect(project.root).toBe(`apps/${options.name}`);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Tree, addProjectConfiguration, } from '@nrwl/devkit';
import { ApplicationGeneratorOptions } from './schema';
import { ProjectGeneratorOptions } from './schema';
import { normalizeOptions, generateBootProject, restoreExecutePermission, addBuilInfoTask } from './lib';


export async function applicationGenerator(tree: Tree, options: ApplicationGeneratorOptions) {
export async function projectGenerator(tree: Tree, options: ProjectGeneratorOptions) {
const normalizedOptions = normalizeOptions(tree,options);

const targets = {};
Expand All @@ -30,4 +30,4 @@ export async function applicationGenerator(tree: Tree, options: ApplicationGener

}

export default applicationGenerator;
export default projectGenerator;
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
names,
getWorkspaceLayout,
} from '@nrwl/devkit';
import { ApplicationGeneratorOptions, NormalizedSchema } from '../schema';
import { ProjectGeneratorOptions, NormalizedSchema } from '../schema';



export function normalizeOptions(tree:Tree,
options: ApplicationGeneratorOptions
options: ProjectGeneratorOptions
): NormalizedSchema {
const { appsDir, libsDir } = getWorkspaceLayout(tree);
const projectRootDir = options.projectType === 'application' ? appsDir : libsDir;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ApplicationGeneratorOptions {
export interface ProjectGeneratorOptions {
name: string;
projectType: 'application' | 'library';
tags?: string;
Expand All @@ -19,7 +19,7 @@ export interface ApplicationGeneratorOptions {
version?: string;
}

export interface NormalizedSchema extends ApplicationGeneratorOptions {
export interface NormalizedSchema extends ProjectGeneratorOptions {
projectName: string;
projectRoot: string;
projectDirectory: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-spring-boot/src/utils/boot-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { execSync } from 'child_process'
import { BuildCommandAliasType, BuildCore } from '../core/build-core.class';
import { GradleBuild } from '../core/gradle-build.class';
import { MavenBuild } from '../core/maven-build.class';
import { NormalizedSchema } from '../generators/application/schema';
import { NormalizedSchema } from '../generators/project/schema';


export function determineBuildSystem(cwd: string): BuildCore {
Expand Down

0 comments on commit 05b5272

Please sign in to comment.