dev-prism 0.3.0 → 0.6.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.
- package/README.md +262 -70
- package/bin/dev-prism.js +45 -42
- package/dist/chunk-24OM3LGM.js +35 -0
- package/dist/chunk-3FYEGH2G.js +217 -0
- package/dist/chunk-3NW2OWIU.js +78 -0
- package/dist/chunk-3Q454U3I.js +71 -0
- package/dist/chunk-3TRRZEFR.js +38 -0
- package/dist/chunk-4UNCSJRM.js +70 -0
- package/dist/chunk-63II3EL4.js +98 -0
- package/dist/chunk-76LSQIZI.js +31 -0
- package/dist/chunk-7OSTLJLO.js +219 -0
- package/dist/chunk-7YEZWM6Y.js +97 -0
- package/dist/chunk-AEVARZQ4.js +203 -0
- package/dist/chunk-AIVPJ467.js +70 -0
- package/dist/chunk-AOM6BONB.js +98 -0
- package/dist/chunk-BXYXWNGH.js +30 -0
- package/dist/chunk-CUQVGZBX.js +44 -0
- package/dist/chunk-DQER5GNG.js +72 -0
- package/dist/chunk-DTE5YQMI.js +41 -0
- package/dist/chunk-EXRHG5KQ.js +60 -0
- package/dist/chunk-FKTFCSU7.js +78 -0
- package/dist/chunk-GKXXK2ZH.js +203 -0
- package/dist/chunk-H3L73URT.js +65 -0
- package/dist/chunk-H4HPDIY3.js +95 -0
- package/dist/chunk-HZBJF67X.js +60 -0
- package/dist/chunk-I3U6JK77.js +66 -0
- package/dist/chunk-JMKE3ZKI.js +61 -0
- package/dist/chunk-JZ2VPQXP.js +132 -0
- package/dist/chunk-KDYKLH6P.js +40 -0
- package/dist/chunk-KZJE62TK.js +203 -0
- package/dist/chunk-LAOWFCQL.js +21 -0
- package/dist/chunk-LNIOSGC4.js +78 -0
- package/dist/chunk-MRBTH5PL.js +66 -0
- package/dist/chunk-NNVP5F6I.js +77 -0
- package/dist/chunk-OL25TBYX.js +67 -0
- package/dist/chunk-OOJ6YOGS.js +53 -0
- package/dist/chunk-OPEZFBBI.js +219 -0
- package/dist/chunk-Q5DPX4WL.js +219 -0
- package/dist/chunk-RC2AUYZ7.js +49 -0
- package/dist/chunk-RQ245R7T.js +67 -0
- package/dist/chunk-SD3TON6N.js +32 -0
- package/dist/chunk-SEKH4ZV6.js +60 -0
- package/dist/chunk-SUMJLXT7.js +30 -0
- package/dist/chunk-UKYQN4A3.js +38 -0
- package/dist/chunk-URGGS3XM.js +95 -0
- package/dist/chunk-VUNPVDSO.js +74 -0
- package/dist/chunk-VXP2SPRI.js +51 -0
- package/dist/chunk-W54CPPSK.js +217 -0
- package/dist/chunk-X2PXZRYU.js +41 -0
- package/dist/chunk-X6FHBEAS.js +200 -0
- package/dist/chunk-YSO3IDZZ.js +40 -0
- package/dist/chunk-YY5DA35Z.js +40 -0
- package/dist/chunk-Z2ISJMLW.js +92 -0
- package/dist/chunk-ZKHNUDSL.js +119 -0
- package/dist/commands/create.d.ts +2 -1
- package/dist/commands/create.js +6 -5
- package/dist/commands/destroy.d.ts +1 -1
- package/dist/commands/destroy.js +4 -3
- package/dist/commands/info.d.ts +3 -0
- package/dist/commands/info.js +3 -2
- package/dist/commands/list.d.ts +1 -1
- package/dist/commands/list.js +3 -5
- package/dist/commands/logs.d.ts +8 -0
- package/dist/commands/logs.js +3 -2
- package/dist/commands/prune.d.ts +6 -0
- package/dist/commands/prune.js +4 -3
- package/dist/commands/start.d.ts +7 -0
- package/dist/commands/start.js +3 -2
- package/dist/commands/stop-all.d.ts +3 -0
- package/dist/commands/stop-all.js +3 -4
- package/dist/commands/stop.d.ts +3 -0
- package/dist/commands/stop.js +3 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +36 -18
- package/dist/lib/compose.d.ts +12 -0
- package/dist/lib/compose.js +12 -0
- package/dist/lib/config.d.ts +4 -0
- package/dist/lib/config.test.d.ts +1 -0
- package/dist/lib/config.test.js +32 -0
- package/dist/lib/docker-inspect.d.ts +24 -0
- package/dist/lib/docker-inspect.js +16 -0
- package/dist/lib/env.d.ts +5 -4
- package/dist/lib/env.js +1 -1
- package/dist/lib/env.test.d.ts +1 -0
- package/dist/lib/env.test.js +68 -0
- package/dist/lib/ports.d.ts +3 -3
- package/dist/lib/ports.js +3 -3
- package/dist/lib/ports.test.d.ts +1 -0
- package/dist/lib/ports.test.js +61 -0
- package/dist/lib/session.d.ts +16 -0
- package/dist/lib/session.js +13 -0
- package/dist/lib/store.d.ts +46 -0
- package/dist/lib/store.js +1 -1
- package/dist/lib/store.test.d.ts +1 -0
- package/dist/lib/store.test.js +205 -0
- package/dist/lib/worktree.d.ts +3 -13
- package/dist/lib/worktree.js +1 -1
- package/dist/lib/worktree.test.d.ts +1 -0
- package/dist/lib/worktree.test.js +41 -0
- package/package.json +2 -5
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractPorts,
|
|
3
|
+
formatPortsTable
|
|
4
|
+
} from "./chunk-LAOWFCQL.js";
|
|
5
|
+
import {
|
|
6
|
+
generateEnvStub,
|
|
7
|
+
writeComposeFile
|
|
8
|
+
} from "./chunk-JMKE3ZKI.js";
|
|
9
|
+
import {
|
|
10
|
+
writeAppEnvFiles,
|
|
11
|
+
writeEnvFile
|
|
12
|
+
} from "./chunk-SEKH4ZV6.js";
|
|
13
|
+
import {
|
|
14
|
+
createWorktree,
|
|
15
|
+
generateDefaultBranchName,
|
|
16
|
+
removeWorktree
|
|
17
|
+
} from "./chunk-3Q454U3I.js";
|
|
18
|
+
import {
|
|
19
|
+
down,
|
|
20
|
+
logs,
|
|
21
|
+
up
|
|
22
|
+
} from "./chunk-GBN67HYD.js";
|
|
23
|
+
import {
|
|
24
|
+
getSessionsDir,
|
|
25
|
+
loadConfig
|
|
26
|
+
} from "./chunk-25WQHUYW.js";
|
|
27
|
+
import {
|
|
28
|
+
getPortMappings,
|
|
29
|
+
sessionExists
|
|
30
|
+
} from "./chunk-JZ2VPQXP.js";
|
|
31
|
+
|
|
32
|
+
// src/commands/create.ts
|
|
33
|
+
import { existsSync, mkdirSync, copyFileSync, readFileSync, writeFileSync } from "fs";
|
|
34
|
+
import { basename, join, resolve } from "path";
|
|
35
|
+
import chalk from "chalk";
|
|
36
|
+
import { execa } from "execa";
|
|
37
|
+
function updateEnvDatabaseUrl(envPath, newDbUrl) {
|
|
38
|
+
if (!existsSync(envPath)) return;
|
|
39
|
+
let content = readFileSync(envPath, "utf-8");
|
|
40
|
+
if (content.includes("DATABASE_URL=")) {
|
|
41
|
+
content = content.replace(/^DATABASE_URL=.*/m, `DATABASE_URL=${newDbUrl}`);
|
|
42
|
+
} else {
|
|
43
|
+
content += `
|
|
44
|
+
DATABASE_URL=${newDbUrl}
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
writeFileSync(envPath, content);
|
|
48
|
+
}
|
|
49
|
+
async function createSession(projectRoot, _sessionId, options) {
|
|
50
|
+
const config = await loadConfig(projectRoot);
|
|
51
|
+
const sessionsDir = getSessionsDir(config, projectRoot);
|
|
52
|
+
const inPlace = options.inPlace ?? false;
|
|
53
|
+
const mode = options.mode || "docker";
|
|
54
|
+
let workingDir;
|
|
55
|
+
let branchName = "";
|
|
56
|
+
if (inPlace) {
|
|
57
|
+
workingDir = projectRoot;
|
|
58
|
+
console.log(chalk.blue(`Creating session in current directory (${mode} mode)...`));
|
|
59
|
+
} else {
|
|
60
|
+
branchName = options.branch || generateDefaultBranchName();
|
|
61
|
+
workingDir = resolve(sessionsDir, branchName);
|
|
62
|
+
console.log(chalk.blue(`Creating session (${mode} mode)...`));
|
|
63
|
+
console.log(chalk.gray(`Branch: ${branchName}`));
|
|
64
|
+
console.log(chalk.gray(`Directory: ${workingDir}`));
|
|
65
|
+
}
|
|
66
|
+
if (await sessionExists(workingDir)) {
|
|
67
|
+
console.error(chalk.red(`
|
|
68
|
+
Error: Session already running in this directory.`));
|
|
69
|
+
console.error(chalk.gray(`Stop it first with: dev-prism stop`));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
let profiles;
|
|
73
|
+
try {
|
|
74
|
+
if (!inPlace) {
|
|
75
|
+
if (!existsSync(sessionsDir)) {
|
|
76
|
+
mkdirSync(sessionsDir, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
console.log(chalk.blue("\nCreating git worktree..."));
|
|
79
|
+
await createWorktree(projectRoot, workingDir, branchName);
|
|
80
|
+
console.log(chalk.green(` Created: ${workingDir}`));
|
|
81
|
+
}
|
|
82
|
+
const projectName = config.projectName ?? basename(projectRoot);
|
|
83
|
+
const services = config.services ?? [
|
|
84
|
+
{ name: "postgres", internalPort: 5432 },
|
|
85
|
+
{ name: "app", internalPort: 3e3 }
|
|
86
|
+
];
|
|
87
|
+
console.log(chalk.blue("\nGenerating docker-compose.session.yml..."));
|
|
88
|
+
const composePath = writeComposeFile(workingDir, projectName, services);
|
|
89
|
+
console.log(chalk.green(` Written: ${composePath}`));
|
|
90
|
+
console.log(chalk.blue("\nGenerating .env.session stub..."));
|
|
91
|
+
const envStub = generateEnvStub(workingDir, projectName);
|
|
92
|
+
const envPath = resolve(workingDir, ".env.session");
|
|
93
|
+
writeFileSync(envPath, envStub, "utf-8");
|
|
94
|
+
console.log(chalk.green(` Written: ${envPath}`));
|
|
95
|
+
if (!inPlace) {
|
|
96
|
+
const envFilesToCopy = config.envFiles ?? [];
|
|
97
|
+
for (const envFile of envFilesToCopy) {
|
|
98
|
+
const srcPath = join(projectRoot, envFile);
|
|
99
|
+
const destPath = join(workingDir, envFile);
|
|
100
|
+
if (existsSync(srcPath)) {
|
|
101
|
+
copyFileSync(srcPath, destPath);
|
|
102
|
+
console.log(chalk.green(` Copied: ${envFile}`));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
console.log(chalk.blue("\nStarting Docker services..."));
|
|
107
|
+
if (mode === "docker") {
|
|
108
|
+
const allApps = config.apps ?? [];
|
|
109
|
+
const excludeApps = options.without ?? [];
|
|
110
|
+
profiles = allApps.filter((app) => !excludeApps.includes(app));
|
|
111
|
+
if (excludeApps.length > 0) {
|
|
112
|
+
console.log(chalk.gray(` Excluding apps: ${excludeApps.join(", ")}`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await up({ cwd: workingDir, profiles, detach: true });
|
|
116
|
+
console.log(chalk.blue("Waiting for services to be ready..."));
|
|
117
|
+
await new Promise((resolve2) => setTimeout(resolve2, 3e3));
|
|
118
|
+
console.log(chalk.blue("\nDiscovering ports from containers..."));
|
|
119
|
+
const portMappings = await getPortMappings(workingDir);
|
|
120
|
+
const ports = extractPorts(portMappings);
|
|
121
|
+
console.log(chalk.gray("Discovered ports:"));
|
|
122
|
+
console.log(chalk.gray(formatPortsTable(ports)));
|
|
123
|
+
const finalEnvContent = writeEnvFile(workingDir, ports, projectName);
|
|
124
|
+
console.log(chalk.green(` Updated: ${finalEnvContent}`));
|
|
125
|
+
const appEnvFiles = writeAppEnvFiles(config, workingDir, ports);
|
|
126
|
+
for (const file of appEnvFiles) {
|
|
127
|
+
console.log(chalk.green(` Written: ${file}`));
|
|
128
|
+
}
|
|
129
|
+
if (!inPlace && ports.POSTGRES_PORT) {
|
|
130
|
+
const sessionDbUrl = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
|
|
131
|
+
const envFilesToCopy = config.envFiles ?? [];
|
|
132
|
+
for (const envFile of envFilesToCopy) {
|
|
133
|
+
const destPath = join(workingDir, envFile);
|
|
134
|
+
if (existsSync(destPath)) {
|
|
135
|
+
updateEnvDatabaseUrl(destPath, sessionDbUrl);
|
|
136
|
+
console.log(chalk.green(` Updated DATABASE_URL in: ${envFile}`));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (config.setup.length > 0) {
|
|
141
|
+
console.log(chalk.blue("\nRunning setup commands..."));
|
|
142
|
+
const setupEnv = {
|
|
143
|
+
...process.env,
|
|
144
|
+
SESSION_DIR: workingDir
|
|
145
|
+
};
|
|
146
|
+
for (const [name, port] of Object.entries(ports)) {
|
|
147
|
+
setupEnv[name] = String(port);
|
|
148
|
+
}
|
|
149
|
+
if (ports.POSTGRES_PORT) {
|
|
150
|
+
setupEnv.DATABASE_URL = `postgresql://postgres:postgres@localhost:${ports.POSTGRES_PORT}/postgres`;
|
|
151
|
+
}
|
|
152
|
+
for (const cmd of config.setup) {
|
|
153
|
+
console.log(chalk.gray(` Running: ${cmd}`));
|
|
154
|
+
const [command, ...args] = cmd.split(" ");
|
|
155
|
+
try {
|
|
156
|
+
await execa(command, args, {
|
|
157
|
+
cwd: workingDir,
|
|
158
|
+
stdio: "inherit",
|
|
159
|
+
env: setupEnv
|
|
160
|
+
});
|
|
161
|
+
} catch {
|
|
162
|
+
console.warn(chalk.yellow(` Warning: Command failed: ${cmd}`));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
console.log(chalk.green(`
|
|
167
|
+
Session ready!`));
|
|
168
|
+
console.log(chalk.gray(`Directory: ${workingDir}`));
|
|
169
|
+
if (mode === "docker") {
|
|
170
|
+
console.log(chalk.gray("\nDocker mode - all services in containers."));
|
|
171
|
+
console.log(chalk.gray("View logs: docker compose -f docker-compose.session.yml logs -f"));
|
|
172
|
+
} else {
|
|
173
|
+
console.log(chalk.gray("\nNative mode - run apps with: pnpm dev"));
|
|
174
|
+
}
|
|
175
|
+
console.log(chalk.gray("\nPorts:"));
|
|
176
|
+
for (const [name, port] of Object.entries(ports)) {
|
|
177
|
+
console.log(chalk.cyan(` ${name}: http://localhost:${port}`));
|
|
178
|
+
}
|
|
179
|
+
if (options.detach === false) {
|
|
180
|
+
console.log(chalk.blue("\nStreaming logs (Ctrl+C to stop)..."));
|
|
181
|
+
console.log(chalk.gray("\u2500".repeat(60)));
|
|
182
|
+
try {
|
|
183
|
+
await logs({ cwd: workingDir, profiles });
|
|
184
|
+
} catch (error) {
|
|
185
|
+
const execaError = error;
|
|
186
|
+
if (execaError.signal === "SIGINT") {
|
|
187
|
+
console.log(chalk.gray("\n\u2500".repeat(60)));
|
|
188
|
+
console.log(chalk.yellow("\nLog streaming stopped. Services are still running."));
|
|
189
|
+
console.log(
|
|
190
|
+
chalk.gray(
|
|
191
|
+
`Resume logs: cd ${workingDir} && docker compose -f docker-compose.session.yml --env-file .env.session logs -f`
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
} else {
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error(chalk.red("Session creation failed. Cleaning up..."));
|
|
201
|
+
try {
|
|
202
|
+
await down({ cwd: workingDir });
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
if (!inPlace && branchName) {
|
|
206
|
+
try {
|
|
207
|
+
await removeWorktree(projectRoot, workingDir, branchName);
|
|
208
|
+
} catch {
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
createSession
|
|
217
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
removeWorktree
|
|
3
|
+
} from "./chunk-Y3GR6XK7.js";
|
|
4
|
+
import {
|
|
5
|
+
down
|
|
6
|
+
} from "./chunk-GBN67HYD.js";
|
|
7
|
+
import {
|
|
8
|
+
loadConfig
|
|
9
|
+
} from "./chunk-25WQHUYW.js";
|
|
10
|
+
import {
|
|
11
|
+
SessionStore
|
|
12
|
+
} from "./chunk-H4HPDIY3.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/destroy.ts
|
|
15
|
+
import { existsSync } from "fs";
|
|
16
|
+
import { resolve } from "path";
|
|
17
|
+
import chalk from "chalk";
|
|
18
|
+
async function destroySession(projectRoot, sessionId, options) {
|
|
19
|
+
const config = await loadConfig(projectRoot);
|
|
20
|
+
const store = new SessionStore();
|
|
21
|
+
try {
|
|
22
|
+
if (options.all) {
|
|
23
|
+
console.log(chalk.blue("Destroying all sessions..."));
|
|
24
|
+
const sessions = store.listByProject(projectRoot);
|
|
25
|
+
if (sessions.length === 0) {
|
|
26
|
+
console.log(chalk.gray("No sessions found."));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
for (const session2 of sessions) {
|
|
30
|
+
await destroySingleSession(projectRoot, session2.session_id, session2.session_dir, session2.branch, session2.in_place === 1);
|
|
31
|
+
store.markDestroyed(projectRoot, session2.session_id);
|
|
32
|
+
}
|
|
33
|
+
console.log(chalk.green(`
|
|
34
|
+
Destroyed ${sessions.length} session(s).`));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!sessionId) {
|
|
38
|
+
console.error(chalk.red("Error: Session ID required. Use --all to destroy all sessions."));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
if (!/^\d{3}$/.test(sessionId)) {
|
|
42
|
+
console.error(chalk.red("Error: Session ID must be exactly 3 digits (001-999)"));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const session = store.findSession(projectRoot, sessionId);
|
|
46
|
+
if (!session) {
|
|
47
|
+
console.error(chalk.red(`Error: Session ${sessionId} not found.`));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
await destroySingleSession(projectRoot, sessionId, session.session_dir, session.branch, session.in_place === 1);
|
|
51
|
+
store.markDestroyed(projectRoot, sessionId);
|
|
52
|
+
console.log(chalk.green(`
|
|
53
|
+
Session ${sessionId} destroyed.`));
|
|
54
|
+
} finally {
|
|
55
|
+
store.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function destroySingleSession(projectRoot, sessionId, sessionDir, branchName, inPlace) {
|
|
59
|
+
console.log(chalk.blue(`
|
|
60
|
+
Destroying session ${sessionId}...`));
|
|
61
|
+
const envFile = resolve(sessionDir, ".env.session");
|
|
62
|
+
if (existsSync(envFile)) {
|
|
63
|
+
console.log(chalk.gray(" Stopping Docker containers..."));
|
|
64
|
+
try {
|
|
65
|
+
await down({ cwd: sessionDir });
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!inPlace) {
|
|
70
|
+
console.log(chalk.gray(" Removing git worktree..."));
|
|
71
|
+
await removeWorktree(projectRoot, sessionDir, branchName);
|
|
72
|
+
}
|
|
73
|
+
console.log(chalk.green(` Session ${sessionId} destroyed.`));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
destroySession
|
|
78
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/lib/worktree.ts
|
|
2
|
+
import { existsSync, rmSync } from "fs";
|
|
3
|
+
import { execa } from "execa";
|
|
4
|
+
async function branchExists(projectRoot, branchName) {
|
|
5
|
+
try {
|
|
6
|
+
await execa("git", ["rev-parse", "--verify", branchName], {
|
|
7
|
+
cwd: projectRoot,
|
|
8
|
+
stdio: "pipe"
|
|
9
|
+
});
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function findNextSessionId(usedIds) {
|
|
16
|
+
for (let i = 1; i <= 999; i++) {
|
|
17
|
+
const sessionId = String(i).padStart(3, "0");
|
|
18
|
+
if (!usedIds.has(sessionId)) {
|
|
19
|
+
return sessionId;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
throw new Error("No available session IDs (001-999 all in use)");
|
|
23
|
+
}
|
|
24
|
+
function generateDefaultBranchName() {
|
|
25
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, -5);
|
|
26
|
+
return `session/${timestamp}`;
|
|
27
|
+
}
|
|
28
|
+
async function createWorktree(projectRoot, sessionDir, branchName) {
|
|
29
|
+
if (existsSync(sessionDir)) {
|
|
30
|
+
throw new Error(`Session directory already exists: ${sessionDir}`);
|
|
31
|
+
}
|
|
32
|
+
const exists = await branchExists(projectRoot, branchName);
|
|
33
|
+
if (exists) {
|
|
34
|
+
await execa("git", ["worktree", "add", sessionDir, branchName], {
|
|
35
|
+
cwd: projectRoot,
|
|
36
|
+
stdio: "inherit"
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
await execa("git", ["worktree", "add", sessionDir, "-b", branchName, "HEAD"], {
|
|
40
|
+
cwd: projectRoot,
|
|
41
|
+
stdio: "inherit"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function removeWorktree(projectRoot, sessionDir, branchName) {
|
|
46
|
+
if (existsSync(sessionDir)) {
|
|
47
|
+
try {
|
|
48
|
+
await execa("git", ["worktree", "remove", "--force", sessionDir], {
|
|
49
|
+
cwd: projectRoot,
|
|
50
|
+
stdio: "inherit"
|
|
51
|
+
});
|
|
52
|
+
} catch {
|
|
53
|
+
rmSync(sessionDir, { recursive: true, force: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await execa("git", ["branch", "-D", branchName], {
|
|
58
|
+
cwd: projectRoot,
|
|
59
|
+
stdio: "pipe"
|
|
60
|
+
// Don't show output, branch might not exist
|
|
61
|
+
});
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
findNextSessionId,
|
|
68
|
+
generateDefaultBranchName,
|
|
69
|
+
createWorktree,
|
|
70
|
+
removeWorktree
|
|
71
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
up
|
|
3
|
+
} from "./chunk-GBN67HYD.js";
|
|
4
|
+
import {
|
|
5
|
+
loadConfig
|
|
6
|
+
} from "./chunk-25WQHUYW.js";
|
|
7
|
+
import {
|
|
8
|
+
SessionStore
|
|
9
|
+
} from "./chunk-H4HPDIY3.js";
|
|
10
|
+
|
|
11
|
+
// src/commands/start.ts
|
|
12
|
+
import chalk from "chalk";
|
|
13
|
+
async function startSession(projectRoot, sessionId, options) {
|
|
14
|
+
const config = await loadConfig(projectRoot);
|
|
15
|
+
const store = new SessionStore();
|
|
16
|
+
let sessionDir;
|
|
17
|
+
try {
|
|
18
|
+
const session = store.findSession(projectRoot, sessionId);
|
|
19
|
+
if (!session) {
|
|
20
|
+
console.error(chalk.red(`Error: Session ${sessionId} not found.`));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
sessionDir = session.session_dir;
|
|
24
|
+
} finally {
|
|
25
|
+
store.close();
|
|
26
|
+
}
|
|
27
|
+
let profiles;
|
|
28
|
+
if (options.mode === "docker") {
|
|
29
|
+
const allApps = config.apps ?? [];
|
|
30
|
+
const excludeApps = options.without ?? [];
|
|
31
|
+
profiles = allApps.filter((app) => !excludeApps.includes(app));
|
|
32
|
+
}
|
|
33
|
+
await up({ cwd: sessionDir, profiles });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
startSession
|
|
38
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calculatePorts
|
|
3
|
+
} from "./chunk-3ATDGV4Y.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-H4HPDIY3.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.cyan(` ${name}: http://localhost:${port}`));
|
|
64
|
+
}
|
|
65
|
+
console.log("");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
listSessions
|
|
70
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
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-H4HPDIY3.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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSession
|
|
3
|
+
} from "./chunk-DQER5GNG.js";
|
|
4
|
+
|
|
5
|
+
// src/commands/stop.ts
|
|
6
|
+
import { existsSync, unlinkSync } from "fs";
|
|
7
|
+
import { resolve } from "path";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { execa } from "execa";
|
|
10
|
+
async function stopSession(workingDir) {
|
|
11
|
+
const session = await getSession(workingDir);
|
|
12
|
+
if (!session) {
|
|
13
|
+
console.error(chalk.red(`Error: No session found in directory: ${workingDir}`));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
console.log(chalk.blue(`Stopping session in ${workingDir}...`));
|
|
17
|
+
if (session.containers.length > 0) {
|
|
18
|
+
const containerIds = session.containers.map((c) => c.id);
|
|
19
|
+
await execa("docker", ["stop", ...containerIds], { stdio: "inherit" });
|
|
20
|
+
}
|
|
21
|
+
const envPath = resolve(workingDir, ".env.session");
|
|
22
|
+
if (existsSync(envPath)) {
|
|
23
|
+
unlinkSync(envPath);
|
|
24
|
+
console.log(chalk.gray(`Deleted: ${envPath}`));
|
|
25
|
+
}
|
|
26
|
+
console.log(chalk.green("Session stopped."));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
stopSession
|
|
31
|
+
};
|