UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

68 lines (67 loc) 3.08 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 }); /** * Undo current changes */ const NewCommand = { alias: ['cl'], description: 'Discard local changes', hidden: false, name: 'clear', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; // Retrieve the tools we need const { config, git, helper, parameters, print: { info, spin, success }, prompt: { confirm }, system: { run, startTimer }, } = toolbox; // Load configuration const ltConfig = config.loadConfig(); // Parse CLI arguments const dryRun = parameters.options.dryRun || parameters.options['dry-run']; // Determine noConfirm with priority: CLI > config > global > default (false) const noConfirm = config.getNoConfirm({ cliValue: parameters.options.noConfirm, commandConfig: (_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.clear, config: ltConfig, parentConfig: (_c = ltConfig === null || ltConfig === void 0 ? void 0 : ltConfig.commands) === null || _c === void 0 ? void 0 : _c.git, }); // Check git if (!(yield git.gitInstalled())) { return; } // Get current branch const branch = yield git.currentBranch(); // Dry-run mode: show what would be affected if (dryRun) { const result = yield git.showDryRunInfo({ branch, operation: 'discard' }); return result || `dry-run clear branch ${branch}`; } // Ask to clear the branch if (!noConfirm && !(yield confirm(`Clear "${branch}"?`))) { return; } // Start timer const timer = startTimer(); // Reset soft const undoSpinner = spin(`Clear ${branch}`); yield run('git reset --hard && git clean -fd'); undoSpinner.succeed(); // Success success(`Clear ${branch} in ${helper.msToMinutesAndSeconds(timer())}m.`); info(''); // Exit if not running from menu if (!toolbox.parameters.options.fromGluegunMenu) { process.exit(); } // For tests return `clear branch ${branch}`; }), }; exports.default = NewCommand;