Skip to content

Commit

Permalink
breaking: change behavior of text() and regex() methods in JHipsterMo…
Browse files Browse the repository at this point in the history
…dule to not always do the replacement

The previous behavior was a bit unexpected since other replacers shortcuts were doing the replacements conditionally.

Adapted the react-jwt module, the only one that was relying on the previous behavior.
  • Loading branch information
murdos committed Sep 19, 2024
1 parent be0077d commit 203007a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

public class ReactJwtModuleFactory {

private static final String APP = "<App />";

private static final JHipsterSource ROOT = from("client/react/security/jwt");

private static final JHipsterSource SOURCE = ROOT.append("src");
Expand Down Expand Up @@ -86,9 +84,14 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.and()
.in(path("src/main/webapp/app/index.tsx"))
.add(lineBeforeText("import { createRoot } from 'react-dom/client';"), "import { NextUIProvider } from '@nextui-org/react';")
.add(lineBeforeText(APP), properties.indentation().times(2) + "<NextUIProvider>")
.add(lineBeforeText("</React.StrictMode>,"), properties.indentation().times(2) + "</NextUIProvider>")
.add(text(APP), properties.indentation().times(1) + APP)
.add(regex("\\s+<App />"),
"""
\t\t<NextUIProvider>
\t\t\t<App />
\t\t</NextUIProvider>\
""".replace("\t", properties.indentation().spaces())
)
.and()
.in(path("src/main/webapp/app/index.css"))
.add(lineBeforeText("body {"), "@tailwind base;" + LINE_BREAK + "@tailwind components;" + LINE_BREAK + "@tailwind utilities;" + LINE_BREAK)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.jhipster.lite.module.domain;

import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.always;
import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.notContainingReplacement;

import java.nio.file.Paths;
Expand Down Expand Up @@ -250,11 +249,11 @@ public static VersionSlug versionSlug(String versionSlug) {
}

public static TextReplacer text(String text) {
return new TextReplacer(always(), text);
return new TextReplacer(notContainingReplacement(), text);
}

public static RegexReplacer regex(String regex) {
return new RegexReplacer(always(), regex);
return new RegexReplacer(notContainingReplacement(), regex);
}

public static FileStartReplacer fileStart() {
Expand Down

0 comments on commit 203007a

Please sign in to comment.