UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

106 lines (105 loc) 5.24 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 path_1 = require("path"); /** * Update branch */ const NewCommand = { alias: ['up'], description: 'Update branch', hidden: false, name: 'update', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; // Retrieve the tools we need const { config, git, helper, npm, parameters, print: { info, spin, success, warning }, system: { run, startTimer }, } = toolbox; // Parse dry-run flag early const dryRun = parameters.options.dryRun || parameters.options['dry-run']; // Check git if (!(yield git.gitInstalled())) { return; } // Load configuration const ltConfig = config.loadConfig(); const configSkipInstall = (_c = (_b = (_a = ltConfig === null || ltConfig === void 0 ? void 0 : ltConfig.commands) === null || _a === void 0 ? void 0 : _a.git) === null || _b === void 0 ? void 0 : _b.update) === null || _c === void 0 ? void 0 : _c.skipInstall; const globalSkipInstall = config.getGlobalDefault(ltConfig, 'skipInstall'); // Determine skipInstall with priority: CLI > config > global > default (false) const skipInstall = config.getValue({ cliValue: parameters.options.skipInstall || parameters.options['skip-install'], configValue: configSkipInstall, defaultValue: false, globalValue: globalSkipInstall, }); // Get current branch const branch = yield git.currentBranch(); // Dry-run mode: show what would happen if (dryRun) { warning('DRY-RUN MODE - No changes will be made'); info(''); info(`Current branch: ${branch}`); info(''); // Fetch to see incoming changes (use short SSH timeout so it doesn't hang offline) yield run('GIT_TERMINAL_PROMPT=0 GIT_SSH_COMMAND="ssh -o ConnectTimeout=5 -o BatchMode=yes" git fetch 2>/dev/null || true'); // Check for incoming commits const incomingCommits = yield run(`git log ${branch}..origin/${branch} --oneline 2>/dev/null || echo ""`); const commits = (incomingCommits === null || incomingCommits === void 0 ? void 0 : incomingCommits.trim().split('\n').filter((c) => c)) || []; if (commits.length > 0) { info(`Incoming commits (${commits.length}):`); commits.slice(0, 10).forEach((c) => info(` ${c}`)); if (commits.length > 10) { info(` ... and ${commits.length - 10} more`); } } else { info('No incoming commits - branch is up to date.'); } info(''); info('Steps that would be executed:'); info(' 1. git fetch'); info(' 2. git pull'); if (!skipInstall) { info(` 3. ${toolbox.pm.install()}`); } else { info(` 3. ${toolbox.pm.install()} (SKIPPED via config)`); } return `dry-run update branch ${branch}`; } // Start timer const timer = startTimer(); // Update const updateSpin = spin(`Update branch ${branch}`); yield run('GIT_TERMINAL_PROMPT=0 GIT_SSH_COMMAND="ssh -o ConnectTimeout=5 -o BatchMode=yes" git fetch 2>/dev/null || true && GIT_TERMINAL_PROMPT=0 GIT_SSH_COMMAND="ssh -o ConnectTimeout=5 -o BatchMode=yes" git pull --rebase'); updateSpin.succeed(); // Install packages (unless skipped) with correctly detected package manager (supports monorepo lockfiles) if (!skipInstall) { const { path: pkgPath } = yield npm.getPackageJson(); if (pkgPath) { const projectDir = (0, path_1.dirname)(pkgPath); const detectedPm = toolbox.pm.detect(projectDir); const installSpin = spin(`Install packages using ${detectedPm}`); yield run(`cd ${projectDir} && ${toolbox.pm.install(detectedPm)}`); installSpin.succeed(); } } // Success success(`Updated ${branch} in ${helper.msToMinutesAndSeconds(timer())}m.`); info(''); // Exit if not running from menu if (!toolbox.parameters.options.fromGluegunMenu) { process.exit(); } // For tests return `updated ${branch}`; }), }; exports.default = NewCommand;