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,200 +0,0 @@
1
- import {
2
- writeAppEnvFiles,
3
- writeEnvFile
4
- } from "./chunk-J36LRUXM.js";
5
- import {
6
- calculatePorts,
7
- formatPortsTable
8
- } from "./chunk-3ATDGV4Y.js";
9
- import {
10
- createWorktree,
11
- findNextSessionId,
12
- generateDefaultBranchName,
13
- removeWorktree
14
- } from "./chunk-FKTFCSU7.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}: http://localhost:${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,67 +0,0 @@
1
- import {
2
- getSessionWorktrees,
3
- removeWorktree
4
- } from "./chunk-GWDGC2OE.js";
5
- import {
6
- loadConfig
7
- } from "./chunk-25WQHUYW.js";
8
- import {
9
- down
10
- } from "./chunk-VR3QWHHB.js";
11
-
12
- // src/commands/destroy.ts
13
- import { existsSync } from "fs";
14
- import { resolve } from "path";
15
- import chalk from "chalk";
16
- async function destroySession(projectRoot, sessionId, options) {
17
- const config = await loadConfig(projectRoot);
18
- const sessions = await getSessionWorktrees(projectRoot);
19
- if (options.all) {
20
- console.log(chalk.blue("Destroying all sessions..."));
21
- if (sessions.length === 0) {
22
- console.log(chalk.gray("No sessions found."));
23
- return;
24
- }
25
- for (const session2 of sessions) {
26
- await destroySingleSession(projectRoot, session2.sessionId, session2.path, session2.branch);
27
- }
28
- console.log(chalk.green(`
29
- Destroyed ${sessions.length} session(s).`));
30
- return;
31
- }
32
- if (!sessionId) {
33
- console.error(chalk.red("Error: Session ID required. Use --all to destroy all sessions."));
34
- process.exit(1);
35
- }
36
- if (!/^\d{3}$/.test(sessionId)) {
37
- console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
38
- process.exit(1);
39
- }
40
- const session = sessions.find((s) => s.sessionId === sessionId);
41
- if (!session) {
42
- console.error(chalk.red(`Error: Session ${sessionId} not found.`));
43
- process.exit(1);
44
- }
45
- await destroySingleSession(projectRoot, sessionId, session.path, session.branch);
46
- console.log(chalk.green(`
47
- Session ${sessionId} destroyed.`));
48
- }
49
- async function destroySingleSession(projectRoot, sessionId, sessionDir, branchName) {
50
- console.log(chalk.blue(`
51
- Destroying session ${sessionId}...`));
52
- const envFile = resolve(sessionDir, ".env.session");
53
- if (existsSync(envFile)) {
54
- console.log(chalk.gray(" Stopping Docker containers..."));
55
- try {
56
- await down({ cwd: sessionDir });
57
- } catch {
58
- }
59
- }
60
- console.log(chalk.gray(" Removing git worktree..."));
61
- await removeWorktree(projectRoot, sessionDir, branchName);
62
- console.log(chalk.green(` Session ${sessionId} destroyed.`));
63
- }
64
-
65
- export {
66
- destroySession
67
- };
@@ -1,8 +0,0 @@
1
- interface LogsOptions {
2
- mode?: string;
3
- without?: string[];
4
- tail?: string;
5
- }
6
- declare function streamLogs(projectRoot: string, sessionId: string, options: LogsOptions): Promise<void>;
7
-
8
- export { type LogsOptions, streamLogs };
@@ -1,8 +0,0 @@
1
- import {
2
- streamLogs
3
- } from "../chunk-RC2AUYZ7.js";
4
- import "../chunk-25WQHUYW.js";
5
- import "../chunk-H4HPDIY3.js";
6
- export {
7
- streamLogs
8
- };
@@ -1,7 +0,0 @@
1
- interface StartOptions {
2
- mode?: string;
3
- without?: string[];
4
- }
5
- declare function startSession(projectRoot: string, sessionId: string, options: StartOptions): Promise<void>;
6
-
7
- export { type StartOptions, startSession };
@@ -1,9 +0,0 @@
1
- import {
2
- startSession
3
- } from "../chunk-3TRRZEFR.js";
4
- import "../chunk-GBN67HYD.js";
5
- import "../chunk-25WQHUYW.js";
6
- import "../chunk-H4HPDIY3.js";
7
- export {
8
- startSession
9
- };
@@ -1,3 +0,0 @@
1
- declare function stopAllSessions(projectRoot: string): Promise<void>;
2
-
3
- export { stopAllSessions };
@@ -1,9 +0,0 @@
1
- import {
2
- stopAllSessions
3
- } from "../chunk-OL25TBYX.js";
4
- import "../chunk-GBN67HYD.js";
5
- import "../chunk-25WQHUYW.js";
6
- import "../chunk-H4HPDIY3.js";
7
- export {
8
- stopAllSessions
9
- };
@@ -1,3 +0,0 @@
1
- declare function stopSession(projectRoot: string, sessionId: string): Promise<void>;
2
-
3
- export { stopSession };
@@ -1,7 +0,0 @@
1
- import {
2
- stopSession
3
- } from "../chunk-SUMJLXT7.js";
4
- import "../chunk-H4HPDIY3.js";
5
- export {
6
- stopSession
7
- };
@@ -1,12 +0,0 @@
1
- interface DockerComposeOptions {
2
- cwd: string;
3
- profiles?: string[];
4
- detach?: boolean;
5
- }
6
- declare function up(options: DockerComposeOptions): Promise<void>;
7
- declare function logs(options: DockerComposeOptions): Promise<void>;
8
- declare function down(options: DockerComposeOptions): Promise<void>;
9
- declare function ps(options: DockerComposeOptions): Promise<string>;
10
- declare function isRunning(options: DockerComposeOptions): Promise<boolean>;
11
-
12
- export { type DockerComposeOptions, down, isRunning, logs, ps, up };
@@ -1,14 +0,0 @@
1
- import {
2
- down,
3
- isRunning,
4
- logs,
5
- ps,
6
- up
7
- } from "../chunk-GBN67HYD.js";
8
- export {
9
- down,
10
- isRunning,
11
- logs,
12
- ps,
13
- up
14
- };
@@ -1,6 +0,0 @@
1
- import { SessionConfig } from './config.js';
2
-
3
- declare function calculatePorts(config: SessionConfig, sessionId: string): Record<string, number>;
4
- declare function formatPortsTable(ports: Record<string, number>): string;
5
-
6
- export { calculatePorts, formatPortsTable };
package/dist/lib/ports.js DELETED
@@ -1,8 +0,0 @@
1
- import {
2
- calculatePorts,
3
- formatPortsTable
4
- } from "../chunk-3ATDGV4Y.js";
5
- export {
6
- calculatePorts,
7
- formatPortsTable
8
- };
@@ -1,46 +0,0 @@
1
- interface SessionRow {
2
- id: number;
3
- session_id: string;
4
- project_root: string;
5
- session_dir: string;
6
- branch: string;
7
- mode: string;
8
- in_place: number;
9
- created_at: string;
10
- destroyed_at: string | null;
11
- }
12
- declare class SessionStore {
13
- private db;
14
- constructor(dbPath?: string);
15
- insert(row: {
16
- sessionId: string;
17
- projectRoot: string;
18
- sessionDir: string;
19
- branch?: string;
20
- mode?: string;
21
- inPlace?: boolean;
22
- }): SessionRow;
23
- /**
24
- * Atomically remove any old destroyed row and insert a new one.
25
- * Uses a transaction so the UNIQUE constraint prevents concurrent creates
26
- * from claiming the same session ID.
27
- */
28
- reserve(row: {
29
- sessionId: string;
30
- projectRoot: string;
31
- sessionDir: string;
32
- branch?: string;
33
- mode?: string;
34
- inPlace?: boolean;
35
- }): SessionRow;
36
- listByProject(projectRoot: string): SessionRow[];
37
- listAll(): SessionRow[];
38
- findSession(projectRoot: string, sessionId: string): SessionRow | undefined;
39
- findByDir(sessionDir: string): SessionRow | undefined;
40
- getUsedSessionIds(projectRoot: string): Set<string>;
41
- markDestroyed(projectRoot: string, sessionId: string): boolean;
42
- remove(projectRoot: string, sessionId: string): boolean;
43
- close(): void;
44
- }
45
-
46
- export { type SessionRow, SessionStore };
package/dist/lib/store.js DELETED
@@ -1,6 +0,0 @@
1
- import {
2
- SessionStore
3
- } from "../chunk-H4HPDIY3.js";
4
- export {
5
- SessionStore
6
- };