bgrun 3.3.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/README.md +720 -0
- package/dashboard/app/api/logs/[name]/route.ts +17 -0
- package/dashboard/app/api/processes/[name]/route.ts +19 -0
- package/dashboard/app/api/processes/route.ts +150 -0
- package/dashboard/app/api/restart/[name]/route.ts +20 -0
- package/dashboard/app/api/start/route.ts +22 -0
- package/dashboard/app/api/stop/[name]/route.ts +16 -0
- package/dashboard/app/api/version/route.ts +8 -0
- package/dashboard/app/globals.css +1135 -0
- package/dashboard/app/layout.tsx +47 -0
- package/dashboard/app/page.client.tsx +554 -0
- package/dashboard/app/page.tsx +130 -0
- package/dist/index.js +1580 -0
- package/examples/bgr-startup.sh +40 -0
- package/package.json +60 -0
- package/src/api.ts +31 -0
- package/src/build.ts +26 -0
- package/src/commands/cleanup.ts +142 -0
- package/src/commands/details.ts +46 -0
- package/src/commands/list.ts +86 -0
- package/src/commands/logs.ts +49 -0
- package/src/commands/run.ts +151 -0
- package/src/commands/watch.ts +223 -0
- package/src/config.ts +37 -0
- package/src/db.ts +115 -0
- package/src/index.ts +349 -0
- package/src/logger.ts +29 -0
- package/src/platform.ts +440 -0
- package/src/schema.ts +2 -0
- package/src/server.ts +24 -0
- package/src/table.ts +230 -0
- package/src/types.ts +27 -0
- package/src/utils.ts +99 -0
- package/src/version.macro.ts +17 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface CommandOptions {
|
|
2
|
+
remoteName: string;
|
|
3
|
+
command?: string;
|
|
4
|
+
directory?: string;
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
configPath?: string;
|
|
7
|
+
action: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
force?: boolean;
|
|
10
|
+
fetch?: boolean;
|
|
11
|
+
stdout?: string;
|
|
12
|
+
stderr?: string;
|
|
13
|
+
dbPath?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ProcessRecord {
|
|
17
|
+
id: number;
|
|
18
|
+
pid: number;
|
|
19
|
+
workdir: string;
|
|
20
|
+
command: string;
|
|
21
|
+
name: string;
|
|
22
|
+
env: string;
|
|
23
|
+
timestamp: string;
|
|
24
|
+
configPath?: string;
|
|
25
|
+
stdout_path: string;
|
|
26
|
+
stderr_path: string;
|
|
27
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
export function parseEnvString(envString: string): Record<string, string> {
|
|
3
|
+
const env: Record<string, string> = {};
|
|
4
|
+
envString.split(",").forEach(pair => {
|
|
5
|
+
const [key, value] = pair.split("=");
|
|
6
|
+
if (key && value) env[key] = value;
|
|
7
|
+
});
|
|
8
|
+
return env;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function calculateRuntime(startTime: string): string {
|
|
13
|
+
const start = new Date(startTime).getTime();
|
|
14
|
+
const now = new Date().getTime();
|
|
15
|
+
const diffInMinutes = Math.floor((now - start) / (1000 * 60));
|
|
16
|
+
return `${diffInMinutes} minutes`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Re-export specific utils from platform if they are used as generic utils
|
|
20
|
+
export { isProcessRunning } from "./platform";
|
|
21
|
+
|
|
22
|
+
import * as fs from "fs";
|
|
23
|
+
import { join } from "path";
|
|
24
|
+
import chalk from "chalk";
|
|
25
|
+
|
|
26
|
+
// Read version at runtime instead of using macros (macros crash on Windows)
|
|
27
|
+
export async function getVersion(): Promise<string> {
|
|
28
|
+
try {
|
|
29
|
+
const pkgPath = join(import.meta.dir, '../package.json');
|
|
30
|
+
const pkg = await Bun.file(pkgPath).json();
|
|
31
|
+
return pkg.version || '0.0.0';
|
|
32
|
+
} catch {
|
|
33
|
+
return '0.0.0';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export function validateDirectory(directory: string) {
|
|
39
|
+
if (!directory || !fs.existsSync(directory)) {
|
|
40
|
+
console.log(chalk.red("❌ Error: 'directory' must be a valid path."));
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function tailFile(path: string, prefix: string, colorFn: (s: string) => string, lines?: number): () => void {
|
|
46
|
+
let position = 0;
|
|
47
|
+
let lastPartial = '';
|
|
48
|
+
// Check if file exists first? The original code did fs.openSync which throws if not exist.
|
|
49
|
+
// Assuming caller checks persistence or we catch.
|
|
50
|
+
|
|
51
|
+
if (!fs.existsSync(path)) {
|
|
52
|
+
return () => { };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fd = fs.openSync(path, 'r');
|
|
56
|
+
|
|
57
|
+
const printNewContent = () => {
|
|
58
|
+
try {
|
|
59
|
+
const stats = fs.statSync(path);
|
|
60
|
+
if (stats.size <= position) return;
|
|
61
|
+
|
|
62
|
+
const buffer = Buffer.alloc(stats.size - position);
|
|
63
|
+
fs.readSync(fd, buffer, 0, buffer.length, position);
|
|
64
|
+
|
|
65
|
+
let content = buffer.toString();
|
|
66
|
+
content = lastPartial + content;
|
|
67
|
+
lastPartial = '';
|
|
68
|
+
|
|
69
|
+
const lineArray = content.split(/\r?\n/);
|
|
70
|
+
if (!content.endsWith('\n')) {
|
|
71
|
+
lastPartial = lineArray.pop() || '';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
lineArray.forEach(line => {
|
|
75
|
+
if (line) {
|
|
76
|
+
console.log(colorFn(prefix + line));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
position = stats.size;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
// ignore read errors
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const watcher = fs.watch(path, { persistent: true }, (event) => {
|
|
87
|
+
if (event === 'change') {
|
|
88
|
+
printNewContent();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
printNewContent(); // Check immediately
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
watcher.close();
|
|
96
|
+
try { fs.closeSync(fd); } catch { }
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { file } from 'bun';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reads the project's version from package.json at build time.
|
|
6
|
+
* The returned value is directly inlined into the bundle.
|
|
7
|
+
*/
|
|
8
|
+
export async function getVersion(): Promise<string> {
|
|
9
|
+
try {
|
|
10
|
+
const pkgPath = join(import.meta.dir, '../package.json');
|
|
11
|
+
const pkg = await file(pkgPath).json();
|
|
12
|
+
return pkg.version || '0.0.0';
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("Failed to read version from package.json during build:", err);
|
|
15
|
+
return '0.0.0-error';
|
|
16
|
+
}
|
|
17
|
+
}
|