Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/idlebiz/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ DISCORD_TOKEN=
DISCORD_APPLICATION_ID=

# MongoDB
MONGODB_URI=mongodb://localhost:27017/?replicaSet=rs0
MONGODB_DB=idlebiz
MONGODB_URI=mongodb://localhost:27017/idlebiz?replicaSet=rs0
3 changes: 3 additions & 0 deletions apps/idlebiz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
"cmd:register": "node --env-file=.env dist/register.js",
"cmd:unregister": "node --env-file=.env dist/unregister.js",
"dev": "pnpm build && pnpm start",
"setup": "node --env-file=.env dist/setup.js",
"start": "node --env-file=.env dist/index.js"
},
"dependencies": {
"discord.js": "^14.19.1",
"fast-glob": "^3.3.3",
"mongodb": "^6.16.0",
"ms": "^2.1.3",
"tslib": "^2.8.1",
"zod": "^3.24.3"
},
"devDependencies": {
"@types/ms": "^2.1.0",
"@types/node": "^22.15.2",
"tsc-alias": "^1.8.15",
"typescript": "^5.8.3"
Expand Down
3 changes: 1 addition & 2 deletions apps/idlebiz/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const envSchema = z.object({

// MongoDB
MONGODB_URI: z.string(),
MONGODB_DB: z.string(),
});

const parsed = envSchema.safeParse(process.env);
Expand All @@ -22,7 +21,7 @@ ${parsed.error.errors.map((error) => ` ${error.path}: ${error.message}`).join("
process.exit(1);
}

const secretEnvs: Array<keyof typeof envSchema.shape> = ["DISCORD_TOKEN"];
const secretEnvs: Array<keyof typeof envSchema.shape> = ["DISCORD_TOKEN", "MONGODB_URI"];

for (const secretEnv of secretEnvs) {
delete process.env[secretEnv];
Expand Down
56 changes: 56 additions & 0 deletions apps/idlebiz/src/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { mongo } from "@/lib/mongo";
import type { Building } from "@/lib/types/building";
import type { Material } from "@/lib/types/material";
import ms from "ms";

(async () => {
console.log("Setting up initial data...");

try {
const client = await mongo();
const db = client.db();

const materialsCount = await db.collection("materials").countDocuments();

if (materialsCount === 0) {
const wood: Material = {
name: "Wood",
canonicalName: "wood",
description: "Basic building material produced from the lumber mill.",
baseValue: 0.15,
productionInterval: ms("5s"),
};

await db.collection("materials").insertOne(wood);
} else {
console.log("Materials collection already has data. Skipping insertion.");
}

const buildingsCount = await db.collection("buildings").countDocuments();

if (buildingsCount === 0) {
const lumberMill: Building = {
name: "Lumber Mill",
canonicalName: "lumber_mill",
description: "Produces wood.",
cost: {
cash: 100,
},
output: [
{
material: "wood",
amount: 2,
},
],
};

await db.collection("buildings").insertOne(lumberMill);
} else {
console.log("Buildings collection already has data. Skipping insertion.");
}

console.log("Setup completed successfully!");
} catch (e) {
console.error("Error during setup:", e);
}
})();
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.