dev-prism 0.4.0 → 0.7.0

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 (98) hide show
  1. package/README.md +180 -131
  2. package/bin/dev-prism.js +77 -97
  3. package/dist/{chunk-7YGOMAJG.js → chunk-3CIXBEXK.js} +22 -28
  4. package/dist/chunk-AHC6CD7F.js +92 -0
  5. package/dist/chunk-FQTS57VO.js +64 -0
  6. package/dist/chunk-GWQPK7MZ.js +50 -0
  7. package/dist/chunk-HDGBJGIH.js +55 -0
  8. package/dist/chunk-ILICQAU7.js +60 -0
  9. package/dist/chunk-IWZN6P6M.js +155 -0
  10. package/dist/chunk-KP56QH72.js +133 -0
  11. package/dist/{chunk-Y3GR6XK7.js → chunk-NJAITOCG.js} +3 -13
  12. package/dist/{chunk-25WQHUYW.js → chunk-TSNFAXVQ.js} +5 -12
  13. package/dist/chunk-VAPRJUC7.js +67 -0
  14. package/dist/chunk-VL56YPMK.js +45 -0
  15. package/dist/commands/claude.js +1 -1
  16. package/dist/commands/create.d.ts +1 -4
  17. package/dist/commands/create.js +5 -7
  18. package/dist/commands/destroy.d.ts +1 -1
  19. package/dist/commands/destroy.js +4 -5
  20. package/dist/commands/env.d.ts +7 -0
  21. package/dist/commands/env.js +9 -0
  22. package/dist/commands/info.js +4 -2
  23. package/dist/commands/list.d.ts +1 -3
  24. package/dist/commands/list.js +2 -5
  25. package/dist/commands/prune.d.ts +1 -1
  26. package/dist/commands/prune.js +2 -5
  27. package/dist/commands/with-env.d.ts +3 -0
  28. package/dist/commands/with-env.js +9 -0
  29. package/dist/index.d.ts +9 -12
  30. package/dist/index.js +58 -56
  31. package/dist/lib/config.d.ts +4 -7
  32. package/dist/lib/config.js +1 -3
  33. package/dist/lib/db.d.ts +26 -0
  34. package/dist/lib/db.js +28 -0
  35. package/dist/lib/env.d.ts +7 -5
  36. package/dist/lib/env.js +9 -9
  37. package/dist/lib/worktree.d.ts +2 -3
  38. package/dist/lib/worktree.js +1 -3
  39. package/package.json +8 -8
  40. package/dist/chunk-35SHBLIZ.js +0 -69
  41. package/dist/chunk-3ATDGV4Y.js +0 -22
  42. package/dist/chunk-3MSC3CGG.js +0 -78
  43. package/dist/chunk-3NW2OWIU.js +0 -78
  44. package/dist/chunk-3TRRZEFR.js +0 -38
  45. package/dist/chunk-4UNCSJRM.js +0 -70
  46. package/dist/chunk-5KDDYO6Y.js +0 -168
  47. package/dist/chunk-63II3EL4.js +0 -98
  48. package/dist/chunk-6YMQTISJ.js +0 -84
  49. package/dist/chunk-AOM6BONB.js +0 -98
  50. package/dist/chunk-AW2FJGXA.js +0 -38
  51. package/dist/chunk-C4WLIOBR.js +0 -67
  52. package/dist/chunk-D6QWWXZD.js +0 -49
  53. package/dist/chunk-FKTFCSU7.js +0 -78
  54. package/dist/chunk-GBN67HYD.js +0 -57
  55. package/dist/chunk-GKXXK2ZH.js +0 -203
  56. package/dist/chunk-GWDGC2OE.js +0 -116
  57. package/dist/chunk-H4HPDIY3.js +0 -95
  58. package/dist/chunk-HCCZKLC4.js +0 -64
  59. package/dist/chunk-HZUN6NRB.js +0 -70
  60. package/dist/chunk-J36LRUXM.js +0 -60
  61. package/dist/chunk-JHR4WADC.js +0 -200
  62. package/dist/chunk-JIU574KX.js +0 -41
  63. package/dist/chunk-KZJE62TK.js +0 -203
  64. package/dist/chunk-LDK6QMR6.js +0 -67
  65. package/dist/chunk-LEHA65A7.js +0 -59
  66. package/dist/chunk-LNIOSGC4.js +0 -78
  67. package/dist/chunk-LOVO4P3Y.js +0 -41
  68. package/dist/chunk-NNVP5F6I.js +0 -77
  69. package/dist/chunk-OL25TBYX.js +0 -67
  70. package/dist/chunk-P3ETW2KK.js +0 -166
  71. package/dist/chunk-PJKUD2N2.js +0 -22
  72. package/dist/chunk-PKC2ZED2.js +0 -168
  73. package/dist/chunk-PS76Q3HD.js +0 -168
  74. package/dist/chunk-QSG5CXPX.js +0 -171
  75. package/dist/chunk-QUMZI5KK.js +0 -98
  76. package/dist/chunk-RC2AUYZ7.js +0 -49
  77. package/dist/chunk-SMFAL2VP.js +0 -69
  78. package/dist/chunk-SSQ7XBY2.js +0 -30
  79. package/dist/chunk-SUMJLXT7.js +0 -30
  80. package/dist/chunk-UHI2QJFI.js +0 -200
  81. package/dist/chunk-VR3QWHHB.js +0 -57
  82. package/dist/chunk-X5A6H4Q7.js +0 -70
  83. package/dist/chunk-X6FHBEAS.js +0 -200
  84. package/dist/chunk-XUWQUDLT.js +0 -67
  85. package/dist/commands/logs.d.ts +0 -8
  86. package/dist/commands/logs.js +0 -8
  87. package/dist/commands/start.d.ts +0 -7
  88. package/dist/commands/start.js +0 -9
  89. package/dist/commands/stop-all.d.ts +0 -3
  90. package/dist/commands/stop-all.js +0 -9
  91. package/dist/commands/stop.d.ts +0 -3
  92. package/dist/commands/stop.js +0 -7
  93. package/dist/lib/docker.d.ts +0 -12
  94. package/dist/lib/docker.js +0 -14
  95. package/dist/lib/ports.d.ts +0 -6
  96. package/dist/lib/ports.js +0 -8
  97. package/dist/lib/store.d.ts +0 -46
  98. package/dist/lib/store.js +0 -6
@@ -1,98 +0,0 @@
1
- import {
2
- removeWorktree
3
- } from "./chunk-Y3GR6XK7.js";
4
- import {
5
- down,
6
- isRunning
7
- } from "./chunk-GBN67HYD.js";
8
- import {
9
- loadConfig
10
- } from "./chunk-25WQHUYW.js";
11
- import {
12
- SessionStore
13
- } from "./chunk-6YMQTISJ.js";
14
-
15
- // src/commands/prune.ts
16
- import { existsSync } from "fs";
17
- import { resolve } from "path";
18
- import { createInterface } from "readline";
19
- import chalk from "chalk";
20
- async function pruneSessions(projectRoot, options) {
21
- const config = await loadConfig(projectRoot);
22
- const store = new SessionStore();
23
- try {
24
- const sessions = store.listByProject(projectRoot);
25
- if (sessions.length === 0) {
26
- console.log(chalk.gray("No sessions found."));
27
- return;
28
- }
29
- const stoppedSessions = [];
30
- for (const session of sessions) {
31
- const envFile = resolve(session.session_dir, ".env.session");
32
- let running = false;
33
- if (existsSync(envFile)) {
34
- running = await isRunning({ cwd: session.session_dir });
35
- }
36
- if (!running) {
37
- stoppedSessions.push({
38
- sessionId: session.session_id,
39
- path: session.session_dir,
40
- branch: session.branch,
41
- inPlace: session.in_place === 1
42
- });
43
- }
44
- }
45
- if (stoppedSessions.length === 0) {
46
- console.log(chalk.gray("No stopped sessions to prune."));
47
- return;
48
- }
49
- console.log(chalk.yellow(`
50
- Found ${stoppedSessions.length} stopped session(s) to prune:`));
51
- for (const session of stoppedSessions) {
52
- console.log(chalk.gray(` - Session ${session.sessionId} (${session.branch})`));
53
- }
54
- console.log("");
55
- if (!options.yes) {
56
- const rl = createInterface({
57
- input: process.stdin,
58
- output: process.stdout
59
- });
60
- const answer = await new Promise((resolve2) => {
61
- rl.question(chalk.red("Are you sure you want to delete these sessions? This cannot be undone. [y/N] "), resolve2);
62
- });
63
- rl.close();
64
- if (answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
65
- console.log(chalk.gray("Cancelled."));
66
- return;
67
- }
68
- }
69
- console.log(chalk.blue("\nPruning stopped sessions...\n"));
70
- for (const session of stoppedSessions) {
71
- console.log(chalk.gray(` Removing session ${session.sessionId}...`));
72
- try {
73
- const envFile = resolve(session.path, ".env.session");
74
- if (existsSync(envFile)) {
75
- try {
76
- await down({ cwd: session.path });
77
- } catch {
78
- }
79
- }
80
- if (!session.inPlace) {
81
- await removeWorktree(projectRoot, session.path, session.branch);
82
- }
83
- store.markDestroyed(projectRoot, session.sessionId);
84
- console.log(chalk.green(` Session ${session.sessionId} removed.`));
85
- } catch {
86
- console.log(chalk.yellow(` Warning: Could not fully remove session ${session.sessionId}`));
87
- }
88
- }
89
- console.log(chalk.green(`
90
- Pruned ${stoppedSessions.length} session(s).`));
91
- } finally {
92
- store.close();
93
- }
94
- }
95
-
96
- export {
97
- pruneSessions
98
- };
@@ -1,49 +0,0 @@
1
- import {
2
- loadConfig
3
- } from "./chunk-25WQHUYW.js";
4
- import {
5
- SessionStore
6
- } from "./chunk-H4HPDIY3.js";
7
-
8
- // src/commands/logs.ts
9
- import chalk from "chalk";
10
- import { execa } from "execa";
11
- async function streamLogs(projectRoot, sessionId, options) {
12
- const config = await loadConfig(projectRoot);
13
- const store = new SessionStore();
14
- let sessionDir;
15
- try {
16
- const session = store.findSession(projectRoot, sessionId);
17
- if (!session) {
18
- console.error(chalk.red(`Error: Session ${sessionId} not found.`));
19
- process.exit(1);
20
- }
21
- sessionDir = session.session_dir;
22
- } finally {
23
- store.close();
24
- }
25
- let profileFlags = [];
26
- if (options.mode === "docker") {
27
- const allApps = config.apps ?? [];
28
- const excludeApps = options.without ?? [];
29
- const profiles = allApps.filter((app) => !excludeApps.includes(app));
30
- profileFlags = profiles.flatMap((p) => ["--profile", p]);
31
- }
32
- const args = [
33
- "compose",
34
- "-f",
35
- "docker-compose.session.yml",
36
- "--env-file",
37
- ".env.session",
38
- ...profileFlags,
39
- "logs",
40
- "-f",
41
- "--tail",
42
- options.tail ?? "50"
43
- ];
44
- await execa("docker", args, { cwd: sessionDir, stdio: "inherit" });
45
- }
46
-
47
- export {
48
- streamLogs
49
- };
@@ -1,69 +0,0 @@
1
- import {
2
- calculatePorts
3
- } from "./chunk-PJKUD2N2.js";
4
- import {
5
- getSessionWorktrees
6
- } from "./chunk-GWDGC2OE.js";
7
- import {
8
- loadConfig
9
- } from "./chunk-25WQHUYW.js";
10
- import {
11
- isRunning
12
- } from "./chunk-VR3QWHHB.js";
13
-
14
- // src/commands/list.ts
15
- import { existsSync } from "fs";
16
- import { resolve } from "path";
17
- import chalk from "chalk";
18
- async function listSessions(projectRoot) {
19
- const config = await loadConfig(projectRoot);
20
- const sessions = await getSessionWorktrees(projectRoot);
21
- if (sessions.length === 0) {
22
- console.log(chalk.gray("No active sessions found."));
23
- console.log(chalk.gray("\nTo create a session:"));
24
- console.log(chalk.cyan(" dev-prism create"));
25
- return;
26
- }
27
- console.log(chalk.blue("Active Sessions:"));
28
- console.log(chalk.gray("================\n"));
29
- for (const session of sessions) {
30
- const status = await getSessionStatus(session.sessionId, session.path, session.branch, config);
31
- printSessionStatus(status);
32
- }
33
- }
34
- async function getSessionStatus(sessionId, path, branch, config) {
35
- const ports = calculatePorts(config, sessionId);
36
- let running = false;
37
- const envFile = resolve(path, ".env.session");
38
- if (existsSync(envFile)) {
39
- running = await isRunning({ cwd: path });
40
- }
41
- return {
42
- sessionId,
43
- path,
44
- branch,
45
- running,
46
- ports
47
- };
48
- }
49
- function printSessionStatus(status) {
50
- const statusIcon = status.running ? chalk.green("\u25CF") : chalk.red("\u25CB");
51
- const statusText = status.running ? chalk.green("running") : chalk.gray("stopped");
52
- console.log(`${statusIcon} Session ${chalk.bold(status.sessionId)} ${statusText}`);
53
- console.log(chalk.gray(` Path: ${status.path}`));
54
- console.log(chalk.gray(` Branch: ${status.branch}`));
55
- console.log(chalk.gray(" Ports:"));
56
- for (const [name, port] of Object.entries(status.ports)) {
57
- const isApp = name.includes("APP") || name.includes("WEB") || name.includes("WIDGET");
58
- if (isApp) {
59
- console.log(chalk.gray(` ${name}: http://localhost:${port}`));
60
- } else {
61
- console.log(chalk.gray(` ${name}: ${port}`));
62
- }
63
- }
64
- console.log("");
65
- }
66
-
67
- export {
68
- listSessions
69
- };
@@ -1,30 +0,0 @@
1
- import {
2
- SessionStore
3
- } from "./chunk-6YMQTISJ.js";
4
-
5
- // src/commands/stop.ts
6
- import chalk from "chalk";
7
- import { execa } from "execa";
8
- async function stopSession(projectRoot, sessionId) {
9
- const store = new SessionStore();
10
- let sessionDir;
11
- try {
12
- const session = store.findSession(projectRoot, sessionId);
13
- if (!session) {
14
- console.error(chalk.red(`Error: Session ${sessionId} not found.`));
15
- process.exit(1);
16
- }
17
- sessionDir = session.session_dir;
18
- } finally {
19
- store.close();
20
- }
21
- await execa(
22
- "docker",
23
- ["compose", "-f", "docker-compose.session.yml", "--env-file", ".env.session", "stop"],
24
- { cwd: sessionDir, stdio: "inherit" }
25
- );
26
- }
27
-
28
- export {
29
- stopSession
30
- };
@@ -1,30 +0,0 @@
1
- import {
2
- SessionStore
3
- } from "./chunk-H4HPDIY3.js";
4
-
5
- // src/commands/stop.ts
6
- import chalk from "chalk";
7
- import { execa } from "execa";
8
- async function stopSession(projectRoot, sessionId) {
9
- const store = new SessionStore();
10
- let sessionDir;
11
- try {
12
- const session = store.findSession(projectRoot, sessionId);
13
- if (!session) {
14
- console.error(chalk.red(`Error: Session ${sessionId} not found.`));
15
- process.exit(1);
16
- }
17
- sessionDir = session.session_dir;
18
- } finally {
19
- store.close();
20
- }
21
- await execa(
22
- "docker",
23
- ["compose", "-f", "docker-compose.session.yml", "--env-file", ".env.session", "stop"],
24
- { cwd: sessionDir, stdio: "inherit" }
25
- );
26
- }
27
-
28
- export {
29
- stopSession
30
- };
@@ -1,200 +0,0 @@
1
- import {
2
- writeAppEnvFiles,
3
- writeEnvFile
4
- } from "./chunk-J36LRUXM.js";
5
- import {
6
- calculatePorts,
7
- formatPortsTable
8
- } from "./chunk-PJKUD2N2.js";
9
- import {
10
- createWorktree,
11
- findNextSessionId,
12
- generateDefaultBranchName,
13
- removeWorktree
14
- } from "./chunk-Y3GR6XK7.js";
15
- import {
16
- down,
17
- logs,
18
- up
19
- } from "./chunk-GBN67HYD.js";
20
- import {
21
- getSessionDir,
22
- getSessionsDir,
23
- loadConfig
24
- } from "./chunk-25WQHUYW.js";
25
- import {
26
- SessionStore
27
- } from "./chunk-6YMQTISJ.js";
28
-
29
- // src/commands/create.ts
30
- import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from "fs";
31
- import { basename, join } from "path";
32
- import chalk from "chalk";
33
- import { execa } from "execa";
34
- function updateEnvDatabaseUrl(envPath, newDbUrl) {
35
- if (!existsSync(envPath)) return;
36
- let content = readFileSync(envPath, "utf-8");
37
- if (content.includes("DATABASE_URL=")) {
38
- content = content.replace(/^DATABASE_URL=.*/m, `DATABASE_URL=${newDbUrl}`);
39
- } else {
40
- content += `
41
- DATABASE_URL=${newDbUrl}
42
- `;
43
- }
44
- writeFileSync(envPath, content);
45
- }
46
- async function createSession(projectRoot, sessionId, options) {
47
- const config = await loadConfig(projectRoot);
48
- const sessionsDir = getSessionsDir(config, projectRoot);
49
- const store = new SessionStore();
50
- try {
51
- if (!sessionId) {
52
- sessionId = findNextSessionId(store.getUsedSessionIds(projectRoot));
53
- console.log(chalk.gray(`Auto-assigned session ID: ${sessionId}`));
54
- }
55
- if (!/^\d{3}$/.test(sessionId)) {
56
- console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
57
- process.exit(1);
58
- }
59
- const inPlace = options.inPlace ?? false;
60
- const branchName = options.branch || generateDefaultBranchName(sessionId);
61
- const mode = options.mode || "docker";
62
- console.log(chalk.blue(`Creating session ${sessionId} (${mode} mode${inPlace ? ", in-place" : ""})...`));
63
- if (!inPlace) {
64
- console.log(chalk.gray(`Branch: ${branchName}`));
65
- }
66
- const ports = calculatePorts(config, sessionId);
67
- console.log(chalk.gray("\nPorts:"));
68
- console.log(chalk.gray(formatPortsTable(ports)));
69
- let sessionDir;
70
- if (inPlace) {
71
- sessionDir = projectRoot;
72
- console.log(chalk.blue("\nUsing current directory (in-place mode)..."));
73
- console.log(chalk.green(` Directory: ${sessionDir}`));
74
- } else {
75
- if (!existsSync(sessionsDir)) {
76
- mkdirSync(sessionsDir, { recursive: true });
77
- }
78
- sessionDir = getSessionDir(config, projectRoot, sessionId);
79
- console.log(chalk.blue("\nCreating git worktree..."));
80
- await createWorktree(projectRoot, sessionDir, branchName);
81
- console.log(chalk.green(` Created: ${sessionDir}`));
82
- const sessionDbUrl = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
83
- const envFilesToCopy = config.envFiles ?? [];
84
- for (const envFile of envFilesToCopy) {
85
- const srcPath = join(projectRoot, envFile);
86
- const destPath = join(sessionDir, envFile);
87
- if (existsSync(srcPath)) {
88
- copyFileSync(srcPath, destPath);
89
- updateEnvDatabaseUrl(destPath, sessionDbUrl);
90
- console.log(chalk.green(` Copied: ${envFile} (updated DATABASE_URL)`));
91
- }
92
- }
93
- }
94
- console.log(chalk.blue("\nGenerating .env.session..."));
95
- const projectName = config.projectName ?? basename(projectRoot);
96
- const envPath = writeEnvFile(sessionDir, sessionId, ports, projectName);
97
- console.log(chalk.green(` Written: ${envPath}`));
98
- const appEnvFiles = writeAppEnvFiles(config, sessionDir, sessionId, ports);
99
- for (const file of appEnvFiles) {
100
- console.log(chalk.green(` Written: ${file}`));
101
- }
102
- console.log(chalk.blue("\nStarting Docker services..."));
103
- let profiles;
104
- if (mode === "docker") {
105
- const allApps = config.apps ?? [];
106
- const excludeApps = options.without ?? [];
107
- profiles = allApps.filter((app) => !excludeApps.includes(app));
108
- if (excludeApps.length > 0) {
109
- console.log(chalk.gray(` Excluding apps: ${excludeApps.join(", ")}`));
110
- }
111
- }
112
- await up({ cwd: sessionDir, profiles });
113
- console.log(chalk.blue("Waiting for services to be ready..."));
114
- await new Promise((resolve) => setTimeout(resolve, 3e3));
115
- if (config.setup.length > 0) {
116
- console.log(chalk.blue("\nRunning setup commands..."));
117
- const setupEnv = {
118
- ...process.env,
119
- SESSION_ID: sessionId,
120
- // Add DATABASE_URL for db commands
121
- DATABASE_URL: `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`
122
- };
123
- for (const [name, port] of Object.entries(ports)) {
124
- setupEnv[name] = String(port);
125
- }
126
- for (const cmd of config.setup) {
127
- console.log(chalk.gray(` Running: ${cmd}`));
128
- const [command, ...args] = cmd.split(" ");
129
- try {
130
- await execa(command, args, {
131
- cwd: sessionDir,
132
- stdio: "inherit",
133
- env: setupEnv
134
- });
135
- } catch {
136
- console.warn(chalk.yellow(` Warning: Command failed: ${cmd}`));
137
- }
138
- }
139
- }
140
- store.remove(projectRoot, sessionId);
141
- try {
142
- store.insert({
143
- sessionId,
144
- projectRoot,
145
- sessionDir,
146
- branch: inPlace ? "" : branchName,
147
- mode,
148
- inPlace
149
- });
150
- } catch (dbErr) {
151
- console.error(chalk.red("Failed to record session in database. Cleaning up..."));
152
- try {
153
- await down({ cwd: sessionDir });
154
- } catch {
155
- }
156
- if (!inPlace) {
157
- try {
158
- await removeWorktree(projectRoot, sessionDir, branchName);
159
- } catch {
160
- }
161
- }
162
- throw dbErr;
163
- }
164
- console.log(chalk.green(`
165
- Session ${sessionId} ready!`));
166
- console.log(chalk.gray(`Directory: ${sessionDir}`));
167
- if (mode === "docker") {
168
- console.log(chalk.gray("\nDocker mode - all services in containers."));
169
- console.log(chalk.gray("View logs: docker compose -f docker-compose.session.yml logs -f"));
170
- } else {
171
- console.log(chalk.gray("\nNative mode - run apps with: pnpm dev"));
172
- }
173
- console.log(chalk.gray("\nPorts:"));
174
- for (const [name, port] of Object.entries(ports)) {
175
- console.log(chalk.cyan(` ${name}: ${port}`));
176
- }
177
- if (options.detach === false) {
178
- console.log(chalk.blue("\nStreaming logs (Ctrl+C to stop)..."));
179
- console.log(chalk.gray("\u2500".repeat(60)));
180
- try {
181
- await logs({ cwd: sessionDir, profiles });
182
- } catch (error) {
183
- const execaError = error;
184
- if (execaError.signal === "SIGINT") {
185
- console.log(chalk.gray("\n\u2500".repeat(60)));
186
- console.log(chalk.yellow("\nLog streaming stopped. Services are still running."));
187
- console.log(chalk.gray(`Resume logs: cd ${sessionDir} && docker compose -f docker-compose.session.yml --env-file .env.session logs -f`));
188
- } else {
189
- throw error;
190
- }
191
- }
192
- }
193
- } finally {
194
- store.close();
195
- }
196
- }
197
-
198
- export {
199
- createSession
200
- };
@@ -1,57 +0,0 @@
1
- // src/lib/docker.ts
2
- import { execa } from "execa";
3
- var COMPOSE_FILE = "docker-compose.session.yml";
4
- var ENV_FILE = ".env.session";
5
- async function compose(args, options) {
6
- const profileFlags = options.profiles?.flatMap((p) => ["--profile", p]) ?? [];
7
- const fullArgs = [
8
- "compose",
9
- "-f",
10
- COMPOSE_FILE,
11
- "--env-file",
12
- ENV_FILE,
13
- ...profileFlags,
14
- ...args
15
- ];
16
- return execa("docker", fullArgs, {
17
- cwd: options.cwd,
18
- stdio: "inherit"
19
- });
20
- }
21
- async function up(options) {
22
- const detach = options.detach !== false;
23
- const args = detach ? ["up", "-d"] : ["up"];
24
- await compose(args, options);
25
- }
26
- async function logs(options) {
27
- await compose(["logs", "-f", "--tail=50"], options);
28
- }
29
- async function down(options) {
30
- await compose(["down", "-v"], options);
31
- }
32
- async function ps(options) {
33
- const result = await execa(
34
- "docker",
35
- ["compose", "-f", COMPOSE_FILE, "--env-file", ENV_FILE, "ps", "--format", "json"],
36
- { cwd: options.cwd, reject: false }
37
- );
38
- return result.stdout;
39
- }
40
- async function isRunning(options) {
41
- try {
42
- const output = await ps(options);
43
- if (!output.trim()) return false;
44
- const services = output.trim().split("\n").map((line) => JSON.parse(line));
45
- return services.some((s) => s.State === "running");
46
- } catch {
47
- return false;
48
- }
49
- }
50
-
51
- export {
52
- up,
53
- logs,
54
- down,
55
- ps,
56
- isRunning
57
- };
@@ -1,70 +0,0 @@
1
- import {
2
- calculatePorts
3
- } from "./chunk-PJKUD2N2.js";
4
- import {
5
- isRunning
6
- } from "./chunk-GBN67HYD.js";
7
- import {
8
- loadConfig
9
- } from "./chunk-25WQHUYW.js";
10
- import {
11
- SessionStore
12
- } from "./chunk-6YMQTISJ.js";
13
-
14
- // src/commands/list.ts
15
- import { existsSync } from "fs";
16
- import { resolve } from "path";
17
- import chalk from "chalk";
18
- async function listSessions(projectRoot) {
19
- const config = await loadConfig(projectRoot);
20
- const store = new SessionStore();
21
- let sessions;
22
- try {
23
- sessions = store.listByProject(projectRoot);
24
- } finally {
25
- store.close();
26
- }
27
- if (sessions.length === 0) {
28
- console.log(chalk.gray("No active sessions found."));
29
- console.log(chalk.gray("\nTo create a session:"));
30
- console.log(chalk.cyan(" dev-prism create"));
31
- return;
32
- }
33
- console.log(chalk.blue("Active Sessions:"));
34
- console.log(chalk.gray("================\n"));
35
- for (const session of sessions) {
36
- const status = await getSessionStatus(session.session_id, session.session_dir, session.branch, config);
37
- printSessionStatus(status);
38
- }
39
- }
40
- async function getSessionStatus(sessionId, path, branch, config) {
41
- const ports = calculatePorts(config, sessionId);
42
- let running = false;
43
- const envFile = resolve(path, ".env.session");
44
- if (existsSync(envFile)) {
45
- running = await isRunning({ cwd: path });
46
- }
47
- return {
48
- sessionId,
49
- path,
50
- branch,
51
- running,
52
- ports
53
- };
54
- }
55
- function printSessionStatus(status) {
56
- const statusIcon = status.running ? chalk.green("\u25CF") : chalk.red("\u25CB");
57
- const statusText = status.running ? chalk.green("running") : chalk.gray("stopped");
58
- console.log(`${statusIcon} Session ${chalk.bold(status.sessionId)} ${statusText}`);
59
- console.log(chalk.gray(` Path: ${status.path}`));
60
- console.log(chalk.gray(` Branch: ${status.branch}`));
61
- console.log(chalk.gray(" Ports:"));
62
- for (const [name, port] of Object.entries(status.ports)) {
63
- console.log(chalk.gray(` ${name}: ${port}`));
64
- }
65
- console.log("");
66
- }
67
-
68
- export {
69
- listSessions
70
- };