Skip to content

Commit

Permalink
Merge pull request #1760 from DamnClin/rework-template-methods
Browse files Browse the repository at this point in the history
Rework template methods
  • Loading branch information
pascalgrimaud authored May 18, 2022
2 parents d07dcff + 3747d8e commit 06dc134
Show file tree
Hide file tree
Showing 79 changed files with 1,173 additions and 846 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void addJavaBuildGradleKts(Project project) {
String baseName = project.getBaseName().orElse("");
project.addConfig("dasherizedBaseName", WordUtils.kebabCase(baseName));

projectRepository.template(project, SOURCE, BUILD_GRADLE_KTS);
projectRepository.template(project, SOURCE, SETTINGS_GRADLE_KTS);
projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, BUILD_GRADLE_KTS).withSameDestination());
projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, SETTINGS_GRADLE_KTS).withSameDestination());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void addJavaPomXml(Project project) {
String baseName = project.getBaseName().orElse("");
project.addConfig("dasherizedBaseName", WordUtils.kebabCase(baseName));

projectRepository.template(project, SOURCE, POM_XML);
projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, POM_XML).withSameDestination());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tech.jhipster.lite.generator.ci.github.actions.domain;

import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.domain.ProjectFile;
import tech.jhipster.lite.generator.project.domain.ProjectRepository;

public class GitHubActionsDomainService implements GitHubActionsService {
Expand All @@ -26,30 +27,28 @@ public void addGitHubActions(Project project) {
addSetupYamls(project);
if (project.isMavenProject()) {
projectRepository.template(
project,
GITHUB_ACTIONS_CI_SOURCE_FOLDER,
GITHUB_ACTIONS_MAVEN_CI_YML,
GITHUB_ACTIONS_CI_DESTINATION_FOLDER,
GITHUB_ACTIONS_CI_YML
ProjectFile
.forProject(project)
.withSource(GITHUB_ACTIONS_CI_SOURCE_FOLDER, GITHUB_ACTIONS_MAVEN_CI_YML)
.withDestination(GITHUB_ACTIONS_CI_DESTINATION_FOLDER, GITHUB_ACTIONS_CI_YML)
);
}
if (project.isGradleProject()) {
projectRepository.template(
project,
GITHUB_ACTIONS_CI_SOURCE_FOLDER,
GITHUB_ACTIONS_GRADLE_CI_YML,
GITHUB_ACTIONS_CI_DESTINATION_FOLDER,
GITHUB_ACTIONS_CI_YML
ProjectFile
.forProject(project)
.withSource(GITHUB_ACTIONS_CI_SOURCE_FOLDER, GITHUB_ACTIONS_GRADLE_CI_YML)
.withDestination(GITHUB_ACTIONS_CI_DESTINATION_FOLDER, GITHUB_ACTIONS_CI_YML)
);
}
}

private void addSetupYamls(Project project) {
projectRepository.template(
project,
GITHUB_ACTIONS_SETUP_SOURCE_FOLDER,
GITHUB_ACTIONS_SETUP_YML,
GITHUB_ACTIONS_SETUP_DESTINATION_FOLDER
ProjectFile
.forProject(project)
.withSource(GITHUB_ACTIONS_SETUP_SOURCE_FOLDER, GITHUB_ACTIONS_SETUP_YML)
.withDestinationFolder(GITHUB_ACTIONS_SETUP_DESTINATION_FOLDER)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static tech.jhipster.lite.generator.project.domain.Constants.*;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*;

import java.util.List;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService;
import tech.jhipster.lite.generator.project.domain.Project;
Expand Down Expand Up @@ -45,8 +46,12 @@ private void addCommonAngular(Project project) {
public void addAppFiles(Project project) {
project.addDefaultConfig(BASE_NAME);

projectRepository.template(project, SOURCE_PRIMARY, APP_COMPONENT_HTML, DESTINATION_PRIMARY);
projectRepository.template(project, SOURCE_PRIMARY, APP_COMPONENT, DESTINATION_PRIMARY);
projectRepository.template(
ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, APP_COMPONENT_HTML).withDestinationFolder(DESTINATION_PRIMARY)
);
projectRepository.template(
ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, APP_COMPONENT).withDestinationFolder(DESTINATION_PRIMARY)
);

addImages(project);
}
Expand Down Expand Up @@ -91,9 +96,20 @@ public void addFiles(Project project) {

public void addAngularFiles(Project project) {
project.addDefaultConfig(BASE_NAME);
Angular

List<ProjectFile> files = Angular
.angularFiles()
.forEach((file, path) -> projectRepository.template(project, getPath(SOURCE_WEBAPP, path), file, getPath(MAIN_WEBAPP, path)));
.entrySet()
.stream()
.map(entry ->
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE_WEBAPP, entry.getValue()), entry.getKey())
.withDestinationFolder(getPath(MAIN_WEBAPP, entry.getValue()))
)
.toList();

projectRepository.template(files);
}

public void addImages(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME;

import java.util.List;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.domain.ProjectFile;
import tech.jhipster.lite.generator.project.domain.ProjectRepository;

public class AngularJwtDomainService implements AngularJwtService {
Expand Down Expand Up @@ -46,34 +48,34 @@ public void updateAngularFilesForJwt(Project project) {
String oldHtml = "// jhipster-needle-angular-jwt-login-form";
String newHtml =
"""
{
path: '',
loadChildren: () => import('./login/login.module').then(m => m.LoginModule),
}""";
{
path: '',
loadChildren: () => import('./login/login.module').then(m => m.LoginModule),
}""";
projectRepository.replaceText(project, APP, APP_ROUTING_MODULE, oldHtml, newHtml);

oldHtml = "import \\{ AppRoutingModule \\} from './app-routing.module';";
newHtml =
"""
import { TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { AppRoutingModule, routes } from './app-routing.module';""";
import { TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { AppRoutingModule, routes } from './app-routing.module';""";
projectRepository.replaceText(project, APP, APP_ROUTING_MODULE_SPEC, oldHtml, newHtml);

oldHtml = "// jhipster-needle-angular-jwt-login-form";
newHtml =
"""
let router: Router;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes(routes)]
}).compileComponents();
router = TestBed.get(Router);
router.initialNavigation();
});
""";
let router: Router;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes(routes)]
}).compileComponents();
router = TestBed.get(Router);
router.initialNavigation();
});
""";
projectRepository.replaceText(project, APP, APP_ROUTING_MODULE_SPEC, oldHtml, newHtml);

oldHtml = "import \\{ NgModule \\} from '@angular/core';";
Expand Down Expand Up @@ -121,14 +123,37 @@ public void updateAngularFilesForJwt(Project project) {

public void addJwtFiles(Project project) {
project.addConfig("serverPort", 8080);
AngularJwt.jwtFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, getPath("", path)));

List<ProjectFile> files = AngularJwt
.jwtFiles()
.entrySet()
.stream()
.map(entry ->
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE, entry.getValue()), entry.getKey())
.withDestinationFolder(getPath("", entry.getValue()))
)
.toList();

projectRepository.template(files);
}

public void addAngularJwtFiles(Project project) {
project.addDefaultConfig(BASE_NAME);
AngularJwt

List<ProjectFile> files = AngularJwt
.angularJwtFiles()
.forEach((file, path) -> projectRepository.template(project, getPath(SOURCE_WEBAPP, path), file, getPath(MAIN_WEBAPP, path)));
.entrySet()
.stream()
.map(entry ->
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE_WEBAPP, entry.getValue()), entry.getKey())
.withDestinationFolder(getPath(MAIN_WEBAPP, entry.getValue()))
)
.toList();
projectRepository.template(files);
}

private void addDependency(Project project, String dependency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static tech.jhipster.lite.common.domain.FileUtils.*;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*;

import java.util.List;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService;
import tech.jhipster.lite.generator.project.domain.Project;
Expand Down Expand Up @@ -84,17 +85,35 @@ public void addFiles(Project project) {
}

public void addReactCommonFiles(Project project) {
React.reactCommonFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, path));
List<ProjectFile> files = React
.reactCommonFiles()
.entrySet()
.stream()
.map(entry ->
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE, entry.getValue()), entry.getKey())
.withDestinationFolder(entry.getValue())
)
.toList();

projectRepository.template(files);
}

public void addReactUnstyledFiles(Project project) {
projectRepository.template(project, getPath(SOURCE, SOURCE_APP), "App.tsx", SOURCE_APP);
projectRepository.template(
ProjectFile.forProject(project).withSource(getPath(SOURCE, SOURCE_APP), "App.tsx").withDestinationFolder(SOURCE_APP)
);
}

public void addReactStyledFiles(Project project) {
String imagesPath = "src/main/webapp/content/images";
projectRepository.template(project, getPath(SOURCE, SOURCE_APP), "StyledApp.tsx", SOURCE_APP, "App.tsx");
projectRepository.template(project, getPath(SOURCE, SOURCE_APP), "App.css", SOURCE_APP);
projectRepository.template(
ProjectFile.forProject(project).withSource(getPath(SOURCE, SOURCE_APP), "StyledApp.tsx").withDestination(SOURCE_APP, "App.tsx")
);
projectRepository.template(
ProjectFile.forProject(project).withSource(getPath(SOURCE, SOURCE_APP), "App.css").withDestinationFolder(SOURCE_APP)
);

projectRepository.add(
ProjectFile.forProject(project).withSource(getPath(SOURCE, imagesPath), "ReactLogo.png").withDestinationFolder(imagesPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,45 @@ public void addSvelteConfigFile(Project project) {
public void addRootFiles(Project project) {
String pathWebapp = "src/main/webapp";

projectRepository.template(project, getPath(SOURCE, pathWebapp), "app.html", pathWebapp);
projectRepository.template(project, getPath(SOURCE, pathWebapp), "app.d.ts", pathWebapp);
projectRepository.template(project, getPath(SOURCE, pathWebapp), "jest-setup.ts", pathWebapp);
projectRepository.template(
ProjectFile.forProject(project).withSource(getPath(SOURCE, pathWebapp), "app.html").withDestinationFolder(pathWebapp)
);
projectRepository.template(
ProjectFile.forProject(project).withSource(getPath(SOURCE, pathWebapp), "app.d.ts").withDestinationFolder(pathWebapp)
);
projectRepository.template(
ProjectFile.forProject(project).withSource(getPath(SOURCE, pathWebapp), "jest-setup.ts").withDestinationFolder(pathWebapp)
);
}

public void addAppFiles(Project project) {
String sourceRoutes = getPath(SOURCE, "src/main/webapp/routes");
String destinationRoutes = "src/main/webapp/routes";

projectRepository.template(project, sourceRoutes, "index.svelte", destinationRoutes);
projectRepository.template(
ProjectFile.forProject(project).withSource(sourceRoutes, "index.svelte").withDestinationFolder(destinationRoutes)
);

projectRepository.template(
project,
getPath(SOURCE, "src/test/spec/common/primary/app"),
"App.spec.ts",
"src/test/javascript/spec/common/primary/app"
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE, "src/test/spec/common/primary/app"), "App.spec.ts")
.withDestinationFolder("src/test/javascript/spec/common/primary/app")
);
}

public void addUnstyledHomeFiles(Project project) {
projectRepository.template(project, SOURCE_PRIMARY, "App.svelte", DESTINATION_PRIMARY);
projectRepository.template(
ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, "App.svelte").withDestinationFolder(DESTINATION_PRIMARY)
);
}

public void addStyledHomeFiles(Project project) {
String assets = "src/main/webapp/assets";

projectRepository.template(project, SOURCE_PRIMARY, "StyledApp.svelte", DESTINATION_PRIMARY, "App.svelte");
projectRepository.template(
ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, "StyledApp.svelte").withDestination(DESTINATION_PRIMARY, "App.svelte")
);

projectRepository.add(
ProjectFile.forProject(project).withSource(getPath(SOURCE, assets), "JHipster-Lite-neon-orange.png").withDestinationFolder(assets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public void addCypressScripts(Project project) {

public void addCypressFiles(Project project) {
project.addConfig("serverPort", 8080);
projectRepository.template(project, getPath(SOURCE, JAVASCRIPT_INTEGRATION), "cypress-config.json", getPath(JAVASCRIPT_INTEGRATION));
projectRepository.template(
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE, JAVASCRIPT_INTEGRATION), "cypress-config.json")
.withDestinationFolder(getPath(JAVASCRIPT_INTEGRATION))
);

List<ProjectFile> files = Cypress
.cypressFiles()
Expand All @@ -73,7 +78,19 @@ public void addCypressFiles(Project project) {
}

public void addCypressTestFiles(Project project) {
Cypress.cypressTestFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, path));
List<ProjectFile> files = Cypress
.cypressTestFiles()
.entrySet()
.stream()
.map(entry ->
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE, entry.getValue()), entry.getKey())
.withDestinationFolder(entry.getValue())
)
.toList();

projectRepository.template(files);
}

private void excludeIntegrationFilesTsConfig(Project project) {
Expand Down
Loading

0 comments on commit 06dc134

Please sign in to comment.