@lenne.tech/cli
Version:
lenne.Tech CLI: lt
79 lines (78 loc) • 4.18 kB
JavaScript
;
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 dev_identity_1 = require("../../lib/dev-identity");
const dev_project_1 = require("../../lib/dev-project");
const dev_state_1 = require("../../lib/dev-state");
const dev_ticket_1 = require("../../lib/dev-ticket");
/**
* `lt ticket list` — the dashboard of all active ticket worktrees: id, folder,
* branch, URLs, DB and running state. The one place to re-view every ticket's
* URLs at any time.
*/
const ListCommand = {
alias: ['ls'],
description: 'List all ticket worktrees with their URLs + status',
name: 'list',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const { filesystem, parameters, print: { colors, info, warning }, } = toolbox;
const layout = (0, dev_project_1.resolveLayout)(filesystem.cwd(), filesystem);
let mainRepoRoot;
try {
mainRepoRoot = (0, dev_ticket_1.gitMainRepoRoot)(layout.root);
}
catch (_b) {
warning('Not inside a git repository.');
if (!parameters.options.fromGluegunMenu)
process.exit(1);
return 'ticket list: not a git repo';
}
const base = (0, dev_identity_1.buildIdentity)(mainRepoRoot);
const tickets = (0, dev_ticket_1.listWorktrees)(mainRepoRoot).filter((w) => w.ticket);
const reg = (0, dev_state_1.loadRegistry)();
info('');
info(colors.bold('Ticket environments'));
info(colors.dim('─'.repeat(64)));
if (tickets.length === 0) {
info(colors.dim(' none — start one with `lt ticket start <ticket-or-name>`'));
info('');
if (!parameters.options.fromGluegunMenu)
process.exit();
return 'ticket list: empty';
}
for (const wt of tickets) {
const session = (0, dev_state_1.loadSession)(wt.path);
const apiAlive = (session === null || session === void 0 ? void 0 : session.pids.api) ? (0, dev_state_1.isPidAlive)(session.pids.api) : false;
const appAlive = (session === null || session === void 0 ? void 0 : session.pids.app) ? (0, dev_state_1.isPidAlive)(session.pids.app) : false;
const running = apiAlive || appAlive;
const dot = running ? colors.green('●') : colors.dim('○');
// The dev stack for this ticket is registered under `<base>-<id>`.
const entry = reg.projects[`${base.slug}-${wt.ticket}`];
info(` ${dot} ${colors.bold(String(wt.ticket).padEnd(16))} ${colors.dim(`branch ${(_a = wt.branch) !== null && _a !== void 0 ? _a : '-'}`)}`);
if (entry) {
for (const [sub, host] of Object.entries(entry.subdomains))
info(` ${sub.padEnd(4)} https://${host}`);
if (entry.dbName)
info(` db mongodb://127.0.0.1/${entry.dbName}`);
}
info(colors.dim(` dir ${wt.path}`));
info(colors.dim(` ${running ? 'running' : 'stopped'}${entry ? '' : ' (not brought up yet)'}`));
}
info('');
info(colors.dim('Open: `code <dir>` / `lt ticket switch <id>` · Test: `lt ticket test <id>` · Stop: `lt ticket stop <id>`'));
info('');
if (!parameters.options.fromGluegunMenu)
process.exit();
return `ticket list: ${tickets.length}`;
}),
};
module.exports = ListCommand;