Skip to content

Commit

Permalink
refactor: move ViteProperties to javite-webmvc
Browse files Browse the repository at this point in the history
  • Loading branch information
benny123tw committed Jun 27, 2024
1 parent 9d535bf commit 0198ccb
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 58 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.1.2
version=0.1.3-alpha
15 changes: 0 additions & 15 deletions javite-core/src/main/java/com/javite/config/package-info.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.javite.spring.config;

import com.javite.config.ViteProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
Expand Down Expand Up @@ -31,6 +31,7 @@
* @see com.javite.spring.annotation.EnableVite
*/
@Configuration
@ComponentScan(basePackages = "com.javite.spring.config")
public class ViteConfig {

@Value("${vite.debug:true}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.javite.config;
package com.javite.spring.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Configuration properties for integrating Vite with Java web applications.
*
* <p>This class provides properties that can be used to configure the Vite integration,
* including settings for the Vite manifest file, local development server URL, resource paths,
* and debug mode.</p>
* including settings for the Vite manifest file, local development server URL, resource paths, and debug mode.</p>
*
* <p>These properties can be configured in the application's configuration file (e.g., `application.properties`
* or `application.yml` for Spring applications) and are typically used by integration modules to
* facilitate the setup and use of Vite in Java web applications.</p>
* or `application.yml` for Spring applications) and are typically used by integration modules to facilitate the setup and use of Vite in Java web
* applications.</p>
*
* <p>Usage example:</p>
* <pre class="code">
Expand All @@ -19,6 +21,8 @@
* vite.resourcePath=/resources
* </pre>
*/
@Component
@ConfigurationProperties(prefix = "vite")
public class ViteProperties {

/**
Expand Down Expand Up @@ -116,4 +120,5 @@ public String getResourcePath() {
public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.javite.spring.tags;

import com.fasterxml.jackson.databind.JsonNode;
import com.javite.config.ViteProperties;
import com.javite.spring.config.ViteProperties;
import com.javite.util.HtmlUtils;
import com.javite.util.ManifestUtils;
import java.io.IOException;
Expand Down
8 changes: 4 additions & 4 deletions javite-webmvc-jre8/src/main/resources/META-INF/vite.tld
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<description>Vite JSP Tag Library</description>
<short-name>vite</short-name>
<tag>
<description>Import a Vite asset.</description>
<name>import</name>
<tag-class>com.javite.spring.tags.ViteImport</tag-class>
<body-content>empty</body-content>
<attribute>
<description>The entry point of the Vite asset to be imported.</description>
<name>entry</name>
Expand Down Expand Up @@ -37,10 +41,6 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<body-content>empty</body-content>
<description>Import a Vite asset.</description>
<name>import</name>
<tag-class>com.javite.spring.tags.ViteImport</tag-class>
</tag>
<tlib-version>1.0</tlib-version>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.javite.spring.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.javite.config.ViteProperties;

/**
* Configuration class for integrating Vite with Spring MVC applications.
Expand All @@ -12,6 +12,7 @@
* {@code application.properties} file.</p>
*/
@Configuration
@EnableConfigurationProperties(ViteProperties.class)
public class ViteConfig {

@Value("${vite.debug:true}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.javite.spring.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Configuration properties for integrating Vite with Java web applications.
*
* <p>This class provides properties that can be used to configure the Vite integration,
* including settings for the Vite manifest file, local development server URL, resource paths, and debug mode.</p>
*
* <p>These properties can be configured in the application's configuration file (e.g., `application.properties`
* or `application.yml` for Spring applications) and are typically used by integration modules to facilitate the setup and use of Vite in Java web
* applications.</p>
*
* <p>Usage example:</p>
* <pre class="code">
* vite.debug=true
* vite.manifestPath=/WEB-INF/dist/.vite/manifest.json
* vite.localServerUrl=http://localhost:5173
* vite.resourcePath=/resources
* </pre>
*/
@Component
@ConfigurationProperties(prefix = "vite")
public class ViteProperties {

/**
* Whether to enable debug mode in Vite.
* <p>Default is {@code true}.</p>
*/
private boolean debug = true;

/**
* The path of the manifest file generated by Vite.
* <p>Default is {@code /WEB-INF/dist/.vite/manifest.json}.</p>
*/
private String manifestPath = "/WEB-INF/dist/.vite/manifest.json";

/**
* The local server URL for Vite development.
* <p>Default is {@code http://localhost:5173}.</p>
*/
private String localServerUrl = "http://localhost:5173";

/**
* The path to the resources.
* <p>Default is {@code /resources}.</p>
*/
private String resourcePath = "/resources";

/**
* Returns whether debug mode is enabled.
*
* @return {@code true} if debug mode is enabled, {@code false} otherwise
*/
public boolean isDebug() {
return debug;
}

/**
* Sets whether debug mode is enabled.
*
* @param debug {@code true} to enable debug mode, {@code false} to disable it
*/
public void setDebug(boolean debug) {
this.debug = debug;
}

/**
* Returns the path of the manifest file generated by Vite.
*
* @return the manifest file path
*/
public String getManifestPath() {
return manifestPath;
}

/**
* Sets the path of the manifest file generated by Vite.
*
* @param manifestPath the manifest file path
*/
public void setManifestPath(String manifestPath) {
this.manifestPath = manifestPath;
}

/**
* Returns the local server URL for Vite development.
*
* @return the local server URL
*/
public String getLocalServerUrl() {
return localServerUrl;
}

/**
* Sets the local server URL for Vite development.
*
* @param localServerUrl the local server URL
*/
public void setLocalServerUrl(String localServerUrl) {
this.localServerUrl = localServerUrl;
}

/**
* Returns the path to the resources.
*
* @return the resource path
*/
public String getResourcePath() {
return resourcePath;
}

/**
* Sets the path to the resources.
*
* @param resourcePath the resource path
*/
public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.javite.spring.tags;

import com.fasterxml.jackson.databind.JsonNode;
import com.javite.config.ViteProperties;
import com.javite.spring.config.ViteProperties;
import com.javite.util.HtmlUtils;
import com.javite.util.ManifestUtils;
import jakarta.servlet.ServletContext;
Expand Down
2 changes: 1 addition & 1 deletion javite-webmvc/src/main/resources/META-INF/vite.tld
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>Vite JSP Tag Library</description>
<tlib-version>1.0</tlib-version>
<short-name>vite</short-name>
<uri>https://javite.com</uri>
<uri>https://javite.com/tags</uri>

<tag>
<description>Import a Vite asset.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.javite.spring.config;

import com.javite.config.ViteProperties;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(classes = ViteConfigTest.TestConfig.class)
public class ViteConfigTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.javite.config.ViteProperties;
import com.javite.spring.config.ViteProperties;
import jakarta.servlet.ServletContext;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
Expand Down

0 comments on commit 0198ccb

Please sign in to comment.