@absolutejs/absolute 0.13.4 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +29 -12
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli/index.ts
|
|
5
|
+
var {$ } = globalThis.Bun;
|
|
5
6
|
import { existsSync } from "fs";
|
|
6
7
|
import { resolve } from "path";
|
|
7
8
|
var COMPOSE_PATH = "db/docker-compose.db.yml";
|
|
@@ -17,20 +18,36 @@ var readDbScripts = async () => {
|
|
|
17
18
|
return null;
|
|
18
19
|
return { upCommand, downCommand };
|
|
19
20
|
};
|
|
21
|
+
var timed = async (label, fn) => {
|
|
22
|
+
process.stdout.write(label);
|
|
23
|
+
const start = performance.now();
|
|
24
|
+
await fn();
|
|
25
|
+
const duration = ((performance.now() - start) / 1000).toFixed(2);
|
|
26
|
+
process.stdout.write(` \x1B[90m${duration}s\x1B[0m
|
|
27
|
+
`);
|
|
28
|
+
};
|
|
20
29
|
var startDatabase = async (scripts) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
await timed("Starting database container...", async () => {
|
|
31
|
+
const { exitCode } = await $`${{ raw: scripts.upCommand }}`.quiet().nothrow();
|
|
32
|
+
if (exitCode !== 0)
|
|
33
|
+
process.exit(exitCode);
|
|
34
|
+
});
|
|
25
35
|
};
|
|
26
36
|
var stopDatabase = async (scripts) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
await
|
|
37
|
+
process.stdout.write(`
|
|
38
|
+
`);
|
|
39
|
+
await timed("Stopping database container...", async () => {
|
|
40
|
+
await $`${{ raw: scripts.downCommand }}`.quiet().nothrow();
|
|
41
|
+
});
|
|
30
42
|
};
|
|
31
43
|
var dev = async (serverEntry) => {
|
|
32
44
|
const usesDocker = existsSync(resolve(COMPOSE_PATH));
|
|
33
|
-
|
|
45
|
+
let scripts = null;
|
|
46
|
+
if (usesDocker) {
|
|
47
|
+
await timed("Reading db scripts...", async () => {
|
|
48
|
+
scripts = await readDbScripts();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
34
51
|
if (scripts)
|
|
35
52
|
await startDatabase(scripts);
|
|
36
53
|
const server = Bun.spawn(["bun", "--watch", serverEntry], {
|
|
@@ -39,7 +56,7 @@ var dev = async (serverEntry) => {
|
|
|
39
56
|
stderr: "inherit"
|
|
40
57
|
});
|
|
41
58
|
let cleaning = false;
|
|
42
|
-
const cleanup = async (
|
|
59
|
+
const cleanup = async (exitCode = 0) => {
|
|
43
60
|
if (cleaning)
|
|
44
61
|
return;
|
|
45
62
|
cleaning = true;
|
|
@@ -51,12 +68,12 @@ var dev = async (serverEntry) => {
|
|
|
51
68
|
await server.exited;
|
|
52
69
|
if (scripts)
|
|
53
70
|
await stopDatabase(scripts);
|
|
54
|
-
process.exit(
|
|
71
|
+
process.exit(exitCode);
|
|
55
72
|
};
|
|
56
73
|
process.on("SIGINT", () => cleanup(0));
|
|
57
74
|
process.on("SIGTERM", () => cleanup(0));
|
|
58
|
-
|
|
59
|
-
await cleanup(
|
|
75
|
+
await server.exited;
|
|
76
|
+
await cleanup(0);
|
|
60
77
|
};
|
|
61
78
|
var command = process.argv[2];
|
|
62
79
|
if (command === "dev") {
|
package/package.json
CHANGED