@absolutejs/absolute 0.13.0 → 0.13.1
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.d.ts +2 -0
- package/dist/cli/index.js +84 -0
- package/package.json +6 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/cli/index.ts
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
var COMPOSE_PATH = "db/docker-compose.db.yml";
|
|
8
|
+
var DEFAULT_SERVER_ENTRY = "src/backend/server.ts";
|
|
9
|
+
var readDbScripts = async () => {
|
|
10
|
+
const pkgPath = resolve("package.json");
|
|
11
|
+
if (!existsSync(pkgPath))
|
|
12
|
+
return null;
|
|
13
|
+
const pkg = await Bun.file(pkgPath).json();
|
|
14
|
+
const upCommand = pkg.scripts?.["db:up"];
|
|
15
|
+
const downCommand = pkg.scripts?.["db:down"];
|
|
16
|
+
if (!upCommand || !downCommand)
|
|
17
|
+
return null;
|
|
18
|
+
return { upCommand, downCommand };
|
|
19
|
+
};
|
|
20
|
+
var execCommand = async (command) => {
|
|
21
|
+
const args = command.split(" ");
|
|
22
|
+
const proc = Bun.spawn(args, {
|
|
23
|
+
stdin: "inherit",
|
|
24
|
+
stdout: "inherit",
|
|
25
|
+
stderr: "inherit"
|
|
26
|
+
});
|
|
27
|
+
return proc.exited;
|
|
28
|
+
};
|
|
29
|
+
var startDatabase = async (scripts) => {
|
|
30
|
+
console.log("Starting database container...");
|
|
31
|
+
const exitCode = await execCommand(scripts.upCommand);
|
|
32
|
+
if (exitCode !== 0)
|
|
33
|
+
process.exit(exitCode);
|
|
34
|
+
};
|
|
35
|
+
var stopDatabase = async (scripts) => {
|
|
36
|
+
console.log(`
|
|
37
|
+
Stopping database container...`);
|
|
38
|
+
try {
|
|
39
|
+
await execCommand(scripts.downCommand);
|
|
40
|
+
} catch {
|
|
41
|
+
console.error("Failed to stop database container");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var dev = async (serverEntry) => {
|
|
45
|
+
const usesDocker = existsSync(resolve(COMPOSE_PATH));
|
|
46
|
+
const scripts = usesDocker ? await readDbScripts() : null;
|
|
47
|
+
if (scripts)
|
|
48
|
+
await startDatabase(scripts);
|
|
49
|
+
const server = Bun.spawn(["bun", "--watch", serverEntry], {
|
|
50
|
+
stdin: "inherit",
|
|
51
|
+
stdout: "inherit",
|
|
52
|
+
stderr: "inherit"
|
|
53
|
+
});
|
|
54
|
+
let cleaning = false;
|
|
55
|
+
const cleanup = async () => {
|
|
56
|
+
if (cleaning)
|
|
57
|
+
return;
|
|
58
|
+
cleaning = true;
|
|
59
|
+
server.kill();
|
|
60
|
+
await server.exited;
|
|
61
|
+
if (scripts)
|
|
62
|
+
await stopDatabase(scripts);
|
|
63
|
+
process.exit(0);
|
|
64
|
+
};
|
|
65
|
+
process.on("SIGINT", cleanup);
|
|
66
|
+
process.on("SIGTERM", cleanup);
|
|
67
|
+
const exitCode = await server.exited;
|
|
68
|
+
if (!cleaning && scripts)
|
|
69
|
+
await stopDatabase(scripts);
|
|
70
|
+
if (!cleaning)
|
|
71
|
+
process.exit(exitCode);
|
|
72
|
+
};
|
|
73
|
+
var command = process.argv[2];
|
|
74
|
+
if (command === "dev") {
|
|
75
|
+
const serverEntry = process.argv[3] ?? DEFAULT_SERVER_ENTRY;
|
|
76
|
+
await dev(serverEntry);
|
|
77
|
+
} else {
|
|
78
|
+
const message = command ? `Unknown command: ${command}` : "No command specified";
|
|
79
|
+
console.error(message);
|
|
80
|
+
console.error("Usage: absolutejs <command>");
|
|
81
|
+
console.error("Commands:");
|
|
82
|
+
console.error(" dev [entry] Start development server");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Alex Kahn",
|
|
3
|
+
"bin": {
|
|
4
|
+
"absolutejs": "./dist/cli/index.js"
|
|
5
|
+
},
|
|
3
6
|
"description": "A fullstack meta-framework for building web applications with TypeScript",
|
|
4
7
|
"devDependencies": {
|
|
5
8
|
"@elysiajs/static": "1.3.0",
|
|
@@ -41,10 +44,10 @@
|
|
|
41
44
|
"url": "https://github.com/absolutejs/absolutejs.git"
|
|
42
45
|
},
|
|
43
46
|
"scripts": {
|
|
44
|
-
"build": "rm -rf dist && bun build src/index.ts --outdir dist --sourcemap --target=bun --external react --external react-dom --external vue --external @vue/compiler-sfc --external svelte --external elysia && tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
47
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --sourcemap --target=bun --external react --external react-dom --external vue --external @vue/compiler-sfc --external svelte --external elysia && bun build src/cli/index.ts --outfile dist/cli/index.js --target=bun && tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
45
48
|
"db:push": "drizzle-kit push",
|
|
46
49
|
"db:studio": "drizzle-kit studio",
|
|
47
|
-
"dev": "bun
|
|
50
|
+
"dev": "bun src/cli/index.ts dev example/server.ts",
|
|
48
51
|
"format": "prettier --write \"./**/*.{js,jsx,ts,tsx,css,json,mjs,md,svelte,html,vue}\"",
|
|
49
52
|
"lint": "eslint ./",
|
|
50
53
|
"release": "bun run format && bun run build && bun publish",
|
|
@@ -52,5 +55,5 @@
|
|
|
52
55
|
"typecheck": "bun run tsc --noEmit"
|
|
53
56
|
},
|
|
54
57
|
"types": "./dist/index.d.ts",
|
|
55
|
-
"version": "0.13.
|
|
58
|
+
"version": "0.13.1"
|
|
56
59
|
}
|