-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split init & init-minimal to have a prettier module
Fix #3224
- Loading branch information
Showing
56 changed files
with
279 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...in/java/tech/jhipster/lite/generator/prettier/application/PrettierApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../jhipster/lite/generator/prettier/infrastructure/primary/PrettierModuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.