-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(client): factorize some code that allow patching eslint conf…
…ig, ts config and vitest config
- Loading branch information
Showing
8 changed files
with
131 additions
and
63 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
29 changes: 29 additions & 0 deletions
29
src/main/java/tech/jhipster/lite/generator/typescript/common/domain/EslintShortcuts.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,29 @@ | ||
package tech.jhipster.lite.generator.typescript.common.domain; | ||
|
||
import static tech.jhipster.lite.module.domain.JHipsterModule.lineAfterRegex; | ||
import static tech.jhipster.lite.module.domain.JHipsterModule.path; | ||
|
||
import java.util.function.Consumer; | ||
import tech.jhipster.lite.module.domain.Indentation; | ||
import tech.jhipster.lite.module.domain.JHipsterModule; | ||
import tech.jhipster.lite.module.domain.replacement.MandatoryReplacer; | ||
|
||
public final class EslintShortcuts { | ||
|
||
private EslintShortcuts() {} | ||
|
||
public static Consumer<JHipsterModule.JHipsterModuleBuilder> eslintTypescriptRule(String rule, Indentation indentation) { | ||
//@formatter:off | ||
return moduleBuilder -> moduleBuilder | ||
.mandatoryReplacements() | ||
.in(path("eslint.config.js")) | ||
.add(eslintTypescriptVueRuleReplacement(rule, indentation)) | ||
.and() | ||
.and(); | ||
//@formatter:on | ||
} | ||
|
||
private static MandatoryReplacer eslintTypescriptVueRuleReplacement(String rule, Indentation indentation) { | ||
return new MandatoryReplacer(lineAfterRegex("rules: \\{"), indentation.times(3) + rule + ","); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/tech/jhipster/lite/generator/typescript/common/domain/TsConfigShortcuts.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,33 @@ | ||
package tech.jhipster.lite.generator.typescript.common.domain; | ||
|
||
import static tech.jhipster.lite.module.domain.JHipsterModule.lineAfterRegex; | ||
import static tech.jhipster.lite.module.domain.JHipsterModule.path; | ||
|
||
import java.util.function.Consumer; | ||
import tech.jhipster.lite.module.domain.Indentation; | ||
import tech.jhipster.lite.module.domain.JHipsterModule; | ||
import tech.jhipster.lite.module.domain.replacement.MandatoryReplacer; | ||
|
||
public final class TsConfigShortcuts { | ||
|
||
private TsConfigShortcuts() {} | ||
|
||
public static Consumer<JHipsterModule.JHipsterModuleBuilder> tsConfigCompilerOption( | ||
String optionName, | ||
boolean optionValue, | ||
Indentation indentation | ||
) { | ||
//@formatter:off | ||
return moduleBuilder -> moduleBuilder | ||
.mandatoryReplacements() | ||
.in(path("tsconfig.json")) | ||
.add(tsConfigCompilerOptionReplacement(optionName, optionValue, indentation)) | ||
.and(); | ||
//@formatter:on | ||
} | ||
|
||
private static MandatoryReplacer tsConfigCompilerOptionReplacement(String optionName, boolean optionValue, Indentation indentation) { | ||
String compilerOption = indentation.times(2) + "\"%s\": %s,".formatted(optionName, optionValue); | ||
return new MandatoryReplacer(lineAfterRegex("\"compilerOptions\":"), compilerOption); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/tech/jhipster/lite/generator/typescript/common/domain/VitestShortcuts.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,29 @@ | ||
package tech.jhipster.lite.generator.typescript.common.domain; | ||
|
||
import static tech.jhipster.lite.module.domain.JHipsterModule.path; | ||
import static tech.jhipster.lite.module.domain.JHipsterModule.text; | ||
|
||
import java.util.function.Consumer; | ||
import tech.jhipster.lite.module.domain.JHipsterModule; | ||
import tech.jhipster.lite.module.domain.replacement.MandatoryReplacer; | ||
|
||
public final class VitestShortcuts { | ||
|
||
private VitestShortcuts() {} | ||
|
||
public static Consumer<JHipsterModule.JHipsterModuleBuilder> vitestCoverageExclusion(String exclusionFilePattern) { | ||
//@formatter:off | ||
return moduleBuilder -> moduleBuilder | ||
.mandatoryReplacements() | ||
.in(path("vitest.config.ts")) | ||
.add(vitestCoverageExclusionReplacement(exclusionFilePattern)); | ||
//@formatter:on | ||
} | ||
|
||
private static MandatoryReplacer vitestCoverageExclusionReplacement(String filePattern) { | ||
return new MandatoryReplacer( | ||
text("(configDefaults.coverage.exclude as string[])"), | ||
"(configDefaults.coverage.exclude as string[])" + ", '%s'".formatted(filePattern) | ||
); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/tech/jhipster/lite/generator/typescript/common/package-info.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,2 @@ | ||
@tech.jhipster.lite.SharedKernel | ||
package tech.jhipster.lite.generator.typescript.common; |
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