bgrun 3.12.11 → 3.12.13

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.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/dashboard/app/api/config/[name]/route.ts +1 -1
  3. package/dashboard/app/api/debug/route.ts +1 -1
  4. package/dashboard/app/api/dependencies/route.ts +40 -40
  5. package/dashboard/app/api/deploy/[name]/route.ts +1 -1
  6. package/dashboard/app/api/deploy-all/route.ts +25 -25
  7. package/dashboard/app/api/deps/route.ts +3 -3
  8. package/dashboard/app/api/guard/route.ts +1 -1
  9. package/dashboard/app/api/guard-all/route.ts +1 -1
  10. package/dashboard/app/api/guard-events/route.ts +4 -4
  11. package/dashboard/app/api/history/route.ts +105 -105
  12. package/dashboard/app/api/logs/[name]/route.ts +100 -100
  13. package/dashboard/app/api/logs/rotate/route.ts +2 -2
  14. package/dashboard/app/api/next-port/route.ts +32 -32
  15. package/dashboard/app/api/processes/[name]/route.ts +2 -2
  16. package/dashboard/app/api/processes/route.ts +4 -4
  17. package/dashboard/app/api/restart/[name]/route.ts +2 -2
  18. package/dashboard/app/api/start/route.ts +2 -2
  19. package/dashboard/app/api/stop/[name]/route.ts +2 -2
  20. package/dashboard/app/api/templates/route.ts +46 -46
  21. package/dashboard/app/api/version/route.ts +1 -1
  22. package/dashboard/lib/runtime.ts +49 -0
  23. package/dist/api.js +94 -67
  24. package/dist/deploy.js +1373 -0
  25. package/dist/deps.js +1004 -0
  26. package/dist/index.js +224 -224
  27. package/dist/log-rotation.js +95 -0
  28. package/dist/server.js +1488 -0
  29. package/package.json +2 -17
  30. package/src/api.ts +0 -63
  31. package/src/build.ts +0 -24
  32. package/src/commands/cleanup.ts +0 -141
  33. package/src/commands/details.ts +0 -60
  34. package/src/commands/list.ts +0 -133
  35. package/src/commands/logs.ts +0 -49
  36. package/src/commands/run.ts +0 -217
  37. package/src/commands/watch.ts +0 -223
  38. package/src/config.ts +0 -37
  39. package/src/db.ts +0 -422
  40. package/src/deploy.ts +0 -163
  41. package/src/deps.ts +0 -126
  42. package/src/guard.ts +0 -208
  43. package/src/index.ts +0 -623
  44. package/src/log-rotation.ts +0 -93
  45. package/src/logger.ts +0 -40
  46. package/src/platform.ts +0 -665
  47. package/src/server.ts +0 -217
  48. package/src/table.ts +0 -232
  49. package/src/types.ts +0 -14
  50. package/src/utils.ts +0 -96
@@ -1,93 +0,0 @@
1
- /**
2
- * Log rotation for bgrun process output files.
3
- *
4
- * Ensures log files don't grow unbounded by:
5
- * 1. Truncating on rotation (restart) — keeping last N lines
6
- * 2. Size-based rotation — when file exceeds maxBytes, trim to last N lines
7
- * 3. Periodic rotation check — runs on an interval in the dashboard
8
- */
9
-
10
- import { existsSync, statSync, readFileSync, writeFileSync } from 'fs'
11
-
12
- const DEFAULT_MAX_BYTES = 10 * 1024 * 1024 // 10 MB
13
- const DEFAULT_KEEP_LINES = 5000 // Keep last 5000 lines on rotation
14
- const DEFAULT_CHECK_INTERVAL_MS = 60_000 // Check every 60s
15
-
16
- /** Rotate a single log file if it exceeds maxBytes */
17
- export function rotateLogFile(
18
- filePath: string,
19
- maxBytes: number = DEFAULT_MAX_BYTES,
20
- keepLines: number = DEFAULT_KEEP_LINES,
21
- ): boolean {
22
- try {
23
- if (!existsSync(filePath)) return false
24
-
25
- const stat = statSync(filePath)
26
- if (stat.size <= maxBytes) return false
27
-
28
- // Read file, keep last N lines
29
- const content = readFileSync(filePath, 'utf-8')
30
- const lines = content.split('\n')
31
-
32
- if (lines.length <= keepLines) return false
33
-
34
- const truncated = lines.slice(-keepLines)
35
- const header = `--- [bgrun] Log rotated at ${new Date().toISOString()} (was ${lines.length} lines, ${formatBytes(stat.size)}) ---\n`
36
- writeFileSync(filePath, header + truncated.join('\n'))
37
-
38
- return true
39
- } catch {
40
- return false
41
- }
42
- }
43
-
44
- /** Rotate all log files for all processes */
45
- export function rotateAllLogs(
46
- getProcesses: () => Array<{ name: string; stdout_path: string; stderr_path: string }>,
47
- maxBytes: number = DEFAULT_MAX_BYTES,
48
- keepLines: number = DEFAULT_KEEP_LINES,
49
- ): { rotated: string[]; checked: number } {
50
- const processes = getProcesses()
51
- const rotated: string[] = []
52
- let checked = 0
53
-
54
- for (const proc of processes) {
55
- if (proc.stdout_path) {
56
- checked++
57
- if (rotateLogFile(proc.stdout_path, maxBytes, keepLines)) {
58
- rotated.push(`${proc.name}/stdout`)
59
- }
60
- }
61
- if (proc.stderr_path) {
62
- checked++
63
- if (rotateLogFile(proc.stderr_path, maxBytes, keepLines)) {
64
- rotated.push(`${proc.name}/stderr`)
65
- }
66
- }
67
- }
68
-
69
- return { rotated, checked }
70
- }
71
-
72
- /** Start periodic log rotation */
73
- export function startLogRotation(
74
- getProcesses: () => Array<{ name: string; stdout_path: string; stderr_path: string }>,
75
- intervalMs: number = DEFAULT_CHECK_INTERVAL_MS,
76
- maxBytes: number = DEFAULT_MAX_BYTES,
77
- keepLines: number = DEFAULT_KEEP_LINES,
78
- ): ReturnType<typeof setInterval> {
79
- console.log(`[logs] Log rotation active: max ${formatBytes(maxBytes)}/file, keep ${keepLines} lines, check every ${intervalMs / 1000}s`)
80
-
81
- return setInterval(() => {
82
- const { rotated } = rotateAllLogs(getProcesses, maxBytes, keepLines)
83
- if (rotated.length > 0) {
84
- console.log(`[logs] Rotated ${rotated.length} log(s): ${rotated.join(', ')}`)
85
- }
86
- }, intervalMs)
87
- }
88
-
89
- function formatBytes(bytes: number): string {
90
- if (bytes >= 1_000_000) return `${(bytes / 1_000_000).toFixed(1)}MB`
91
- if (bytes >= 1_000) return `${(bytes / 1_000).toFixed(0)}KB`
92
- return `${bytes}B`
93
- }
package/src/logger.ts DELETED
@@ -1,40 +0,0 @@
1
- import boxen from "boxen";
2
- import chalk from "chalk";
3
-
4
- export function announce(message: string, title?: string) {
5
- console.log(
6
- boxen(message, {
7
- padding: 1,
8
- margin: 1,
9
- borderColor: 'green',
10
- title: title || "bgrun",
11
- titleAlignment: 'center',
12
- borderStyle: 'round'
13
- })
14
- );
15
- }
16
-
17
- /** Custom error class so callers can distinguish bgrun errors from unexpected ones */
18
- export class BgrunError extends Error {
19
- constructor(message: string) {
20
- super(message);
21
- this.name = 'BgrunError';
22
- }
23
- }
24
-
25
- export function error(message: string | Error): never {
26
- const text = message instanceof Error ? (message.stack || message.message) : String(message);
27
- console.error(
28
- boxen(chalk.red(text), {
29
- padding: 1,
30
- margin: 1,
31
- borderColor: 'red',
32
- title: "Error",
33
- titleAlignment: 'center',
34
- borderStyle: 'double'
35
- })
36
- );
37
- // Throw instead of process.exit() — lets dashboard API handlers catch gracefully
38
- // CLI entry point has a top-level catch that calls process.exit(1)
39
- throw new BgrunError(text);
40
- }