-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
90 lines (76 loc) · 2.62 KB
/
setup.js
File metadata and controls
90 lines (76 loc) · 2.62 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
const { execSync } = require("child_process");
const { existsSync, copyFileSync } = require("fs");
let currentStep = "";
let stepNumber = 0;
function run(command, options = {}) {
console.log(`\nRunning: ${command}`);
execSync(command, { stdio: "inherit", shell: true, ...options });
}
async function delay(timeoutSeconds) {
return new Promise((resolve) => {
setTimeout(resolve, timeoutSeconds * 1000);
});
}
function logStep() {
console.log("\n==============================");
console.log(`Step ${++stepNumber}: ${currentStep}`);
console.log("==============================");
}
(async function main() {
try {
currentStep = "Installing dependencies";
logStep();
run("pnpm install");
currentStep = "Setting up environment files";
logStep();
const envFiles = [
"apps/web/.env",
"apps/mobile/.env",
"packages/prisma-db/.env",
"packages/sonarqube/.env",
];
envFiles.forEach((file) => {
const exampleFile = `${file}.example`;
if (!existsSync(file) && existsSync(exampleFile)) {
console.log(`Copying ${exampleFile} → ${file}`);
copyFileSync(exampleFile, file);
} else if (!existsSync(exampleFile)) {
console.warn(`Example file missing: ${exampleFile}, skipping copy`);
} else {
console.log(`${file} already exists, skipping copy`);
}
});
currentStep = "Starting Docker containers";
logStep();
console.log("\nMongoDB:");
run("docker-compose -f apps/api/docker-compose.mongo.yml down -v");
await delay(5);
run("docker-compose -f apps/api/docker-compose.mongo.yml up -d");
console.log("\nPostgreSQL:");
run("docker-compose -f apps/api/docker-compose.pg.yml down -v");
await delay(5);
run("docker-compose -f apps/api/docker-compose.pg.yml up -d");
currentStep = "Running Prisma setup (PostgreSQL)";
logStep();
const prismaDir = "packages/prisma-db";
run("pnpm prisma generate", { cwd: prismaDir });
run("pnpm prisma migrate deploy", { cwd: prismaDir });
currentStep = "Building projects";
logStep();
run("pnpm build");
console.log("Projects built successfully.");
currentStep = "Seeding Database(s)";
logStep();
run("pnpm run db:seed:all", { cwd: "apps/api" });
currentStep = "Setup Complete";
logStep();
console.log(
"All dependencies installed, Docker containers running, Prisma setup done.",
);
console.log("You can now run 'pnpm dev' from the root to start all apps.");
} catch (error) {
console.error(`\nSetup failed at step: ${currentStep}`);
console.error(error.message);
process.exit(1);
}
})();