UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

101 lines (100 loc) 5.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const caddy_1 = require("../../lib/caddy"); const dev_env_bridge_1 = require("../../lib/dev-env-bridge"); const dev_process_1 = require("../../lib/dev-process"); const dev_project_1 = require("../../lib/dev-project"); const dev_state_1 = require("../../lib/dev-state"); const dev_test_session_1 = require("../../lib/dev-test-session"); const dev_ticket_1 = require("../../lib/dev-ticket"); /** * Stop the processes started by `lt dev up` and remove the project's * Caddy block. * * - SIGTERM is sent to the detached process GROUP (negative PID) so * children (Vite, Nest watcher) receive the signal too. * - The Caddy block is removed and `caddy reload` is invoked, so the * subdomain stops resolving immediately. */ const DownCommand = { alias: ['d'], description: 'Stop API + App and remove Caddy block', hidden: false, name: 'down', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { const { filesystem, parameters, print: { colors, info, success, warning }, } = toolbox; const layout = (0, dev_project_1.resolveLayout)(filesystem.cwd(), filesystem); // Ticket-aware: in a ticket worktree the slug / Caddy block / test stack are // suffixed (`<slug>-<id>`), so resolve the same identity `up` used. const { identity } = (0, dev_ticket_1.resolveDevIdentity)(layout, { ticket: parameters.options.ticket }); const session = (0, dev_state_1.loadSession)(layout.root); const stopped = []; if (session) { for (const [name, pid] of Object.entries(session.pids)) { if (!pid) continue; if (!(0, dev_state_1.isPidAlive)(pid)) { stopped.push(`${name} (pid ${pid}, already dead)`); continue; } if ((0, dev_process_1.killProcessGroup)(pid)) stopped.push(`${name} (pid ${pid})`); else warning(`Failed to stop ${name} (pid ${pid})`); } (0, dev_state_1.clearSession)(layout.root); } else { info(colors.dim('No running processes registered for this project.')); } // Don't clobber another checkout: when this slug is registered to a DIFFERENT // checkout (two clones of the same project share a package.json "name" → slug), // the Caddy block + registration belong to IT — stop only OUR processes // (above) and leave its routing intact. Otherwise remove the block as usual. const conflict = (0, dev_state_1.detectSlugConflict)(identity.slug, layout.root); if (conflict) { warning(`Slug "${identity.slug}" is registered to another checkout — leaving its Caddy block + registration untouched:`); info(colors.dim(` ${conflict.otherPath}`)); } else { const removed = (0, caddy_1.removeProjectBlock)(identity.slug); if (removed) { const r = yield (0, caddy_1.reloadCaddy)(); if (r.ok) success(`Removed Caddy block for "${identity.slug}".`); else warning(`Removed Caddy block but reload failed: ${r.stderr.split('\n')[0]}`); } } // Clear ENV bridge so subsequent test runs without `lt dev up` // do not pick up stale URLs. if ((0, dev_env_bridge_1.clearEnvBridge)(layout.root)) info(colors.dim('Removed .lt-dev/.env bridge.')); // Also tear down any isolated test stack (`lt dev test`) for this project, // so `lt dev down` always leaves a clean slate. if ((0, dev_test_session_1.hasTestSession)(layout.root)) { const { stopped: testStopped } = yield (0, dev_test_session_1.tearDownTestSession)(layout, identity, { dim: colors.dim, info, warn: warning, }); if (testStopped.length > 0) success(`Stopped test stack: ${testStopped.join(', ')}`); } if (stopped.length > 0) success(`Stopped: ${stopped.join(', ')}`); if (!parameters.options.fromGluegunMenu) process.exit(); return `dev down: ${stopped.length} stopped`; }), }; module.exports = DownCommand;