forked from dossyb/BustinBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.cjs
More file actions
54 lines (45 loc) · 1.68 KB
/
start.cjs
File metadata and controls
54 lines (45 loc) · 1.68 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
// --- BUSTINBOT BOOTSTRAP ---
const { execSync } = require("child_process");
const fs = require("fs");
function run(cmd, allowFail = false) {
console.log(`\n> ${cmd}`);
try {
execSync(cmd, { stdio: "inherit" });
} catch (err) {
if (allowFail) console.warn(`⚠️ Command failed (ignored): ${cmd}`);
else throw err;
}
}
const REPO = "https://github.com/dossyb/BustinBot.git";
const BRANCH = process.env.GIT_BRANCH || "main";
console.log("⚙️ Starting BustinBot startup...");
// --- Pull or clone repo ---
if (!fs.existsSync(".git")) {
console.log("🧭 No .git found — cloning fresh repo...");
run(`git clone -b ${BRANCH} ${REPO} .`);
} else {
console.log("🧹 Resetting existing repo...");
run("git update-index --assume-unchanged start.cjs", true);
run("git reset --hard HEAD", true);
run(`git clean -fdx -e data -e assets -e start.cjs -e .env -e .env.local`, true);
run(`git fetch origin ${BRANCH}`, true);
run(`git reset --hard origin/${BRANCH}`, true);
}
// --- Install dependencies ---
console.log("📦 Installing dependencies...");
run("npm ci");
// --- Clean old build ---
console.log("🧹 Removing old dist folder...");
fs.rmSync("dist", { recursive: true, force: true });
// --- Build the bot ---
console.log("🏗️ Building TypeScript...");
run("npm run build");
// --- Verify data folders ---
if (!fs.existsSync("data")) console.warn("⚠️ Missing /data folder!");
if (!fs.existsSync("assets")) console.warn("⚠️ Missing /assets folder!");
if (!fs.existsSync("dist/index.js")) {
throw new Error("Build completed but dist/index.js was not found.");
}
// --- Launch ---
console.log("🚀 Launching compiled bot...");
run("node dist/index.js");