diff --git a/.gitignore b/.gitignore index 427f4dd..0a528f5 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ build/ *.mv.db *.trace.db + +src/main/resources/app +/build_system diff --git a/build_system.d b/build_system.d new file mode 100755 index 0000000..fddc227 --- /dev/null +++ b/build_system.d @@ -0,0 +1,41 @@ +#!/usr/bin/env dub +/+ dub.sdl: + dependency "dsh" version="~>1.6.1" ++/ + +/** + * This script will build the Rail Signal Vue app, then bundle it into this + * Spring project's files under src/main/resources/app/, and will then build + * this project into a jar file. + */ +module build_system; + +import dsh; + +const DIST = "./src/main/resources/app"; + +void main(string[] args) { + print("Building RailSignalAPI"); + chdir("railsignal-app"); + print("Building app..."); + runOrQuit("npm run build"); + print("Copying dist to %s", DIST); + chdir(".."); + removeIfExists(DIST); + mkdir(DIST); + copyDir("railsignal-app/dist", DIST); + print("Building API..."); + runOrQuit("mvn clean package spring-boot:repackage"); + print("Build complete!"); + + if (args.length > 1 && args[1] == "run") { + string f = findFile("target", "^.+\\.jar$", false); + if (f == null) { + error("Could not find jar file!"); + } else { + print("Running the program."); + run("java -jar " ~ f); + } + } +} + diff --git a/railsignal-app/deploy_to_spring.d b/railsignal-app/deploy_to_spring.d index c8d43a9..bd136d8 100755 --- a/railsignal-app/deploy_to_spring.d +++ b/railsignal-app/deploy_to_spring.d @@ -8,7 +8,7 @@ const DEST = "../src/main/resources/static"; void main() { print("Deploying Vue app to Spring's /static directory."); - runOrQuit("npm run build"); + runOrQuit("vite build --base=/app/"); rmdirRecurse(DEST); copyDir("./dist", DEST); } diff --git a/railsignal-app/package-lock.json b/railsignal-app/package-lock.json index 6e6691a..0b2610b 100644 --- a/railsignal-app/package-lock.json +++ b/railsignal-app/package-lock.json @@ -17,10 +17,10 @@ "vue-router": "^4.0.14" }, "devDependencies": { - "@vitejs/plugin-vue": "^2.3.1", + "@vitejs/plugin-vue": "^2.3.2", "eslint": "^8.5.0", "eslint-plugin-vue": "^8.2.0", - "vite": "^2.9.5" + "vite": "^2.9.8" } }, "node_modules/@babel/parser": { diff --git a/railsignal-app/package.json b/railsignal-app/package.json index 61184a9..65879a2 100644 --- a/railsignal-app/package.json +++ b/railsignal-app/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vite build", + "build": "vite build --base=/app/ --mode=development", "preview": "vite preview --port 5050", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore" }, @@ -17,9 +17,9 @@ "vue-router": "^4.0.14" }, "devDependencies": { - "@vitejs/plugin-vue": "^2.3.1", + "@vitejs/plugin-vue": "^2.3.2", "eslint": "^8.5.0", "eslint-plugin-vue": "^8.2.0", - "vite": "^2.9.5" + "vite": "^2.9.8" } } diff --git a/railsignal-app/src/components/railsystem/drawing.js b/railsignal-app/src/components/railsystem/drawing.js index c017471..b32f834 100644 --- a/railsignal-app/src/components/railsystem/drawing.js +++ b/railsignal-app/src/components/railsystem/drawing.js @@ -35,7 +35,7 @@ export function drawComponent(ctx, worldTx, component) { } } -function drawSignal(ctx, signal) { +function drawSignal(ctx) { roundedRect(ctx, -0.3, -0.5, 0.6, 1, 0.25); ctx.fillStyle = "black"; ctx.fill(); @@ -44,7 +44,7 @@ function drawSignal(ctx, signal) { ctx.fill(); } -function drawSegmentBoundary(ctx, segmentBoundary) { +function drawSegmentBoundary(ctx) { ctx.fillStyle = `rgb(150, 58, 224)`; ctx.beginPath(); ctx.moveTo(0, -0.5); diff --git a/railsignal-app/src/main.js b/railsignal-app/src/main.js index bca74a2..62748cd 100644 --- a/railsignal-app/src/main.js +++ b/railsignal-app/src/main.js @@ -4,8 +4,9 @@ import App from './App.vue' import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap"; -const app = createApp(App); + const pinia = createPinia(); +const app = createApp(App); app.use(pinia); app.mount('#app') diff --git a/src/main/java/nl/andrewl/railsignalapi/page/IndexPageController.java b/src/main/java/nl/andrewl/railsignalapi/page/IndexPageController.java index 1aabc68..e3cf732 100644 --- a/src/main/java/nl/andrewl/railsignalapi/page/IndexPageController.java +++ b/src/main/java/nl/andrewl/railsignalapi/page/IndexPageController.java @@ -5,10 +5,10 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller -@RequestMapping(path = "/") +@RequestMapping(path = {"/", "/app", "/home", "/index.html", "/index"}) public class IndexPageController { @GetMapping public String getIndex() { - return "index"; + return "forward:/app/index.html"; } } diff --git a/src/main/java/nl/andrewl/railsignalapi/rest/WebConfig.java b/src/main/java/nl/andrewl/railsignalapi/rest/WebConfig.java index 4d55147..1725d16 100644 --- a/src/main/java/nl/andrewl/railsignalapi/rest/WebConfig.java +++ b/src/main/java/nl/andrewl/railsignalapi/rest/WebConfig.java @@ -11,8 +11,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/**") - .addResourceLocations("classpath:/static/"); + // Configure resource handlers to use the /app directory for all vue frontend stuff. + registry.addResourceHandler("/app/**") + .addResourceLocations("classpath:/app/"); } @Override