forked from Mr-DaZ/JavaWorkshop-GameServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
117 lines (91 loc) · 4.25 KB
/
Copy pathsetup.js
File metadata and controls
117 lines (91 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# !/usr/bin/env node
// setup.js -- one-time dependency installation for local development
// Run once after cloning: node setup.js
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const REPO_ROOT = __dirname;
const GREEN = "\x1b[32m";
const YELLOW = "\x1b[33m";
const RED = "\x1b[31m";
const CYAN = "\x1b[36m";
const RESET = "\x1b[0m";
const ok = (msg) => console.log(`${GREEN}[ok] ${RESET}${msg}`);
const warn = (msg) => console.log(`${YELLOW}[warn] ${RESET}${msg}`);
const fail = (msg) => { console.error(`${RED}[error]${RESET} ${msg}`); process.exit(1); };
const run = (cmd, cwd = REPO_ROOT) => execSync(cmd, { cwd, stdio: "inherit" });
console.log();
console.log(`${CYAN}JavaWorkshop -- setup${RESET}`);
console.log(`${CYAN}---------------------${RESET}`);
console.log();
// -- Prerequisites ------------------------------------------------------------
const check = (cmd) => { try { execSync(`${cmd} --version`, { stdio: "pipe" }); return true; } catch { return false; } };
if (!check("java")) fail("Java 21+ not found. Install from <https://adoptium.net>");
if (!check("mvn")) fail("Maven not found. Install from <https://maven.apache.org>");
if (!check("node")) fail("Node.js 20+ not found. Install from <https://nodejs.org>");
if (!check("npm")) fail("npm not found (should ship with Node).");
if (!check("docker")) warn("Docker not found -- you will need MySQL and ActiveMQ running locally.");
try {
const raw = execSync("java -version 2>&1", { shell: true }).toString()
|| execSync("java -version", { stdio: ["pipe", "pipe", "pipe"] }).toString();
const match = raw.match(/version "(\d+)/);
if (match && parseInt(match[1]) < 21) warn(`Java 21 recommended (found version ${match[1]})`);
} catch { /*version check is best-effort*/ }
try {
const raw = execSync("node --version", { stdio: "pipe" }).toString().trim();
const match = raw.match(/^v(\d+)/);
if (match && parseInt(match[1]) < 20) warn(`Node.js 20+ required (found ${raw}) — upgrade at https://nodejs.org`);
} catch { /*version check is best-effort*/ }
ok("Prerequisites look good");
console.log();
// -- .env ---------------------------------------------------------------------
const envFile = path.join(REPO_ROOT, ".env");
const envExample = path.join(REPO_ROOT, ".env.example");
if (!fs.existsSync(envFile)) {
fs.copyFileSync(envExample, envFile);
ok("Created .env from .env.example -- review and set DB_PASSWORD before running");
} else {
ok(".env already exists -- skipping");
}
console.log();
// -- Env validation -----------------------------------------------------------
const envVars = {};
fs.readFileSync(envFile, "utf8")
.split("\n")
.forEach((line) => {
line = line.trim();
if (!line || line.startsWith("#")) return;
const idx = line.indexOf("=");
if (idx > 0) {
const key = line.slice(0, idx).trim();
const val = line.slice(idx + 1).trim();
envVars[key] = val;
}
});
const REQUIRED = ["DB_USERNAME", "DB_PASSWORD"];
const missing = REQUIRED.filter((v) => !envVars[v]);
if (envVars["DB_PASSWORD"] === "changeme") {
warn("DB_PASSWORD is still set to the default 'changeme' -- update it in .env before running");
}
if (missing.length > 0) {
fail(`Missing required env variables in .env: ${missing.join(", ")}`);
}
ok("Environment variables look good");
console.log();
// -- Backend ------------------------------------------------------------------
console.log("Building backend (mvn clean install -DskipTests)...");
run("mvn clean install -DskipTests -q", path.join(REPO_ROOT, "backend"));
ok("Backend built");
console.log();
// -- Frontend -----------------------------------------------------------------
console.log("Installing frontend dependencies (npm install)...");
run("npm install --silent", path.join(REPO_ROOT, "frontend"));
ok("Frontend dependencies installed");
console.log();
// -- Done ---------------------------------------------------------------------
console.log(`${GREEN}Setup complete.${RESET}`);
console.log();
console.log("Next steps:");
console.log(" Full stack (Docker): docker compose up --build");
console.log(" Local dev: see README.md -> Local Development");
console.log();