Skip to content

Commit

Permalink
Merge pull request #2502 from DamnClin/react-modules
Browse files Browse the repository at this point in the history
Migrate react modules
  • Loading branch information
pascalgrimaud authored Jul 11, 2022
2 parents 9ef74af + 20795e7 commit 7062222
Show file tree
Hide file tree
Showing 25 changed files with 335 additions and 684 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package tech.jhipster.lite.generator.client.angular.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.ANGULAR;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.*;

import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.module.domain.Indentation;
import tech.jhipster.lite.generator.client.common.domain.ClientsModulesFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
Expand All @@ -13,14 +12,9 @@ public class AngularModuleFactory {

private static final JHipsterSource SOURCE = from("client/angular/core");

private static final String CACHE_NEEDLE = " \"cacheDirectories\":";
private static final String BREAK = "\n";

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return moduleBuilder(properties)
return ClientsModulesFactory.clientModuleBuilder(properties)
.packageJson()
.addDependency(packageName("@angular/animations"), ANGULAR)
.addDependency(packageName("@angular/cdk"), ANGULAR)
Expand Down Expand Up @@ -53,11 +47,6 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.addScript(scriptKey("watch"), scriptCommand("ng build --watch --configuration development"))
.addScript(scriptKey("test"), scriptCommand("ng test --coverage"))
.and()
.optionalReplacements()
.in("package.json")
.add(justLineBefore(text(CACHE_NEEDLE)), jestSonar(properties.indentation()))
.and()
.and()
.files()
.add(SOURCE.file("jest.conf.js"), to("jest.conf.js"))
.add(SOURCE.file("angular.json"), to("angular.json"))
Expand Down Expand Up @@ -94,20 +83,4 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.build();
//@formatter:on
}

private String jestSonar(Indentation indentation) {
return new StringBuilder()
.append(indentation.spaces())
.append("\"jestSonar\": {")
.append(BREAK)
.append(indentation.times(2))
.append("\"reportPath\": \"target/test-results/jest\",")
.append(BREAK)
.append(indentation.times(2))
.append("\"reportFile\": \"TESTS-results-sonar.xml\"")
.append(BREAK)
.append(indentation.spaces())
.append("},")
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tech.jhipster.lite.generator.client.common.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.module.domain.Indentation;
import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

public class ClientsModulesFactory {

private static final String CACHE_NEEDLE = " \"cacheDirectories\":";

private ClientsModulesFactory() {}

public static JHipsterModuleBuilder clientModuleBuilder(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

return moduleBuilder(properties)
.optionalReplacements()
.in("package.json")
.add(justLineBefore(text(CACHE_NEEDLE)), jestSonar(properties.indentation()))
.and()
.and();
}

private static String jestSonar(Indentation indentation) {
return new StringBuilder()
.append(indentation.spaces())
.append("\"jestSonar\": {")
.append(LINE_BREAK)
.append(indentation.times(2))
.append("\"reportPath\": \"target/test-results/jest\",")
.append(LINE_BREAK)
.append(indentation.times(2))
.append("\"reportFile\": \"TESTS-results-sonar.xml\"")
.append(LINE_BREAK)
.append(indentation.spaces())
.append("},")
.toString();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tech.jhipster.lite.generator.client.react.core.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.client.react.core.domain.ReactCoreModulesFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class ReactCoreApplicationService {

private final ReactCoreModulesFactory factory;

public ReactCoreApplicationService() {
factory = new ReactCoreModulesFactory();
}

public JHipsterModule buildModuleWithoutStyle(JHipsterModuleProperties properties) {
return factory.buildModuleWithoutStyle(properties);
}

public JHipsterModule buildModuleWithStyle(JHipsterModuleProperties properties) {
return factory.buildModuleWithStyle(properties);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package tech.jhipster.lite.generator.client.react.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.*;

import tech.jhipster.lite.generator.client.common.domain.ClientsModulesFactory;
import tech.jhipster.lite.module.domain.JHipsterDestination;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

public class ReactCoreModulesFactory {

private static final JHipsterSource SOURCE = from("client/react");

private static final JHipsterSource WEBAPP_SOURCE = SOURCE.append("src/main/webapp");
private static final JHipsterDestination WEBAPP_DESTINATION = to("src/main/webapp");

private static final JHipsterSource APP_SOURCE = WEBAPP_SOURCE.append("app");
private static final JHipsterDestination APP_DESTINATION = WEBAPP_DESTINATION.append("app");

private static final String PRIMARY_APP = "common/primary/app";
private static final String CONTENT_IMAGES = "content/images";

private static final JHipsterSource PRIMARY_APP_SOURCE = APP_SOURCE.append(PRIMARY_APP);
private static final JHipsterDestination PRIMARY_APP_DESTINATION = APP_DESTINATION.append(PRIMARY_APP);

private static final String TEST_PRIMARY = "src/test/javascript/spec/common/primary/app";

public JHipsterModule buildModuleWithoutStyle(JHipsterModuleProperties properties) {
//@formatter:off
return commonModuleBuilder(properties)
.files()
.add(PRIMARY_APP_SOURCE.template("App.tsx"), APP_DESTINATION.append("common/primary/app/App.tsx"))
.and()
.build();
//@formatter:on
}

public JHipsterModule buildModuleWithStyle(JHipsterModuleProperties properties) {
//@formatter:off
return commonModuleBuilder(properties)
.files()
.add(PRIMARY_APP_SOURCE.template("StyledApp.tsx"), PRIMARY_APP_DESTINATION.append("App.tsx"))
.add(PRIMARY_APP_SOURCE.template("App.css"), PRIMARY_APP_DESTINATION.append("App.css"))
.batch(WEBAPP_SOURCE.append(CONTENT_IMAGES), WEBAPP_DESTINATION.append(CONTENT_IMAGES))
.file("JHipster-Lite-neon-blue.png")
.file("ReactLogo.png")
.and()
.and()
.build();
//@formatter:on
}

private static JHipsterModuleBuilder commonModuleBuilder(JHipsterModuleProperties properties) {
//@formatter:off
return ClientsModulesFactory.clientModuleBuilder(properties)
.packageJson()
.addDevDependency(packageName("@testing-library/jest-dom"), REACT)
.addDevDependency(packageName("@testing-library/react"), REACT)
.addDevDependency(packageName("@testing-library/user-event"), REACT)
.addDevDependency(packageName("@types/jest"), REACT)
.addDevDependency(packageName("@types/node"), REACT)
.addDevDependency(packageName("@types/react"), REACT)
.addDevDependency(packageName("@types/react-dom"), REACT)
.addDevDependency(packageName("@types/ws"), REACT)
.addDevDependency(packageName("@vitejs/plugin-react"), REACT)
.addDevDependency(packageName("jest"), REACT)
.addDevDependency(packageName("jest-sonar-reporter"), REACT)
.addDevDependency(packageName("jest-css-modules"), REACT)
.addDevDependency(packageName("jest-environment-jsdom"), REACT)
.addDevDependency(packageName("typescript"), REACT)
.addDevDependency(packageName("ts-jest"), REACT)
.addDevDependency(packageName("ts-node"), REACT)
.addDevDependency(packageName("vite"), REACT)
.addDependency(packageName("react"), REACT)
.addDependency(packageName("react-dom"), REACT)
.addScript(scriptKey("dev"), scriptCommand("vite"))
.addScript(scriptKey("build"), scriptCommand("tsc && vite build --emptyOutDir"))
.addScript(scriptKey("preview"), scriptCommand("vite preview"))
.addScript(scriptKey("start"), scriptCommand("vite"))
.addScript(scriptKey("test"), scriptCommand("jest"))
.addScript(scriptKey("dev"), scriptCommand("vite"))
.addScript(scriptKey("test:watch"), scriptCommand("jest --watch"))
.and()
.files()
.batch(SOURCE, to("."))
.file("tsconfig.json")
.file("vite.config.ts")
.file("jest.config.ts")
.and()
.batch(APP_SOURCE, APP_DESTINATION)
.template("index.css")
.template("index.tsx")
.template("vite-env.d.ts")
.and()
.add(WEBAPP_SOURCE.template("index.html"), WEBAPP_DESTINATION.append("index.html"))
.add(SOURCE.append(TEST_PRIMARY).template("App.spec.tsx"), to(TEST_PRIMARY).append("App.spec.tsx"))
.add(WEBAPP_SOURCE.template("config/setupTests.ts"), WEBAPP_DESTINATION.append("config/setupTests.ts"))
.and();
//@formatter:on
}
}
Loading

0 comments on commit 7062222

Please sign in to comment.