From 845dfa4b943b5dc8605e271af4f48276c5559fdc Mon Sep 17 00:00:00 2001 From: Hippolyte Durix Date: Thu, 25 Aug 2022 17:52:23 +0200 Subject: [PATCH] Split init & init-minimal to have a prettier module Fix #3224 --- .editorconfig | 3 - .../primary/MavenModuleConfiguration.java | 2 +- .../AngularCoreModuleConfiguration.java | 2 +- .../ReactCoreModulesConfiguration.java | 2 +- .../core/domain/SvelteDomainService.java | 6 +- .../primary/CypressModuleConfiguration.java | 2 +- .../PlaywrightModuleConfiguration.java | 2 +- .../primary/VueModuleConfiguration.java | 2 +- .../application/InitApplicationService.java | 8 +-- .../init/domain/InitModuleFactory.java | 45 ++------------ .../primary/InitModuleConfiguration.java | 39 ++---------- .../npm/domain/NpmDomainService.java | 4 +- .../PrettierApplicationService.java | 20 +++++++ .../domain/PrettierModuleFactory.java | 49 +++++++++++++++ .../primary/PrettierModuleConfiguration.java | 30 ++++++++++ .../project/domain/DefaultConfig.java | 6 +- .../TypescriptModuleConfiguration.java | 2 +- .../properties/JHipsterModuleProperties.java | 2 +- .../JHipsterModulePropertiesDefinition.java | 4 ++ .../JHipsterModulePropertyDefinition.java | 4 ++ .../generator/init/.editorconfig.mustache | 8 +-- .../generator/init/package.json.mustache | 5 -- .../{init => prettier}/.husky/pre-commit | 0 .../{init => prettier}/.lintstagedrc.js | 0 .../{init => prettier}/.prettierignore | 0 .../{init => prettier}/.prettierrc.mustache | 4 +- src/test/features/cucumber.feature | 8 +-- src/test/features/dev-tools.feature | 8 +-- src/test/features/init.feature | 18 ------ src/test/features/mariadb.feature | 8 +-- src/test/features/modules.feature | 2 +- src/test/features/mssql.feature | 8 +-- src/test/features/mysql.feature | 8 +-- src/test/features/postgresql.feature | 8 +-- src/test/features/prettier.feature | 13 ++++ .../jhipster/lite/generator/ModulesSteps.java | 2 +- .../domain/AngularJwtModuleFactoryTest.java | 1 - .../core/domain/SvelteDomainServiceTest.java | 11 +++- .../init/domain/InitModuleFactoryTest.java | 60 ++++++------------- .../domain/PrettierModuleFactoryTest.java | 57 ++++++++++++++++++ .../primary/dto/ProjectDTOTest.java | 2 +- .../domain/SpringdocModuleFactoryTest.java | 1 - .../kafka/domain/KafkaModuleFactoryTest.java | 1 - ...myMongoDBPersistenceModuleFactoryTest.java | 1 - .../domain/JHipsterModuleContextTest.java | 10 +--- .../module/domain/JHipsterModulesFixture.java | 5 +- .../domain/properties/IndentationTest.java | 6 +- ...ipsterModuleMandatoryReplacementsTest.java | 1 - ...HipsterModuleOptionalReplacementsTest.java | 1 - ...HipsterModulePropertiesDefinitionTest.java | 2 +- .../RestJHipsterModulePropertiesTest.java | 2 +- .../secondary/TestJHipsterModules.java | 3 +- .../FileSystemProjectsRepositoryTest.java | 1 - .../secondary/ProjectFormattingSteps.java | 1 - tests-ci/config/undertow-oauth2.json | 2 +- tests-ci/generate.sh | 6 +- 56 files changed, 279 insertions(+), 229 deletions(-) create mode 100644 src/main/java/tech/jhipster/lite/generator/prettier/application/PrettierApplicationService.java create mode 100644 src/main/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactory.java create mode 100644 src/main/java/tech/jhipster/lite/generator/prettier/infrastructure/primary/PrettierModuleConfiguration.java rename src/main/resources/generator/{init => prettier}/.husky/pre-commit (100%) rename src/main/resources/generator/{init => prettier}/.lintstagedrc.js (100%) rename src/main/resources/generator/{init => prettier}/.prettierignore (100%) rename src/main/resources/generator/{init => prettier}/.prettierrc.mustache (74%) create mode 100644 src/test/features/prettier.feature create mode 100644 src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java diff --git a/.editorconfig b/.editorconfig index cd1795e23fc..7d2a5203625 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,9 +16,6 @@ insert_final_newline = true indent_style = space indent_size = 2 -[*.{java}] -indent_size = 2 - [*.md] trim_trailing_whitespace = false diff --git a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/infrastructure/primary/MavenModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/infrastructure/primary/MavenModuleConfiguration.java index 054f007c812..4594dc228d6 100644 --- a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/infrastructure/primary/MavenModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/infrastructure/primary/MavenModuleConfiguration.java @@ -19,7 +19,7 @@ JHipsterModuleResource mavenModule(MavenApplicationService maven) { .slug("maven-java") .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addProjectName().build()) .apiDoc(new JHipsterModuleApiDoc("Build Tool", "Init Maven project with pom.xml and wrapper")) - .organization(JHipsterModuleOrganization.builder().feature("java-build-tool").addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().feature("java-build-tool").addModuleDependency("init").build()) .tags("buildtool", "test") .factory(maven::buildModule); } diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/core/infrastructure/primary/AngularCoreModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/angular/core/infrastructure/primary/AngularCoreModuleConfiguration.java index 1824b13b168..a8fa35af0fe 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/angular/core/infrastructure/primary/AngularCoreModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/client/angular/core/infrastructure/primary/AngularCoreModuleConfiguration.java @@ -19,7 +19,7 @@ JHipsterModuleResource angularModule(AngularApplicationService angular) { .slug("angular-core") .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addProjectName().build()) .apiDoc(new JHipsterModuleApiDoc("Angular", "Add Angular + Angular CLI")) - .organization(JHipsterModuleOrganization.builder().feature("client-core").addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().feature("client-core").addModuleDependency("init").build()) .tags("client", "angular") .factory(angular::buildInitModule); } diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/core/infrastructure/primary/ReactCoreModulesConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/react/core/infrastructure/primary/ReactCoreModulesConfiguration.java index 3d92149773f..b1794b48b89 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/react/core/infrastructure/primary/ReactCoreModulesConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/client/react/core/infrastructure/primary/ReactCoreModulesConfiguration.java @@ -21,7 +21,7 @@ JHipsterModuleResource styledReactCoreModule(ReactCoreApplicationService react) .slug("react-core") .propertiesDefinition(properties()) .apiDoc(new JHipsterModuleApiDoc("React", "Add React+Vite with minimal CSS")) - .organization(JHipsterModuleOrganization.builder().feature("client-core").addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().feature("client-core").addModuleDependency("init").build()) .tags("client", REACT) .factory(react::buildModuleWithStyle); } diff --git a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java index 046c16a14f1..37266873e0f 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java @@ -3,6 +3,8 @@ import static tech.jhipster.lite.common.domain.FileUtils.*; import static tech.jhipster.lite.generator.project.domain.Constants.*; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Map; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; @@ -39,7 +41,9 @@ public void addStyledSvelteKit(Project project) { } public void renameJhipsterFiles(Project project) { - projectRepository.rename(project, ".", ".lintstagedrc.js", ".lintstagedrc.cjs"); + if (Files.exists(Paths.get(project.getFolder(), ".lintstagedrc.js"))) { + projectRepository.rename(project, ".", ".lintstagedrc.js", ".lintstagedrc.cjs"); + } } public void addCommonSvelteKit(Project project) { diff --git a/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/infrastructure/primary/CypressModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/infrastructure/primary/CypressModuleConfiguration.java index 379bc01fa6b..e773f6d6450 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/infrastructure/primary/CypressModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/infrastructure/primary/CypressModuleConfiguration.java @@ -19,7 +19,7 @@ JHipsterModuleResource cypresModule(CypressApplicationService cypress) { .slug("cypress") .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addServerPort().addIndentation().build()) .apiDoc(new JHipsterModuleApiDoc("E2e", "Add Cypress")) - .organization(JHipsterModuleOrganization.builder().feature("front-browser-test").addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().feature("front-browser-test").addModuleDependency("init").build()) .tags("client", "cypress", "e2e") .factory(cypress::buildModule); } diff --git a/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/infrastructure/primary/PlaywrightModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/infrastructure/primary/PlaywrightModuleConfiguration.java index a5087a1581c..da33a7075b8 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/infrastructure/primary/PlaywrightModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/infrastructure/primary/PlaywrightModuleConfiguration.java @@ -19,7 +19,7 @@ JHipsterModuleResource playwrightModule(PlaywrightApplicationService playwright) .slug("client-common-playwright") .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addServerPort().build()) .apiDoc(new JHipsterModuleApiDoc("E2e", "/api/clients/playwright")) - .organization(JHipsterModuleOrganization.builder().feature("front-browser-test").addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().feature("front-browser-test").addModuleDependency("init").build()) .tags("client", "test", "playwright") .factory(playwright::buildModule); } diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/core/infrastructure/primary/VueModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/vue/core/infrastructure/primary/VueModuleConfiguration.java index 113740ae7c5..47936bff4d5 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/vue/core/infrastructure/primary/VueModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/core/infrastructure/primary/VueModuleConfiguration.java @@ -19,7 +19,7 @@ JHipsterModuleResource vueModule(VueApplicationService vue) { .slug("vue") .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addIndentation().build()) .apiDoc(new JHipsterModuleApiDoc("Vue", "Add Vue+Vite")) - .organization(JHipsterModuleOrganization.builder().feature("client-core").addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().feature("client-core").addModuleDependency("init").build()) .tags("client", "init", "vue") .factory(vue::buildVueModule); } diff --git a/src/main/java/tech/jhipster/lite/generator/init/application/InitApplicationService.java b/src/main/java/tech/jhipster/lite/generator/init/application/InitApplicationService.java index 33e4cd68d56..fe15086b69b 100644 --- a/src/main/java/tech/jhipster/lite/generator/init/application/InitApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/init/application/InitApplicationService.java @@ -15,11 +15,7 @@ public InitApplicationService(NpmVersions npmVersions) { factory = new InitModuleFactory(npmVersions); } - public JHipsterModule buildFullInitModule(JHipsterModuleProperties properties) { - return factory.buildFullModule(properties); - } - - public JHipsterModule buildMinimalInitModule(JHipsterModuleProperties properties) { - return factory.buildMinimalModule(properties); + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + return factory.buildModule(properties); } } diff --git a/src/main/java/tech/jhipster/lite/generator/init/domain/InitModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/init/domain/InitModuleFactory.java index 82037a4bd6f..8ccb445551c 100644 --- a/src/main/java/tech/jhipster/lite/generator/init/domain/InitModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/init/domain/InitModuleFactory.java @@ -1,11 +1,9 @@ package tech.jhipster.lite.generator.init.domain; import static tech.jhipster.lite.module.domain.JHipsterModule.*; -import static tech.jhipster.lite.module.domain.packagejson.VersionSource.*; import tech.jhipster.lite.error.domain.Assert; import tech.jhipster.lite.module.domain.JHipsterModule; -import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder; import tech.jhipster.lite.module.domain.file.JHipsterDestination; import tech.jhipster.lite.module.domain.file.JHipsterSource; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; @@ -25,56 +23,25 @@ public InitModuleFactory(NpmVersions npmVersions) { this.npmVersions = npmVersions; } - public JHipsterModule buildFullModule(JHipsterModuleProperties properties) { + public JHipsterModule buildModule(JHipsterModuleProperties properties) { //@formatter:off - return minimalModuleBuilder(properties) + return moduleBuilder(properties) .context() - .put("prettierEndOfLine", endOfLine(properties)) .put("dasherizedBaseName", properties.projectBaseName().kebabCase()) .put("nodeVersion", npmVersions.get("node", NpmVersionSource.COMMON).get()) - .and() - .files() - .batch(SOURCE, DESTINATION) - .addFile(".lintstagedrc.js") - .addFile(".prettierignore") - .addTemplate(".prettierrc") - .addTemplate("package.json") - .and() - .addExecutable(SOURCE.append(".husky").file("pre-commit"), DESTINATION.append(".husky/pre-commit")) - .and() - .packageJson() - .addDevDependency(packageName("@prettier/plugin-xml"), COMMON) - .addDevDependency(packageName("husky"), COMMON) - .addDevDependency(packageName("lint-staged"), COMMON) - .addDevDependency(packageName("prettier"), COMMON) - .addDevDependency(packageName("prettier-plugin-java"), COMMON) - .addDevDependency(packageName("prettier-plugin-packagejson"), COMMON) - .and() - .build(); - //@formatter:on - } - - public JHipsterModule buildMinimalModule(JHipsterModuleProperties properties) { - return minimalModuleBuilder(properties).build(); - } - - private JHipsterModuleBuilder minimalModuleBuilder(JHipsterModuleProperties properties) { - Assert.notNull("properties", properties); - - //@formatter:off - return moduleBuilder(properties) - .context() - .put("editorConfigEndOfLine", endOfLine(properties)) + .put("endOfLine", endOfLine(properties)) .and() .files() .batch(SOURCE, DESTINATION) .addTemplate("README.md") + .addTemplate("package.json") .addTemplate(".editorconfig") .addFile(".eslintignore") .and() .add(SOURCE.file("gitignore"), to(".gitignore")) .add(SOURCE.file("gitattributes"), to(".gitattributes")) - .and(); + .and() + .build(); //@formatter:on } diff --git a/src/main/java/tech/jhipster/lite/generator/init/infrastructure/primary/InitModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/init/infrastructure/primary/InitModuleConfiguration.java index 753ab1fe67d..50b141118d4 100644 --- a/src/main/java/tech/jhipster/lite/generator/init/infrastructure/primary/InitModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/init/infrastructure/primary/InitModuleConfiguration.java @@ -4,9 +4,7 @@ import org.springframework.context.annotation.Configuration; import tech.jhipster.lite.generator.init.application.InitApplicationService; import tech.jhipster.lite.module.domain.resource.JHipsterModuleApiDoc; -import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; -import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertyDefinition; import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; @Configuration @@ -16,45 +14,16 @@ class InitModuleConfiguration { JHipsterModuleResource initModule(InitApplicationService inits) { return JHipsterModuleResource .builder() - .legacyUrl("/api/inits/full") + .legacyUrl("/api/inits") .slug("init") .propertiesDefinition(initPropertiesDefinition()) .apiDoc(new JHipsterModuleApiDoc("Init", "Init project")) - .organization(organization()) + .standalone() .tags("server", "init") - .factory(inits::buildFullInitModule); - } - - @Bean - JHipsterModuleResource initMinimalModule(InitApplicationService inits) { - return JHipsterModuleResource - .builder() - .legacyUrl("/api/inits/minimal") - .slug("init-minimal") - .propertiesDefinition(initPropertiesDefinition()) - .apiDoc(new JHipsterModuleApiDoc("Init", "Init minimal project")) - .organization(organization()) - .tags("server", "init") - .factory(inits::buildMinimalInitModule); + .factory(inits::buildModule); } private JHipsterModulePropertiesDefinition initPropertiesDefinition() { - return JHipsterModulePropertiesDefinition - .builder() - .addProjectBaseName() - .addProjectName() - .add( - JHipsterModulePropertyDefinition - .optionalStringProperty("endOfLine") - .description("Type of line break (lf or crlf)") - .example("lf") - .order(200) - .build() - ) - .build(); - } - - private JHipsterModuleOrganization organization() { - return JHipsterModuleOrganization.builder().feature("startup").build(); + return JHipsterModulePropertiesDefinition.builder().addProjectBaseName().addProjectName().addEndOfLine().addIndentation().build(); } } diff --git a/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java b/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java index 39d0ecddce9..e60a240b9de 100644 --- a/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java @@ -43,8 +43,8 @@ public void addScript(Project project, String name, String cmd) { } private void addInformationToPackageJson(Project project, String section, String key, String value) { - project.addDefaultConfig(PRETTIER_DEFAULT_INDENT); - int indent = (Integer) project.getConfig(PRETTIER_DEFAULT_INDENT).orElse(2); + project.addDefaultConfig(INDENT_SIZE); + int indent = (Integer) project.getConfig(INDENT_SIZE).orElse(2); String needle = section + ": " + OB; String newText = needle + LF + indent(2, indent) + DQ + key + DQ + ": " + DQ + value + DQ; diff --git a/src/main/java/tech/jhipster/lite/generator/prettier/application/PrettierApplicationService.java b/src/main/java/tech/jhipster/lite/generator/prettier/application/PrettierApplicationService.java new file mode 100644 index 00000000000..cbf47520902 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/prettier/application/PrettierApplicationService.java @@ -0,0 +1,20 @@ +package tech.jhipster.lite.generator.prettier.application; + +import org.springframework.stereotype.Service; +import tech.jhipster.lite.generator.prettier.domain.PrettierModuleFactory; +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; + +@Service +public class PrettierApplicationService { + + private final PrettierModuleFactory factory; + + public PrettierApplicationService() { + factory = new PrettierModuleFactory(); + } + + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + return factory.buildModule(properties); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactory.java new file mode 100644 index 00000000000..491e1e126c9 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactory.java @@ -0,0 +1,49 @@ +package tech.jhipster.lite.generator.prettier.domain; + +import static tech.jhipster.lite.module.domain.JHipsterModule.*; +import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON; + +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.file.JHipsterDestination; +import tech.jhipster.lite.module.domain.file.JHipsterSource; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; + +public class PrettierModuleFactory { + + private static final JHipsterSource SOURCE = from("prettier"); + private static final JHipsterDestination DESTINATION = to("."); + + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + //@formatter:off + return moduleBuilder(properties) + .context() + .put("dasherizedBaseName", properties.projectBaseName().kebabCase()) + .put("endOfLine", endOfLine(properties)) + .and() + .files() + .batch(SOURCE, DESTINATION) + .addFile(".lintstagedrc.js") + .addFile(".prettierignore") + .addTemplate(".prettierrc") + .and() + .addExecutable(SOURCE.append(".husky").file("pre-commit"), DESTINATION.append(".husky/pre-commit")) + .and() + .packageJson() + .addDevDependency(packageName("@prettier/plugin-xml"), COMMON) + .addDevDependency(packageName("husky"), COMMON) + .addDevDependency(packageName("lint-staged"), COMMON) + .addDevDependency(packageName("prettier"), COMMON) + .addDevDependency(packageName("prettier-plugin-java"), COMMON) + .addDevDependency(packageName("prettier-plugin-packagejson"), COMMON) + .addScript(scriptKey("prepare"), scriptCommand("husky install")) + .addScript(scriptKey("prettier:check"), scriptCommand("prettier --check \\\\\"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\\\\\"")) + .addScript(scriptKey("prettier:format"), scriptCommand("prettier --write \\\\\"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\\\\\"")) + .and() + .build(); + //@formatter:on + } + + private String endOfLine(JHipsterModuleProperties properties) { + return properties.getOrDefaultString("endOfLine", "lf"); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/prettier/infrastructure/primary/PrettierModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/prettier/infrastructure/primary/PrettierModuleConfiguration.java new file mode 100644 index 00000000000..bcd1aaf8a4c --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/prettier/infrastructure/primary/PrettierModuleConfiguration.java @@ -0,0 +1,30 @@ +package tech.jhipster.lite.generator.prettier.infrastructure.primary; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import tech.jhipster.lite.generator.prettier.application.PrettierApplicationService; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleApiDoc; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; +import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; + +@Configuration +class PrettierModuleConfiguration { + + @Bean + JHipsterModuleResource prettierModule(PrettierApplicationService prettier) { + return JHipsterModuleResource + .builder() + .legacyUrl("/api/prettier") + .slug("prettier") + .propertiesDefinition(initPropertiesDefinition()) + .apiDoc(new JHipsterModuleApiDoc("Prettier", "Format project with prettier")) + .organization(JHipsterModuleOrganization.builder().addModuleDependency("init").build()) + .tags("server", "client", "init") + .factory(prettier::buildModule); + } + + private JHipsterModulePropertiesDefinition initPropertiesDefinition() { + return JHipsterModulePropertiesDefinition.builder().addProjectBaseName().addProjectName().addEndOfLine().addIndentation().build(); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/project/domain/DefaultConfig.java b/src/main/java/tech/jhipster/lite/generator/project/domain/DefaultConfig.java index d250e910a50..538bcaf23d2 100644 --- a/src/main/java/tech/jhipster/lite/generator/project/domain/DefaultConfig.java +++ b/src/main/java/tech/jhipster/lite/generator/project/domain/DefaultConfig.java @@ -8,13 +8,11 @@ public class DefaultConfig { public static final String BASE_NAME = "baseName"; - public static final String REMOTE_URL = "remoteUrl"; public static final String PROJECT_NAME = "projectName"; public static final String PACKAGE_NAME = "packageName"; - public static final String PRETTIER_DEFAULT_INDENT = "prettierDefaultIndent"; + public static final String INDENT_SIZE = "indentSize"; public static final String DEFAULT_PACKAGE_NAME = "com.mycompany.myapp"; - public static final String PACKAGE_PATH = "com/mycompany/myapp"; public static final String DEFAULT_BASE_NAME = "jhipster"; public static final String DEFAULT_PROJECT_NAME = "JHipster Project"; @@ -23,7 +21,7 @@ public class DefaultConfig { BASE_NAME, DEFAULT_BASE_NAME, PROJECT_NAME, DEFAULT_PROJECT_NAME, PACKAGE_NAME, DEFAULT_PACKAGE_NAME, - PRETTIER_DEFAULT_INDENT, DEFAULT_INDENTATION + INDENT_SIZE, DEFAULT_INDENTATION ); //@formatter:on diff --git a/src/main/java/tech/jhipster/lite/generator/typescript/infrastructure/primary/TypescriptModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/typescript/infrastructure/primary/TypescriptModuleConfiguration.java index 42bcd25c7cd..bedd7562c5c 100644 --- a/src/main/java/tech/jhipster/lite/generator/typescript/infrastructure/primary/TypescriptModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/typescript/infrastructure/primary/TypescriptModuleConfiguration.java @@ -18,7 +18,7 @@ JHipsterModuleResource typescriptModule(TypescriptApplicationService typescriptA .slug("typescript") .withoutProperties() .apiDoc(new JHipsterModuleApiDoc("Typescript", "Init Typescript project")) - .organization(JHipsterModuleOrganization.builder().addFeatureDependency("startup").build()) + .organization(JHipsterModuleOrganization.builder().addModuleDependency("init").build()) .tags("typescript") .factory(typescriptApplicationService::buildModule); } diff --git a/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterModuleProperties.java b/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterModuleProperties.java index fe560e43ee8..b84e44b2d63 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterModuleProperties.java +++ b/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterModuleProperties.java @@ -7,7 +7,7 @@ public class JHipsterModuleProperties { public static final String BASE_PACKAGE_PARAMETER = "packageName"; - public static final String INDENTATION_PARAMETER = "prettierDefaultIndent"; + public static final String INDENTATION_PARAMETER = "indentSize"; public static final String PROJECT_NAME_PARAMETER = "projectName"; public static final String PROJECT_BASE_NAME_PARAMETER = "baseName"; public static final String SERVER_PORT_PARAMETER = "serverPort"; diff --git a/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertiesDefinition.java b/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertiesDefinition.java index 4a3955cc521..8a698f0b028 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertiesDefinition.java +++ b/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertiesDefinition.java @@ -70,6 +70,10 @@ public JHipsterModulePropertiesDefinitionBuilder addIndentation() { return add(indentationProperty()); } + public JHipsterModulePropertiesDefinitionBuilder addEndOfLine() { + return add(endOfLineProperty()); + } + public JHipsterModulePropertiesDefinitionBuilder add(JHipsterModulePropertyDefinition propertyDefinition) { Assert.notNull("propertyDefinition", propertyDefinition); diff --git a/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertyDefinition.java b/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertyDefinition.java index 0f432c0f537..7f9bad8f52c 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertyDefinition.java +++ b/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterModulePropertyDefinition.java @@ -61,6 +61,10 @@ static JHipsterModulePropertyDefinition serverPortProperty() { .build(); } + public static JHipsterModulePropertyDefinition endOfLineProperty() { + return optionalStringProperty("endOfLine").description("Type of line break (lf or crlf)").example("lf").order(100).build(); + } + public static JHipsterModulePropertyDefinition indentationProperty() { return optionalIntegerProperty(JHipsterModuleProperties.INDENTATION_PARAMETER) .description("Number of spaces in indentation") diff --git a/src/main/resources/generator/init/.editorconfig.mustache b/src/main/resources/generator/init/.editorconfig.mustache index 8d1961b9026..5b5e7e2a445 100644 --- a/src/main/resources/generator/init/.editorconfig.mustache +++ b/src/main/resources/generator/init/.editorconfig.mustache @@ -7,18 +7,14 @@ root = true [*] # We recommend you to keep these unchanged -end_of_line = {{editorConfigEndOfLine}} +end_of_line = {{endOfLine}} charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true # Change these settings to your own preference indent_style = space -indent_size = {{prettierDefaultIndent}} - - -[*.{java}] -indent_size = {{prettierDefaultIndent}} +indent_size = {{indentSize}} [*.md] trim_trailing_whitespace = false diff --git a/src/main/resources/generator/init/package.json.mustache b/src/main/resources/generator/init/package.json.mustache index 70eaba0c358..3bc002d611f 100644 --- a/src/main/resources/generator/init/package.json.mustache +++ b/src/main/resources/generator/init/package.json.mustache @@ -7,11 +7,6 @@ "engines": { "node": ">={{nodeVersion}}" }, - "scripts": { - "prepare": "husky install", - "prettier:check": "prettier --check \"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\"", - "prettier:format": "prettier --write \"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\"" - }, "cacheDirectories": [ "node_modules" ] diff --git a/src/main/resources/generator/init/.husky/pre-commit b/src/main/resources/generator/prettier/.husky/pre-commit similarity index 100% rename from src/main/resources/generator/init/.husky/pre-commit rename to src/main/resources/generator/prettier/.husky/pre-commit diff --git a/src/main/resources/generator/init/.lintstagedrc.js b/src/main/resources/generator/prettier/.lintstagedrc.js similarity index 100% rename from src/main/resources/generator/init/.lintstagedrc.js rename to src/main/resources/generator/prettier/.lintstagedrc.js diff --git a/src/main/resources/generator/init/.prettierignore b/src/main/resources/generator/prettier/.prettierignore similarity index 100% rename from src/main/resources/generator/init/.prettierignore rename to src/main/resources/generator/prettier/.prettierignore diff --git a/src/main/resources/generator/init/.prettierrc.mustache b/src/main/resources/generator/prettier/.prettierrc.mustache similarity index 74% rename from src/main/resources/generator/init/.prettierrc.mustache rename to src/main/resources/generator/prettier/.prettierrc.mustache index 9d4e5580527..eb46c50a5e3 100644 --- a/src/main/resources/generator/init/.prettierrc.mustache +++ b/src/main/resources/generator/prettier/.prettierrc.mustache @@ -2,9 +2,9 @@ printWidth: 140 singleQuote: true -tabWidth: {{prettierDefaultIndent}} +tabWidth: {{indentSize}} useTabs: false -endOfLine: "{{prettierEndOfLine}}" +endOfLine: "{{endOfLine}}" # js and ts rules: arrowParens: avoid diff --git a/src/test/features/cucumber.feature b/src/test/features/cucumber.feature index 2288ba21d4d..9902bdc1c0b 100644 --- a/src/test/features/cucumber.feature +++ b/src/test/features/cucumber.feature @@ -3,10 +3,10 @@ Feature: Cucumber module Scenario: Should get cucumber module properties definition When I get module "spring-boot-cucumber" properties definition Then I should have properties definitions - | Key | Type | Mandatory | - | packageName | STRING | true | - | baseName | STRING | true | - | prettierDefaultIndent | INTEGER | false | + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | indentSize | INTEGER | false | Scenario: Should add cucumber elements using module url When I apply "spring-boot-cucumber" module to default project with maven file diff --git a/src/test/features/dev-tools.feature b/src/test/features/dev-tools.feature index 00516c247be..4c94b76cd20 100644 --- a/src/test/features/dev-tools.feature +++ b/src/test/features/dev-tools.feature @@ -3,10 +3,10 @@ Feature: DevTools module Scenario: Should get devtools module properties definition When I get module "spring-boot-devtools" properties definition Then I should have properties definitions - | Key | Type | Mandatory | - | packageName | STRING | true | - | baseName | STRING | true | - | prettierDefaultIndent | INTEGER | false | + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | indentSize | INTEGER | false | Scenario: Should add devtools elements using module url When I apply "spring-boot-devtools" module to default project with maven file diff --git a/src/test/features/init.feature b/src/test/features/init.feature index a4845fff1eb..18e494d43eb 100644 --- a/src/test/features/init.feature +++ b/src/test/features/init.feature @@ -10,29 +10,11 @@ Feature: Init | .gitattributes | | .editorconfig | | .eslintignore | - | .lintstagedrc.js | - | .prettierignore | - | .prettierrc | | package.json | | README.md | - And I should have files in ".husky" - | pre-commit | - - Scenario: Should init minimal from module - When I apply "init-minimal" module to default project - | packageName | tech.jhipster.chips | - | baseName | jhipster | - | endOfLine | lf | - Then I should have files in "" - | .gitignore | - | .gitattributes | - | .editorconfig | - | .eslintignore | - | README.md | And I should not have files in "" | .lintstagedrc.js | | .prettierignore | | .prettierrc | - | package.json | And I should not have files in ".husky" | pre-commit | diff --git a/src/test/features/mariadb.feature b/src/test/features/mariadb.feature index cc476a126cb..e95a3289eb2 100644 --- a/src/test/features/mariadb.feature +++ b/src/test/features/mariadb.feature @@ -21,10 +21,10 @@ Feature: MariaDB module Scenario: Should get MariaDB module properties definition When I get module "mariadb" properties definition Then I should have properties definitions - | Key | Type | Mandatory | - | packageName | STRING | true | - | baseName | STRING | true | - | prettierDefaultIndent | INTEGER | false | + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | indentSize | INTEGER | false | Scenario: Should add MariaDB elements using module url When I apply "mariadb" module to default project with maven file diff --git a/src/test/features/modules.feature b/src/test/features/modules.feature index bdcdba0c1fb..17366a04aa2 100644 --- a/src/test/features/modules.feature +++ b/src/test/features/modules.feature @@ -21,4 +21,4 @@ Feature: Modules Then I should have landscape level 0 with elements | Type | Slug | | MODULE | infinitest-filters | - | FEATURE | startup | + | MODULE | init | diff --git a/src/test/features/mssql.feature b/src/test/features/mssql.feature index be5fc43a787..3c3fcf82c22 100644 --- a/src/test/features/mssql.feature +++ b/src/test/features/mssql.feature @@ -25,7 +25,7 @@ Feature: mssql module Scenario: Should get MsSQL module properties definition When I get module "mssql" properties definition Then I should have properties definitions - | Key | Type | Mandatory | - | packageName | STRING | true | - | baseName | STRING | true | - | prettierDefaultIndent | INTEGER | false | + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | indentSize | INTEGER | false | diff --git a/src/test/features/mysql.feature b/src/test/features/mysql.feature index 8296a2cffe8..4f239d1fb26 100644 --- a/src/test/features/mysql.feature +++ b/src/test/features/mysql.feature @@ -21,10 +21,10 @@ Feature: MySQL module Scenario: Should get MySQL module properties definition When I get module "mysql" properties definition Then I should have properties definitions - | Key | Type | Mandatory | - | packageName | STRING | true | - | baseName | STRING | true | - | prettierDefaultIndent | INTEGER | false | + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | indentSize | INTEGER | false | Scenario: Should add MySQL elements using module url When I apply "mysql" module to default project with maven file diff --git a/src/test/features/postgresql.feature b/src/test/features/postgresql.feature index b9de60177ec..5a55057153b 100644 --- a/src/test/features/postgresql.feature +++ b/src/test/features/postgresql.feature @@ -24,10 +24,10 @@ Feature: postgreSQL module Scenario: Should get postgreSQL module properties definition When I get module "postgresql" properties definition Then I should have properties definitions - | Key | Type | Mandatory | - | packageName | STRING | true | - | baseName | STRING | true | - | prettierDefaultIndent | INTEGER | false | + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | indentSize | INTEGER | false | Scenario: Should add postgreSQL elements using module url When I apply "postgresql" module to default project with maven file diff --git a/src/test/features/prettier.feature b/src/test/features/prettier.feature new file mode 100644 index 00000000000..f77409e6d47 --- /dev/null +++ b/src/test/features/prettier.feature @@ -0,0 +1,13 @@ +Feature: Prettier + + Scenario: Should prettier from module + When I apply "prettier" module to default project with package json + | packageName | tech.jhipster.chips | + | baseName | jhipster | + | endOfLine | lf | + Then I should have files in "" + | .lintstagedrc.js | + | .prettierignore | + | .prettierrc | + And I should have files in ".husky" + | pre-commit | diff --git a/src/test/java/tech/jhipster/lite/generator/ModulesSteps.java b/src/test/java/tech/jhipster/lite/generator/ModulesSteps.java index e2c35eb5094..862de8eacb3 100644 --- a/src/test/java/tech/jhipster/lite/generator/ModulesSteps.java +++ b/src/test/java/tech/jhipster/lite/generator/ModulesSteps.java @@ -216,7 +216,7 @@ private String buildParameterValue(String value) { } private static void addPackageJsonToProject(String folder) { - addFileToProject(folder, "src/test/resources/projects/node/package.json", "package.json"); + addFileToProject(folder, "src/test/resources/projects/empty-node/package.json", "package.json"); } private static void addPomToProject(String folder) { diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtModuleFactoryTest.java index 80aa4e867dc..3f07c824ae7 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtModuleFactoryTest.java @@ -8,7 +8,6 @@ import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; -import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.ModuleFile; @UnitTest class AngularJwtModuleFactoryTest { diff --git a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java index 1c0a6e235b1..6f231bc57ed 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java @@ -111,10 +111,19 @@ void shouldAddAppFiles() { @Test void shouldRenameJhipsterFiles() { + Project project = tmpProjectWithPackageJsonAndLintStage(); + + svelteDomainService.renameJhipsterFiles(project); + + verify(projectRepository).rename(any(Project.class), anyString(), anyString(), anyString()); + } + + @Test + void shouldNotRenameNotExistingJhipsterFiles() { Project project = tmpProject(); svelteDomainService.renameJhipsterFiles(project); - verify(projectRepository, times(1)).rename(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, never()).rename(any(Project.class), anyString(), anyString(), anyString()); } } diff --git a/src/test/java/tech/jhipster/lite/generator/init/domain/InitModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/init/domain/InitModuleFactoryTest.java index a326f348ef7..b65e2f7d09e 100644 --- a/src/test/java/tech/jhipster/lite/generator/init/domain/InitModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/init/domain/InitModuleFactoryTest.java @@ -1,6 +1,6 @@ package tech.jhipster.lite.generator.init.domain; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.when; import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*; import org.junit.jupiter.api.Test; @@ -13,7 +13,6 @@ import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; -import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.ModuleAsserter; import tech.jhipster.lite.npm.domain.NpmVersion; import tech.jhipster.lite.npm.domain.NpmVersionSource; import tech.jhipster.lite.npm.domain.NpmVersions; @@ -29,38 +28,27 @@ class InitModuleFactoryTest { private InitModuleFactory factory; @Test - void shouldBuildFullModule() { + void shouldBuildModule() { String folder = TestFileUtils.tmpDirForTest(); JHipsterModuleProperties properties = properties(folder); when(npmVersions.get("node", NpmVersionSource.COMMON)).thenReturn(new NpmVersion("16.0.0")); - JHipsterModule module = factory.buildFullModule(properties); + JHipsterModule module = factory.buildModule(properties); - assertMinimalModule(folder, module) - .createFiles(".lintstagedrc.js", ".prettierignore", ".prettierrc") - .createExecutableFiles(".husky/pre-commit") + assertThatModule(module) + .createFile("README.md") + .containing("# Test Project") + .and() + .createFiles(".gitignore", ".gitattributes", ".eslintignore") + .createFile(".editorconfig") + .containing("end_of_line = crlf") + .containing("indent_size = 4") + .and() .createFile("package.json") .containing("test-project") - .containing(nodeDependency("@prettier/plugin-xml")) - .containing(nodeDependency("husky")) - .containing(nodeDependency("lint-staged")) - .containing(nodeDependency("prettier")) - .containing(nodeDependency("prettier-plugin-java")) - .containing(nodeDependency("prettier-plugin-packagejson")) - .containing(nodeScript("prepare", "husky install")) - .containing(nodeScript("prettier:check", "prettier --check \\\"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\\\"")) - .containing(nodeScript("prettier:format", "prettier --write \\\"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\\\"")) - .containing("\"node\": \">=16.0.0\""); - } - - @Test - void shouldBuildMinimalModule() { - String folder = TestFileUtils.tmpDirForTest(); - JHipsterModuleProperties properties = properties(folder); - - JHipsterModule module = factory.buildMinimalModule(properties); - - assertMinimalModule(folder, module); + .containing("Test Project") + .containing("\"node\": \">=16.0.0\"") + .notContaining("scripts"); } private JHipsterModuleProperties properties(String folder) { @@ -68,22 +56,8 @@ private JHipsterModuleProperties properties(String folder) { .propertiesBuilder(folder) .projectBaseName("testProject") .put("projectName", "Test Project") - .put("prettierDefaultIndent", 2) - .put("editorConfigEndOfLine", "lf") - .put("prettierEndOfLine", "lf") + .put("endOfLine", "crlf") + .put("indentSize", 4) .build(); } - - private ModuleAsserter assertMinimalModule(String folder, JHipsterModule module) { - return assertThatModule(module) - .createFile("README.md") - .containing("# Test Project") - .and() - .createFiles(".gitignore", ".gitattributes") - .createFile(".editorconfig") - .containing("end_of_line = lf") - .containing("indent_size = 2") - .and() - .createFiles(".eslintignore"); - } } diff --git a/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java new file mode 100644 index 00000000000..6a784650cf0 --- /dev/null +++ b/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java @@ -0,0 +1,57 @@ +package tech.jhipster.lite.generator.prettier.domain; + +import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import tech.jhipster.lite.TestFileUtils; +import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.JHipsterModulesFixture; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; + +@UnitTest +@ExtendWith(MockitoExtension.class) +class PrettierModuleFactoryTest { + + @InjectMocks + private PrettierModuleFactory factory; + + @Test + void shouldBuildModule() { + String folder = TestFileUtils.tmpDirForTest(); + JHipsterModuleProperties properties = properties(folder); + + JHipsterModule module = factory.buildModule(properties); + + assertThatModuleWithFiles(module, packageJsonFile()) + .createFiles(".lintstagedrc.js", ".prettierignore") + .createFile(".prettierrc") + .containing("tabWidth: 4") + .containing("endOfLine: \"crlf\"") + .and() + .createExecutableFiles(".husky/pre-commit") + .createFile("package.json") + .containing(nodeDependency("@prettier/plugin-xml")) + .containing(nodeDependency("husky")) + .containing(nodeDependency("lint-staged")) + .containing(nodeDependency("prettier")) + .containing(nodeDependency("prettier-plugin-java")) + .containing(nodeDependency("prettier-plugin-packagejson")) + .containing(nodeScript("prepare", "husky install")) + .containing(nodeScript("prettier:check", "prettier --check \\\"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\\\"")) + .containing(nodeScript("prettier:format", "prettier --write \\\"{,src/**/}*.{md,json,yml,html,js,ts,tsx,css,scss,vue,java,xml}\\\"")); + } + + private JHipsterModuleProperties properties(String folder) { + return JHipsterModulesFixture + .propertiesBuilder(folder) + .projectBaseName("testProject") + .put("projectName", "Test Project") + .put("indentSize", 4) + .put("endOfLine", "crlf") + .build(); + } +} diff --git a/src/test/java/tech/jhipster/lite/generator/project/infrastructure/primary/dto/ProjectDTOTest.java b/src/test/java/tech/jhipster/lite/generator/project/infrastructure/primary/dto/ProjectDTOTest.java index a752d9d81db..f74ac912d11 100644 --- a/src/test/java/tech/jhipster/lite/generator/project/infrastructure/primary/dto/ProjectDTOTest.java +++ b/src/test/java/tech/jhipster/lite/generator/project/infrastructure/primary/dto/ProjectDTOTest.java @@ -82,7 +82,7 @@ void shouldConvertToModuleProperties() { private ProjectDTO projectDTO() { return new ProjectDTO() .folder("/tmp/chips") - .generatorJhipster(Map.of(BASE_NAME, "chips", "prettierDefaultIndent", 4, DefaultConfig.PACKAGE_NAME, "base.package")) + .generatorJhipster(Map.of(BASE_NAME, "chips", "indentSize", 4, DefaultConfig.PACKAGE_NAME, "base.package")) .remoteUrl("https://github.com/jhipster/jhipster-lite"); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/apidocumentation/springdoc/domain/SpringdocModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/apidocumentation/springdoc/domain/SpringdocModuleFactoryTest.java index 39f782c6a5f..5aef3d0d07c 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/apidocumentation/springdoc/domain/SpringdocModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/apidocumentation/springdoc/domain/SpringdocModuleFactoryTest.java @@ -9,7 +9,6 @@ import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; -import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.ModuleAsserter; @UnitTest class SpringdocModuleFactoryTest { diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaModuleFactoryTest.java index 79dd1d67bf7..ba5798eebe3 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaModuleFactoryTest.java @@ -15,7 +15,6 @@ import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; -import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.ModuleFile; @UnitTest @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/mongopersistence/domain/DummyMongoDBPersistenceModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/mongopersistence/domain/DummyMongoDBPersistenceModuleFactoryTest.java index 17ba2025765..30f8dd24205 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/mongopersistence/domain/DummyMongoDBPersistenceModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/mongopersistence/domain/DummyMongoDBPersistenceModuleFactoryTest.java @@ -8,7 +8,6 @@ import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; -import tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.ModuleFile; @UnitTest class DummyMongoDBPersistenceModuleFactoryTest { diff --git a/src/test/java/tech/jhipster/lite/module/domain/JHipsterModuleContextTest.java b/src/test/java/tech/jhipster/lite/module/domain/JHipsterModuleContextTest.java index 257c203c898..011106ffaf6 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/JHipsterModuleContextTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/JHipsterModuleContextTest.java @@ -21,12 +21,8 @@ public JHipsterModuleContextTest(LogsSpy logs) { } @Test - void shouldGetDefaultIndentationFromInvalidIndentation() { - Indentation indentation = JHipsterModuleContext - .builder(emptyModuleBuilder()) - .put("prettierDefaultIndent", "dummy") - .build() - .indentation(); + void shouldGetIndentSizeationFromInvalidIndentation() { + Indentation indentation = JHipsterModuleContext.builder(emptyModuleBuilder()).put("indentSize", "dummy").build().indentation(); logs.shouldHave(Level.INFO, "invalid indentation, using default"); assertThat(indentation).isEqualTo(Indentation.DEFAULT); @@ -43,7 +39,7 @@ void shouldGetDefaultContext() { entry("projectName", "JHipster Project"), entry("packageName", "com.mycompany.myapp"), entry("serverPort", 8080), - entry("prettierDefaultIndent", 2) + entry("indentSize", 2) ); } } diff --git a/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java b/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java index ead6138a4f6..0f97cc8de36 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java +++ b/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import tech.jhipster.lite.TestFileUtils; -import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder; import tech.jhipster.lite.module.domain.javabuild.ArtifactId; import tech.jhipster.lite.module.domain.javabuild.GroupId; import tech.jhipster.lite.module.domain.javabuild.command.AddDirectJavaDependency; @@ -42,7 +41,7 @@ public static JHipsterModule module() { .and() .files() .add(from("init/gitignore"), to(".gitignore")) - .addExecutable(from("init/.husky/pre-commit"), to(".husky/pre-commit")) + .addExecutable(from("prettier/.husky/pre-commit"), to(".husky/pre-commit")) .batch(from("server/javatool/base"), to("src/main/java/com/company/myapp/errors")) .addTemplate("Assert.java.mustache") .addTemplate("AssertionException.java.mustache") @@ -218,7 +217,7 @@ public static JHipsterModuleProperties allProperties() { Map.of( "packageName", "tech.jhipster.chips", - "prettierDefaultIndent", + "indentSize", 2, "projectName", "JHipster project", diff --git a/src/test/java/tech/jhipster/lite/module/domain/properties/IndentationTest.java b/src/test/java/tech/jhipster/lite/module/domain/properties/IndentationTest.java index b6c663a2e49..8377844ebb2 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/properties/IndentationTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/properties/IndentationTest.java @@ -10,17 +10,17 @@ class IndentationTest { @Test - void shouldGetDefaultIndentationWithoutIndentation() { + void shouldGetIndentSizeWithoutIndentation() { assertThat(Indentation.from(null)).isEqualTo(Indentation.DEFAULT); } @Test - void shouldGetDefaultIndentationForZeroIndentation() { + void shouldGetIndentSizeForZeroIndentation() { assertThat(Indentation.from(0)).isEqualTo(Indentation.DEFAULT); } @Test - void shouldGetDefaultIndentationForNegativeIndentation() { + void shouldGetIndentSizeForNegativeIndentation() { assertThat(Indentation.from(-1)).isEqualTo(Indentation.DEFAULT); } diff --git a/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleMandatoryReplacementsTest.java b/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleMandatoryReplacementsTest.java index 182c4ae8371..1fbeb4cb7fe 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleMandatoryReplacementsTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleMandatoryReplacementsTest.java @@ -10,7 +10,6 @@ import java.util.Collection; import org.junit.jupiter.api.Test; import tech.jhipster.lite.UnitTest; -import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterProjectFolder; diff --git a/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleOptionalReplacementsTest.java b/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleOptionalReplacementsTest.java index 4fa1b48fa54..774d9c906ca 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleOptionalReplacementsTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/replacement/JHipsterModuleOptionalReplacementsTest.java @@ -10,7 +10,6 @@ import java.util.Collection; import org.junit.jupiter.api.Test; import tech.jhipster.lite.UnitTest; -import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; import tech.jhipster.lite.module.domain.properties.JHipsterProjectFolder; diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesDefinitionTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesDefinitionTest.java index 2bda93c354d..353b6bc6ec9 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesDefinitionTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesDefinitionTest.java @@ -25,7 +25,7 @@ static String json() { "{\"type\":\"INTEGER\",\"mandatory\":true,\"key\":\"mandatoryInteger\",\"order\":0}," + "{\"type\":\"BOOLEAN\",\"mandatory\":false,\"key\":\"optionalBoolean\",\"order\":0}," + "{\"type\":\"STRING\",\"mandatory\":false,\"key\":\"optionalString\",\"order\":0}," + - "{\"type\":\"INTEGER\",\"mandatory\":false,\"key\":\"prettierDefaultIndent\",\"description\":\"Number of spaces in indentation\",\"example\":\"2\",\"order\":500}]}" + "{\"type\":\"INTEGER\",\"mandatory\":false,\"key\":\"indentSize\",\"description\":\"Number of spaces in indentation\",\"example\":\"2\",\"order\":500}]}" ); } } diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesTest.java index 7bb3c95817b..9e55f2e3cfd 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterModulePropertiesTest.java @@ -37,7 +37,7 @@ private static String json() { "commit": true, "parameters": { "packageName": "tech.jhipster.chips", - "prettierDefaultIndent": 2, + "indentSize": 2, "projectName": "JHipster project", "baseName": "jhipster", "optionalString": "optional", diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/TestJHipsterModules.java b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/TestJHipsterModules.java index a7815b5ad90..7c1ee0f03a7 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/TestJHipsterModules.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/TestJHipsterModules.java @@ -1,6 +1,5 @@ package tech.jhipster.lite.module.infrastructure.secondary; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import tech.jhipster.lite.error.domain.Assert; @@ -35,7 +34,7 @@ private static NpmVersions mockedNpmVersion() { } public static void applyInit(Project project) { - applyer().module(initModules.buildFullModule(projectProperties(project))).slug("init").apply(); + applyer().module(initModules.buildModule(projectProperties(project))).slug("init").apply(); } private static JHipsterModuleProperties projectProperties(Project project) { diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java index dae47d82425..09d3c527070 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java @@ -1,7 +1,6 @@ package tech.jhipster.lite.project.infrastructure.secondary; import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static tech.jhipster.lite.project.domain.history.ProjectHistoryFixture.*; diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/ProjectFormattingSteps.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/ProjectFormattingSteps.java index 2b8470188e8..155d9ab8c09 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/ProjectFormattingSteps.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/ProjectFormattingSteps.java @@ -1,6 +1,5 @@ package tech.jhipster.lite.project.infrastructure.secondary; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import io.cucumber.java.en.Then; diff --git a/tests-ci/config/undertow-oauth2.json b/tests-ci/config/undertow-oauth2.json index 33795a8c34d..31fffe88107 100644 --- a/tests-ci/config/undertow-oauth2.json +++ b/tests-ci/config/undertow-oauth2.json @@ -3,7 +3,7 @@ "generator-jhipster": { "projectName": "Beer Project", "baseName": "beer", - "prettierDefaultIndent": 2, + "indentSize": 2, "packageName": "tech.jhipster.beer" }, "provider": null, diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh index 251bf36c2a3..9d33abf8f99 100755 --- a/tests-ci/generate.sh +++ b/tests-ci/generate.sh @@ -35,7 +35,7 @@ callApi() { } spring_boot_mvc() { - callApi "/api/inits/full" + callApi "/api/inits" callApi "/api/build-tools/maven" callApi "/api/developer-tools/github-actions" callApi "/api/servers/java/base" @@ -47,7 +47,7 @@ spring_boot_mvc() { } spring_boot_undertow() { - callApi "/api/inits/full" + callApi "/api/inits" callApi "/api/build-tools/maven" callApi "/api/developer-tools/github-actions" callApi "/api/servers/java/base" @@ -59,7 +59,7 @@ spring_boot_undertow() { } spring_boot() { - callApi "/api/inits/full" + callApi "/api/inits" callApi "/api/build-tools/maven" callApi "/api/developer-tools/github-actions" callApi "/api/servers/java/base"