-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjakefile.js
85 lines (73 loc) · 2.66 KB
/
jakefile.js
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
const { spawn } = require("child_process");
desc("This is the default task.");
task("default", function () {
jake.showAllTaskDescriptions();
});
desc("Start the development environment.");
task("dev", async () => {
await asyncSpawn(
"docker compose -f docker-compose.yml -f docker-compose.dev.yml up --renew-anon-volumes"
);
});
// -- PRISMA --
namespace("prisma", function () {
desc("Generate Prisma Client files.");
task("g", async () => {
await asyncSpawn("cd backend && npx prisma generate"); // Generate Prisma Client files on local
await asyncSpawn("docker compose exec backend npx prisma generate"); // Generate Prisma Client files on docker containr
await asyncSpawn("docker compose restart backend");
});
// Migrations
namespace("m", function () {
desc("Automatically generate new Prisma migration.");
task("g", async () => {
await asyncSpawn(
"docker compose exec backend npx prisma migrate dev --create-only"
);
});
desc("Apply the latest Prisma migrations.");
task("m", async () => {
await asyncSpawn("docker compose exec backend npx prisma migrate deploy");
await asyncSpawn("cd backend && npx prisma generate"); // Generate Prisma Client files on local
await asyncSpawn("docker compose exec backend npx prisma generate"); // Generate Prisma Client files on docker containr
await asyncSpawn("docker compose restart backend");
});
desc(
"Check if my database is up to date with my schema file or if i need to create a migration."
);
task("diff", async () => {
await asyncSpawn(
"docker compose exec backend npx prisma migrate diff --from-schema-datasource prisma/schema.prisma --to-schema-datamodel prisma/schema.prisma --script"
);
});
});
});
// ----------------------------------------------
// Helper functions
// ----------------------------------------------
const log = (message) => {
console.log(`\x1b[32m[Jake] - ${message} \x1b[0m`);
};
const asyncSpawn = (command, options) => {
return new Promise((resolve, reject) => {
const childProcess = spawn(command, {
shell: true,
stdio: ["inherit", "inherit", "inherit"],
...options,
});
childProcess.on("exit", (code) => {
if (code !== 0) {
reject(`Child process exited with code ${code}.`);
}
log(`Child process exited with code ${code}.`);
resolve();
});
childProcess.on("error", (error) => {
reject(`Error on process spawn: ${error.message}.`);
});
// Handle the SIGINT signal (Ctrl+C) to stop the child process before exiting
process.on("SIGINT", () => {
childProcess.kill();
});
});
};