Skip to content

Commit

Permalink
Merge pull request #6810 from murdos/prettier3
Browse files Browse the repository at this point in the history
Upgrade to prettier 3
  • Loading branch information
pascalgrimaud authored Jul 14, 2023
2 parents 6d808a9 + a956c8c commit c266314
Show file tree
Hide file tree
Showing 39 changed files with 222 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ updates:
labels:
- 'area: dependencies'
ignore:
- dependency-name: "node"
versions: ["15.x", "17.x", "19.x", "20.x"]
- dependency-name: 'node'
versions: ['15.x', '17.x', '19.x', '20.x']
- package-ecosystem: 'npm'
directory: '/src/main/resources/generator/dependencies/vue'
schedule:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-image-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
workflow_dispatch:
push:
# Avoid building on main branch - see https://github.com/jhipster/jhipster-lite/issues/5341
# branches:
# - main
# branches:
# - main
# Publish semver tags as releases.
tags:
- 'v*.*.*'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
- name: initial labeling
uses: andymckay/labeler@master
with:
add-labels: "area: triage"
add-labels: 'area: triage'
ignore-if-labeled: true
5 changes: 2 additions & 3 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
'{src/test/javascript,src/main/webapp}/**/*.{js,ts,tsx,vue}': ['eslint --fix'],
'src/main/style/**/*.{css,scss}': ['stylelint --fix'],
'src/main/style/**/*.pug': ['pug-lint'],
'{{src/**/,}*.{md,json,yml,html,vue,java,xml},*.{js,ts},src/{main/webapp,main/glyph,test/javascript}/**/*.{css,scss}}': [
'prettier --write',
],
'{{src/**/,}*.{md,json,yml,html,vue,java,xml},*.{js,ts},.github/**/*.yml,documentation/**/*.md,src/{main/webapp,main/glyph,test/javascript}/**/*.{css,scss}}':
['prettier --write'],
};
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ singleQuote: true
tabWidth: 2
useTabs: false

plugins:
- '@prettier/plugin-xml'
- prettier-plugin-java

# js and ts rules:
arrowParens: avoid

Expand Down
61 changes: 32 additions & 29 deletions documentation/module-creation.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Creating a JHLite module

So you want to create a JHLite module? Great!
So you want to create a JHLite module? Great!

For that you'll need to provide 2 main parts:

* `JHipsterModuleResource`: describe the module organization, it is used to generate the APIs;
* `JHipsterModule`: describe the changes done by the module.
- `JHipsterModuleResource`: describe the module organization, it is used to generate the APIs;
- `JHipsterModule`: describe the changes done by the module.

You can start by the element you prefer but to create a `JHipsterModuleResource` you'll need to be able to build a `JHipsterModule`.

## Creating a JHipsterModule

In fact, you don't just need to create one `JHipsterModule`, you'll need a factory able to create them since each instance depends on the properties chosen by the users.

So, as this is the business of JHLite you probably want to create a `tech.jhipster.lite.generator.my_module.domain` package. And you can start with a simple test:
So, as this is the business of JHLite you probably want to create a `tech.jhipster.lite.generator.my_module.domain` package. And you can start with a simple test:

```java
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
Expand All @@ -27,6 +27,7 @@ import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@UnitTest
class MyModuleFactoryTest {

private static final MyModuleFactory factory = new MyModuleFactory();

@Test
Expand All @@ -38,19 +39,19 @@ class MyModuleFactoryTest {

JHipsterModule module = factory.buildModule(properties);

assertThatModule(module)
.hasPrefixedFiles("src/main/java/com/jhipster/test/my_package", "Dummy.java");
assertThatModule(module).hasPrefixedFiles("src/main/java/com/jhipster/test/my_package", "Dummy.java");
}
}

```

A few things to note here:
A few things to note here:

* We are expecting to have a `buildModule(...)` method in `MyModuleFactory`;
* The `JHipsterModulesAssertions.assertThatModule(...)` will really apply the module to a project and give you a fluent API to ensure some operations;
* Even if the feedback loops are not perfect on that they should be short enough to allow a decent TDD implementation of the factory (on eclipse with [infinitest](https://infinitest.github.io/) feedbacks are under a second).
- We are expecting to have a `buildModule(...)` method in `MyModuleFactory`;
- The `JHipsterModulesAssertions.assertThatModule(...)` will really apply the module to a project and give you a fluent API to ensure some operations;
- Even if the feedback loops are not perfect on that they should be short enough to allow a decent TDD implementation of the factory (on eclipse with [infinitest](https://infinitest.github.io/) feedbacks are under a second).

So, now that we have a first test we can do a simple implementation:
So, now that we have a first test we can do a simple implementation:

```java
import static tech.jhipster.lite.module.domain.JHipsterModule.*;
Expand All @@ -69,11 +70,12 @@ public class MyModuleFactory {
//@formatter:on
}
}

```

This implementation will take a file from `src/main/resources/generator/my-module` and put it in the generated project.

The file is a template named `Dummy.java.mustache` and can contains some mustache placeholders:
The file is a template named `Dummy.java.mustache` and can contains some mustache placeholders:

```java
package {{packageName}}.my_package;
Expand All @@ -92,24 +94,26 @@ And this is it for this part of the documentation... Of course you can do a lot

### Dependency resolution

* In the `src/main/resources/generator/dependencies` folder, different files are maintained to handle the dependencies for different tools/frameworks such as docker, maven, angular etc.
* You can add the dependencies required for your new module in the respective files in the `dependencies` folder.
* The dependency versions are then automatically managed by the dependabot.
- In the `src/main/resources/generator/dependencies` folder, different files are maintained to handle the dependencies for different tools/frameworks such as docker, maven, angular etc.
- You can add the dependencies required for your new module in the respective files in the `dependencies` folder.
- The dependency versions are then automatically managed by the dependabot.

### Overview of Version files/folders in this dependencies folder

* **Docker versions**
* You can add the docker images required for your module in the `src/main/resources/generator/dependencies/Dockerfile`
* These dependencies are resolved using the [FileSystemDockerImagesReader](https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/docker/FileSystemDockerImagesReader.java), an implementation of the `DockerImagesReader` bean to read from a local file.
- **Docker versions**

* **Java versions**
* You can add the java dependencies required for your module in the `src/main/resources/generator/dependencies/pom.xml`
* These dependencies are resolved using [FileSystemJavaDependenciesReader](https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/FileSystemJavaDependenciesReader.java), an implementation of the `JavaDependenciesReader` bean to read from a local file.
- You can add the docker images required for your module in the `src/main/resources/generator/dependencies/Dockerfile`
- These dependencies are resolved using the [FileSystemDockerImagesReader](https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/docker/FileSystemDockerImagesReader.java), an implementation of the `DockerImagesReader` bean to read from a local file.

* **NPM versions**
* Common npm dependencies can be added in the `src/main/resources/generator/dependencies/common/package.json`
* Framework specific npm dependencies can be added in the `package.json` of the respective framework folders. For eg: `src/main/resources/generator/dependencies/react/package.json`
* These dependencies are resolved using [FileSystemNpmVersionReader](https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmVersionReader.java), an implementation of the `NpmVersionsReader` bean to read from a local file.
- **Java versions**

- You can add the java dependencies required for your module in the `src/main/resources/generator/dependencies/pom.xml`
- These dependencies are resolved using [FileSystemJavaDependenciesReader](https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/FileSystemJavaDependenciesReader.java), an implementation of the `JavaDependenciesReader` bean to read from a local file.

- **NPM versions**
- Common npm dependencies can be added in the `src/main/resources/generator/dependencies/common/package.json`
- Framework specific npm dependencies can be added in the `package.json` of the respective framework folders. For eg: `src/main/resources/generator/dependencies/react/package.json`
- These dependencies are resolved using [FileSystemNpmVersionReader](https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmVersionReader.java), an implementation of the `NpmVersionsReader` bean to read from a local file.

## Creating JHipsterModuleResource

Expand Down Expand Up @@ -138,9 +142,7 @@ To be used by JHLite, the `JHipsterModuleResource` needs to be a Spring bean so,
class MyModuleModuleConfiguration {

@Bean
JHipsterModuleResource myModule(
MyModuleApplicationService myModules
) {
JHipsterModuleResource myModule(MyModuleApplicationService myModules) {
return JHipsterModuleResource
.builder()
.slug(JHLiteModuleSlug.MY_MODULE)
Expand All @@ -151,9 +153,10 @@ class MyModuleModuleConfiguration {
.factory(myModules::buildModule);
}
}

```

In fact, you don't really have choices here, the `JHipsterModuleResource.builder()` is fluent and will only let you go to the next possible step.
In fact, you don't really have choices here, the `JHipsterModuleResource.builder()` is fluent and will only let you go to the next possible step.
The most confusing one may be the last one `.factory(myModules::buildModule)` which is, in fact, a method called to build the module.

For this to work, we'll need to add a simple orchestration class in `tech.jhipster.lite.generator.my_module.application`:
Expand Down
Loading

0 comments on commit c266314

Please sign in to comment.