Skip to content

Commit

Permalink
Merge pull request #10878 from murdos/extensible-npm-version-source
Browse files Browse the repository at this point in the history
Extensible npm version source
  • Loading branch information
murdos authored Sep 17, 2024
2 parents 0134b7c + 00d52bf commit cacaf7e
Show file tree
Hide file tree
Showing 36 changed files with 246 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tech.jhipster.lite.generator.client.angular.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.ANGULAR;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.ANGULAR;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;

import tech.jhipster.lite.module.domain.Indentation;
import tech.jhipster.lite.module.domain.JHipsterModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package tech.jhipster.lite.generator.client.angular.security.oauth2.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.ANGULAR;

import java.util.regex.Pattern;
import tech.jhipster.lite.module.domain.Indentation;
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.packagejson.VersionSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.module.domain.replacement.ElementReplacer;
import tech.jhipster.lite.module.domain.replacement.RegexReplacer;
Expand Down Expand Up @@ -114,7 +114,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
.packageJson()
.addDependency(packageName("keycloak-js"), VersionSource.ANGULAR)
.addDependency(packageName("keycloak-js"), ANGULAR)
.and()
.files()
.batch(SOURCE.append("auth"), APP_DESTINATION.append("auth"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tech.jhipster.lite.generator.client.react.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.REACT;
import static tech.jhipster.lite.module.domain.packagejson.NodeModuleFormat.MODULE;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.REACT;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package tech.jhipster.lite.generator.client.react.i18n.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.REACT;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.packagejson.VersionSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

Expand All @@ -23,10 +24,10 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
.packageJson()
.addDependency(packageName("i18next"), VersionSource.COMMON)
.addDependency(packageName("i18next-browser-languagedetector"), VersionSource.COMMON)
.addDependency(packageName("i18next-http-backend"), VersionSource.COMMON)
.addDependency(packageName("react-i18next"), VersionSource.REACT)
.addDependency(packageName("i18next"), COMMON)
.addDependency(packageName("i18next-browser-languagedetector"), COMMON)
.addDependency(packageName("i18next-http-backend"), COMMON)
.addDependency(packageName("react-i18next"), REACT)
.and()
.files()
.batch(APP_SOURCE, to(INDEX + "/app"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tech.jhipster.lite.generator.client.react.security.jwt.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.REACT;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.REACT;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tech.jhipster.lite.generator.client.svelte.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.SVELTE;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.SVELTE;

import tech.jhipster.lite.module.domain.Indentation;
import tech.jhipster.lite.module.domain.JHipsterModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package tech.jhipster.lite.generator.client.tools.cypress.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;

import java.util.function.Function;
import java.util.regex.Pattern;
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.packagejson.VersionSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.module.domain.replacement.RegexReplacer;
import tech.jhipster.lite.shared.error.domain.Assert;
Expand Down Expand Up @@ -48,7 +48,7 @@ public JHipsterModule buildComponentTestsModule(JHipsterModuleProperties propert
//@formatter:off
return commonCypressModuleBuilder(properties, CYPRESS_COMPONENT_TESTS, CYPRESS_COMPONENT_TESTS_EXCLUSION)
.packageJson()
.addDevDependency(packageName("start-server-and-test"), VersionSource.COMMON)
.addDevDependency(packageName("start-server-and-test"), COMMON)
.addScript(scriptKey("test:component"), scriptCommand("start-server-and-test start http://localhost:9000 'cypress open --e2e --config-file src/test/webapp/component/cypress-config.ts'"))
.addScript(
scriptKey("test:component:headless"),
Expand Down Expand Up @@ -86,8 +86,8 @@ private static JHipsterModuleBuilder commonCypressModuleBuilder(
//@formatter:off
return moduleBuilder(properties)
.packageJson()
.addDevDependency(packageName("cypress"), VersionSource.COMMON)
.addDevDependency(packageName("eslint-plugin-cypress"), VersionSource.COMMON)
.addDevDependency(packageName("cypress"), COMMON)
.addDevDependency(packageName("eslint-plugin-cypress"), COMMON)
.and()
.files()
.batch(SOURCE, destinationFolder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tech.jhipster.lite.generator.client.tools.playwright.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.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.packagejson.VersionSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

Expand All @@ -23,7 +23,7 @@ public JHipsterModule buildComponentTestsModule(JHipsterModuleProperties propert
//@formatter:off
return commonPlaywrightModuleBuilder(properties, WEBAPP_COMPONENT_TESTS)
.packageJson()
.addDevDependency(packageName("start-server-and-test"), VersionSource.COMMON)
.addDevDependency(packageName("start-server-and-test"), COMMON)
.addScript(scriptKey("test:component"), scriptCommand("start-server-and-test start http://localhost:9000 'playwright test --ui --config src/test/webapp/component/playwright.config.ts'"))
.addScript(scriptKey("test:component:headless"), scriptCommand("start-server-and-test start http://localhost:9000 'playwright test --config src/test/webapp/component/playwright.config.ts'"))
.and()
Expand Down Expand Up @@ -59,7 +59,7 @@ private static JHipsterModuleBuilder commonPlaywrightModuleBuilder(
//@formatter:off
return moduleBuilder(properties)
.packageJson()
.addDevDependency(packageName("@playwright/test"), VersionSource.COMMON)
.addDevDependency(packageName("@playwright/test"), COMMON)
.and()
.files()
.add(SOURCE.template("playwright.config.ts"), destinationFolder.append("playwright.config.ts"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tech.jhipster.lite.generator.client.vue.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.VUE;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.VUE;
import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.notContainingReplacement;

import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.jhipster.lite.generator.init.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.gradleplugin.GradleMainBuildPlugin;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin;
import tech.jhipster.lite.module.domain.npm.NpmVersionSource;
import tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource;
import tech.jhipster.lite.module.domain.npm.NpmVersions;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;
Expand All @@ -33,7 +33,7 @@ public JHipsterModule buildFrontendMavenModule(JHipsterModuleProperties properti
return commonModuleFiles(properties)
.javaBuildProperties()
.set(buildPropertyKey("node.version"), buildPropertyValue("v" + npmVersions.nodeVersion().get()))
.set(buildPropertyKey("npm.version"), buildPropertyValue(npmVersions.get("npm", NpmVersionSource.COMMON).get()))
.set(buildPropertyKey("npm.version"), buildPropertyValue(npmVersions.get("npm", JHLiteNpmVersionSource.COMMON).get()))
.and()
.mavenPlugins()
.plugin(checksumPlugin())
Expand Down Expand Up @@ -169,7 +169,7 @@ public JHipsterModule buildFrontendGradleModule(JHipsterModuleProperties propert
return commonModuleFiles(properties)
.javaBuildProperties()
.set(buildPropertyKey("node.version.value"), buildPropertyValue(npmVersions.nodeVersion().get()))
.set(buildPropertyKey("npm.version.value"), buildPropertyValue(npmVersions.get("npm", NpmVersionSource.COMMON).get()))
.set(buildPropertyKey("npm.version.value"), buildPropertyValue(npmVersions.get("npm", JHLiteNpmVersionSource.COMMON).get()))
.and()
.gradlePlugins()
.plugin(frontendGradlePlugin())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.jhipster.lite.generator.server.springboot.thymeleaf.template.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;

import java.util.regex.Pattern;
import tech.jhipster.lite.module.domain.JHipsterModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tech.jhipster.lite.generator.typescript.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.packagejson.NodeModuleFormat.MODULE;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tech.jhipster.lite.module.domain.npm;

/**
* {@link NpmVersionSource} that are handled by JHipster Lite.
*/
public enum JHLiteNpmVersionSource implements NpmVersionSourceFactory {
COMMON("common"),
ANGULAR("angular"),
REACT("react"),
SVELTE("svelte"),
VUE("vue");

private final String source;

JHLiteNpmVersionSource(String source) {
this.source = source;
}

@Override
public NpmVersionSource build() {
return new NpmVersionSource(source);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tech.jhipster.lite.module.domain.npm;

import tech.jhipster.lite.shared.error.domain.Assert;
import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage;

public record NpmPackageVersion(String version) {
public NpmPackageVersion {
Expand All @@ -14,4 +15,10 @@ public String get() {
public String majorVersion() {
return version().split("\\.")[0];
}

@Override
@ExcludeFromGeneratedCodeCoverage
public String toString() {
return version;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package tech.jhipster.lite.module.domain.npm;

public enum NpmVersionSource {
COMMON,
ANGULAR,
REACT,
SVELTE,
VUE,
import tech.jhipster.lite.shared.error.domain.Assert;

public record NpmVersionSource(String name) {
public NpmVersionSource {
Assert.notBlank("name", name);
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tech.jhipster.lite.module.domain.npm;

@FunctionalInterface
public interface NpmVersionSourceFactory {
NpmVersionSource build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,25 @@ default NpmPackageVersion get(String packageName, NpmVersionSource source) {
return get(new NpmPackageName(packageName), source);
}

/**
* Get the npm package version from the given source
*
* @param packageName
* name of the package to get the version for
* @param source
* source folder for this version
* @return The version
* @throws UnknownNpmPackageException
* is the package can't be found in source
*/
default NpmPackageVersion get(String packageName, NpmVersionSourceFactory source) {
return get(packageName, source.build());
}

/**
* @return The version of Node.js.
*/
default NpmPackageVersion nodeVersion() {
return get("node", NpmVersionSource.COMMON);
return get("node", JHLiteNpmVersionSource.COMMON.build());
}
}
Loading

0 comments on commit cacaf7e

Please sign in to comment.