UNPKG

@antfu/ni

Version:
1,590 lines 107 kB
import { a as __toESM, i as __require, n as __exportAll, r as __reExport, t as __commonJSMin } from "./chunk-CMuxRQOh.mjs"; import fs, { existsSync, promises } from "node:fs"; import path, { dirname, join, resolve } from "node:path"; import process$1 from "node:process"; import { AGENTS, detect } from "package-manager-detector"; import { INSTALL_PAGE } from "package-manager-detector/constants"; import { x } from "tinyexec"; import os from "node:os"; import { styleText } from "node:util"; //#region node_modules/.pnpm/ini@6.0.0/node_modules/ini/lib/ini.js var require_ini = /* @__PURE__ */ __commonJSMin(((exports, module) => { const { hasOwnProperty } = Object.prototype; const encode = (obj, opt = {}) => { if (typeof opt === "string") opt = { section: opt }; opt.align = opt.align === true; opt.newline = opt.newline === true; opt.sort = opt.sort === true; opt.whitespace = opt.whitespace === true || opt.align === true; /* istanbul ignore next */ opt.platform = opt.platform || typeof process !== "undefined" && process.platform; opt.bracketedArray = opt.bracketedArray !== false; /* istanbul ignore next */ const eol = opt.platform === "win32" ? "\r\n" : "\n"; const separator = opt.whitespace ? " = " : "="; const children = []; const keys = opt.sort ? Object.keys(obj).sort() : Object.keys(obj); let padToChars = 0; if (opt.align) padToChars = safe(keys.filter((k) => obj[k] === null || Array.isArray(obj[k]) || typeof obj[k] !== "object").map((k) => Array.isArray(obj[k]) ? `${k}[]` : k).concat([""]).reduce((a, b) => safe(a).length >= safe(b).length ? a : b)).length; let out = ""; const arraySuffix = opt.bracketedArray ? "[]" : ""; for (const k of keys) { const val = obj[k]; if (val && Array.isArray(val)) for (const item of val) out += safe(`${k}${arraySuffix}`).padEnd(padToChars, " ") + separator + safe(item) + eol; else if (val && typeof val === "object") children.push(k); else out += safe(k).padEnd(padToChars, " ") + separator + safe(val) + eol; } if (opt.section && out.length) out = "[" + safe(opt.section) + "]" + (opt.newline ? eol + eol : eol) + out; for (const k of children) { const nk = splitSections(k, ".").join("\\."); const section = (opt.section ? opt.section + "." : "") + nk; const child = encode(obj[k], { ...opt, section }); if (out.length && child.length) out += eol; out += child; } return out; }; function splitSections(str, separator) { var lastMatchIndex = 0; var lastSeparatorIndex = 0; var nextIndex = 0; var sections = []; do { nextIndex = str.indexOf(separator, lastMatchIndex); if (nextIndex !== -1) { lastMatchIndex = nextIndex + separator.length; if (nextIndex > 0 && str[nextIndex - 1] === "\\") continue; sections.push(str.slice(lastSeparatorIndex, nextIndex)); lastSeparatorIndex = nextIndex + separator.length; } } while (nextIndex !== -1); sections.push(str.slice(lastSeparatorIndex)); return sections; } const decode = (str, opt = {}) => { opt.bracketedArray = opt.bracketedArray !== false; const out = Object.create(null); let p = out; let section = null; const re = /^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i; const lines = str.split(/[\r\n]+/g); const duplicates = {}; for (const line of lines) { if (!line || line.match(/^\s*[;#]/) || line.match(/^\s*$/)) continue; const match = line.match(re); if (!match) continue; if (match[1] !== void 0) { section = unsafe(match[1]); if (section === "__proto__") { p = Object.create(null); continue; } p = out[section] = out[section] || Object.create(null); continue; } const keyRaw = unsafe(match[2]); let isArray; if (opt.bracketedArray) isArray = keyRaw.length > 2 && keyRaw.slice(-2) === "[]"; else { duplicates[keyRaw] = (duplicates?.[keyRaw] || 0) + 1; isArray = duplicates[keyRaw] > 1; } const key = isArray && keyRaw.endsWith("[]") ? keyRaw.slice(0, -2) : keyRaw; if (key === "__proto__") continue; const valueRaw = match[3] ? unsafe(match[4]) : true; const value = valueRaw === "true" || valueRaw === "false" || valueRaw === "null" ? JSON.parse(valueRaw) : valueRaw; if (isArray) { if (!hasOwnProperty.call(p, key)) p[key] = []; else if (!Array.isArray(p[key])) p[key] = [p[key]]; } if (Array.isArray(p[key])) p[key].push(value); else p[key] = value; } const remove = []; for (const k of Object.keys(out)) { if (!hasOwnProperty.call(out, k) || typeof out[k] !== "object" || Array.isArray(out[k])) continue; const parts = splitSections(k, "."); p = out; const l = parts.pop(); const nl = l.replace(/\\\./g, "."); for (const part of parts) { if (part === "__proto__") continue; if (!hasOwnProperty.call(p, part) || typeof p[part] !== "object") p[part] = Object.create(null); p = p[part]; } if (p === out && nl === l) continue; p[nl] = out[k]; remove.push(k); } for (const del of remove) delete out[del]; return out; }; const isQuoted = (val) => { return val.startsWith("\"") && val.endsWith("\"") || val.startsWith("'") && val.endsWith("'"); }; const safe = (val) => { if (typeof val !== "string" || val.match(/[=\r\n]/) || val.match(/^\[/) || val.length > 1 && isQuoted(val) || val !== val.trim()) return JSON.stringify(val); return val.split(";").join("\\;").split("#").join("\\#"); }; const unsafe = (val) => { val = (val || "").trim(); if (isQuoted(val)) { if (val.charAt(0) === "'") val = val.slice(1, -1); try { val = JSON.parse(val); } catch {} } else { let esc = false; let unesc = ""; for (let i = 0, l = val.length; i < l; i++) { const c = val.charAt(i); if (esc) { if ("\\;#".indexOf(c) !== -1) unesc += c; else unesc += "\\" + c; esc = false; } else if (";#".indexOf(c) !== -1) break; else if (c === "\\") esc = true; else unesc += c; } if (esc) unesc += "\\"; return unesc.trim(); } return val; }; module.exports = { parse: decode, decode, stringify: encode, encode, safe, unsafe }; })); //#endregion //#region node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.js var require_kleur = /* @__PURE__ */ __commonJSMin(((exports, module) => { let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true; if (typeof process !== "undefined") { ({FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM} = process.env || {}); isTTY = process.stdout && process.stdout.isTTY; } const $ = { enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY), reset: init(0, 0), bold: init(1, 22), dim: init(2, 22), italic: init(3, 23), underline: init(4, 24), inverse: init(7, 27), hidden: init(8, 28), strikethrough: init(9, 29), black: init(30, 39), red: init(31, 39), green: init(32, 39), yellow: init(33, 39), blue: init(34, 39), magenta: init(35, 39), cyan: init(36, 39), white: init(37, 39), gray: init(90, 39), grey: init(90, 39), bgBlack: init(40, 49), bgRed: init(41, 49), bgGreen: init(42, 49), bgYellow: init(43, 49), bgBlue: init(44, 49), bgMagenta: init(45, 49), bgCyan: init(46, 49), bgWhite: init(47, 49) }; function run(arr, str) { let i = 0, tmp, beg = "", end = ""; for (; i < arr.length; i++) { tmp = arr[i]; beg += tmp.open; end += tmp.close; if (!!~str.indexOf(tmp.close)) str = str.replace(tmp.rgx, tmp.close + tmp.open); } return beg + str + end; } function chain(has, keys) { let ctx = { has, keys }; ctx.reset = $.reset.bind(ctx); ctx.bold = $.bold.bind(ctx); ctx.dim = $.dim.bind(ctx); ctx.italic = $.italic.bind(ctx); ctx.underline = $.underline.bind(ctx); ctx.inverse = $.inverse.bind(ctx); ctx.hidden = $.hidden.bind(ctx); ctx.strikethrough = $.strikethrough.bind(ctx); ctx.black = $.black.bind(ctx); ctx.red = $.red.bind(ctx); ctx.green = $.green.bind(ctx); ctx.yellow = $.yellow.bind(ctx); ctx.blue = $.blue.bind(ctx); ctx.magenta = $.magenta.bind(ctx); ctx.cyan = $.cyan.bind(ctx); ctx.white = $.white.bind(ctx); ctx.gray = $.gray.bind(ctx); ctx.grey = $.grey.bind(ctx); ctx.bgBlack = $.bgBlack.bind(ctx); ctx.bgRed = $.bgRed.bind(ctx); ctx.bgGreen = $.bgGreen.bind(ctx); ctx.bgYellow = $.bgYellow.bind(ctx); ctx.bgBlue = $.bgBlue.bind(ctx); ctx.bgMagenta = $.bgMagenta.bind(ctx); ctx.bgCyan = $.bgCyan.bind(ctx); ctx.bgWhite = $.bgWhite.bind(ctx); return ctx; } function init(open, close) { let blk = { open: `\x1b[${open}m`, close: `\x1b[${close}m`, rgx: new RegExp(`\\x1b\\[${close}m`, "g") }; return function(txt) { if (this !== void 0 && this.has !== void 0) { ~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk)); return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + ""; } return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + ""; }; } module.exports = $; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/action.js var require_action = /* @__PURE__ */ __commonJSMin(((exports, module) => { module.exports = (key, isSelect) => { if (key.meta && key.name !== "escape") return; if (key.ctrl) { if (key.name === "a") return "first"; if (key.name === "c") return "abort"; if (key.name === "d") return "abort"; if (key.name === "e") return "last"; if (key.name === "g") return "reset"; if (key.name === "n") return "down"; if (key.name === "p") return "up"; return; } if (isSelect) { if (key.name === "j") return "down"; if (key.name === "k") return "up"; } if (key.name === "return") return "submit"; if (key.name === "enter") return "submit"; if (key.name === "backspace") return "delete"; if (key.name === "delete") return "deleteForward"; if (key.name === "abort") return "abort"; if (key.name === "escape") return "exit"; if (key.name === "tab") return "next"; if (key.name === "pagedown") return "nextPage"; if (key.name === "pageup") return "prevPage"; if (key.name === "home") return "home"; if (key.name === "end") return "end"; if (key.name === "up") return "up"; if (key.name === "down") return "down"; if (key.name === "right") return "right"; if (key.name === "left") return "left"; return false; }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/strip.js var require_strip = /* @__PURE__ */ __commonJSMin(((exports, module) => { module.exports = (str) => { const pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"].join("|"); const RGX = new RegExp(pattern, "g"); return typeof str === "string" ? str.replace(RGX, "") : str; }; })); //#endregion //#region node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => { const ESC = "\x1B"; const CSI = `${ESC}[`; const beep = "\x07"; const cursor = { to(x, y) { if (!y) return `${CSI}${x + 1}G`; return `${CSI}${y + 1};${x + 1}H`; }, move(x, y) { let ret = ""; if (x < 0) ret += `${CSI}${-x}D`; else if (x > 0) ret += `${CSI}${x}C`; if (y < 0) ret += `${CSI}${-y}A`; else if (y > 0) ret += `${CSI}${y}B`; return ret; }, up: (count = 1) => `${CSI}${count}A`, down: (count = 1) => `${CSI}${count}B`, forward: (count = 1) => `${CSI}${count}C`, backward: (count = 1) => `${CSI}${count}D`, nextLine: (count = 1) => `${CSI}E`.repeat(count), prevLine: (count = 1) => `${CSI}F`.repeat(count), left: `${CSI}G`, hide: `${CSI}?25l`, show: `${CSI}?25h`, save: `${ESC}7`, restore: `${ESC}8` }; module.exports = { cursor, scroll: { up: (count = 1) => `${CSI}S`.repeat(count), down: (count = 1) => `${CSI}T`.repeat(count) }, erase: { screen: `${CSI}2J`, up: (count = 1) => `${CSI}1J`.repeat(count), down: (count = 1) => `${CSI}J`.repeat(count), line: `${CSI}2K`, lineEnd: `${CSI}K`, lineStart: `${CSI}1K`, lines(count) { let clear = ""; for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : ""); if (count) clear += cursor.left; return clear; } }, beep }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/clear.js var require_clear = /* @__PURE__ */ __commonJSMin(((exports, module) => { const strip = require_strip(); const { erase, cursor } = require_src(); const width = (str) => [...strip(str)].length; /** * @param {string} prompt * @param {number} perLine */ module.exports = function(prompt, perLine) { if (!perLine) return erase.line + cursor.to(0); let rows = 0; const lines = prompt.split(/\r?\n/); for (let line of lines) rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine); return erase.lines(rows); }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/figures.js var require_figures = /* @__PURE__ */ __commonJSMin(((exports, module) => { const main = { arrowUp: "↑", arrowDown: "↓", arrowLeft: "←", arrowRight: "→", radioOn: "◉", radioOff: "◯", tick: "✔", cross: "✖", ellipsis: "…", pointerSmall: "›", line: "─", pointer: "❯" }; const win = { arrowUp: main.arrowUp, arrowDown: main.arrowDown, arrowLeft: main.arrowLeft, arrowRight: main.arrowRight, radioOn: "(*)", radioOff: "( )", tick: "√", cross: "×", ellipsis: "...", pointerSmall: "»", line: "─", pointer: ">" }; module.exports = process.platform === "win32" ? win : main; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/style.js var require_style = /* @__PURE__ */ __commonJSMin(((exports, module) => { const c = require_kleur(); const figures = require_figures(); const styles = Object.freeze({ password: { scale: 1, render: (input) => "*".repeat(input.length) }, emoji: { scale: 2, render: (input) => "😃".repeat(input.length) }, invisible: { scale: 0, render: (input) => "" }, default: { scale: 1, render: (input) => `${input}` } }); const render = (type) => styles[type] || styles.default; const symbols = Object.freeze({ aborted: c.red(figures.cross), done: c.green(figures.tick), exited: c.yellow(figures.cross), default: c.cyan("?") }); const symbol = (done, aborted, exited) => aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default; const delimiter = (completing) => c.gray(completing ? figures.ellipsis : figures.pointerSmall); const item = (expandable, expanded) => c.gray(expandable ? expanded ? figures.pointerSmall : "+" : figures.line); module.exports = { styles, render, symbols, symbol, delimiter, item }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/lines.js var require_lines = /* @__PURE__ */ __commonJSMin(((exports, module) => { const strip = require_strip(); /** * @param {string} msg * @param {number} perLine */ module.exports = function(msg, perLine) { let lines = String(strip(msg) || "").split(/\r?\n/); if (!perLine) return lines.length; return lines.map((l) => Math.ceil(l.length / perLine)).reduce((a, b) => a + b); }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/wrap.js var require_wrap = /* @__PURE__ */ __commonJSMin(((exports, module) => { /** * @param {string} msg The message to wrap * @param {object} opts * @param {number|string} [opts.margin] Left margin * @param {number} opts.width Maximum characters per line including the margin */ module.exports = (msg, opts = {}) => { const tab = Number.isSafeInteger(parseInt(opts.margin)) ? new Array(parseInt(opts.margin)).fill(" ").join("") : opts.margin || ""; const width = opts.width; return (msg || "").split(/\r?\n/g).map((line) => line.split(/\s+/g).reduce((arr, w) => { if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width) arr[arr.length - 1] += ` ${w}`; else arr.push(`${tab}${w}`); return arr; }, [tab]).join("\n")).join("\n"); }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/entriesToDisplay.js var require_entriesToDisplay = /* @__PURE__ */ __commonJSMin(((exports, module) => { /** * Determine what entries should be displayed on the screen, based on the * currently selected index and the maximum visible. Used in list-based * prompts like `select` and `multiselect`. * * @param {number} cursor the currently selected entry * @param {number} total the total entries available to display * @param {number} [maxVisible] the number of entries that can be displayed */ module.exports = (cursor, total, maxVisible) => { maxVisible = maxVisible || total; let startIndex = Math.min(total - maxVisible, cursor - Math.floor(maxVisible / 2)); if (startIndex < 0) startIndex = 0; let endIndex = Math.min(startIndex + maxVisible, total); return { startIndex, endIndex }; }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/util/index.js var require_util = /* @__PURE__ */ __commonJSMin(((exports, module) => { module.exports = { action: require_action(), clear: require_clear(), style: require_style(), strip: require_strip(), figures: require_figures(), lines: require_lines(), wrap: require_wrap(), entriesToDisplay: require_entriesToDisplay() }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/elements/prompt.js var require_prompt = /* @__PURE__ */ __commonJSMin(((exports, module) => { const readline = __require("readline"); const { action } = require_util(); const EventEmitter = __require("events"); const { beep, cursor } = require_src(); const color = require_kleur(); /** * Base prompt skeleton * @param {Stream} [opts.stdin] The Readable stream to listen to * @param {Stream} [opts.stdout] The Writable stream to write readline data to */ var Prompt = class extends EventEmitter { constructor(opts = {}) { super(); this.firstRender = true; this.in = opts.stdin || process.stdin; this.out = opts.stdout || process.stdout; this.onRender = (opts.onRender || (() => void 0)).bind(this); const rl = readline.createInterface({ input: this.in, escapeCodeTimeout: 50 }); readline.emitKeypressEvents(this.in, rl); if (this.in.isTTY) this.in.setRawMode(true); const isSelect = ["SelectPrompt", "MultiselectPrompt"].indexOf(this.constructor.name) > -1; const keypress = (str, key) => { let a = action(key, isSelect); if (a === false) this._ && this._(str, key); else if (typeof this[a] === "function") this[a](key); else this.bell(); }; this.close = () => { this.out.write(cursor.show); this.in.removeListener("keypress", keypress); if (this.in.isTTY) this.in.setRawMode(false); rl.close(); this.emit(this.aborted ? "abort" : this.exited ? "exit" : "submit", this.value); this.closed = true; }; this.in.on("keypress", keypress); } fire() { this.emit("state", { value: this.value, aborted: !!this.aborted, exited: !!this.exited }); } bell() { this.out.write(beep); } render() { this.onRender(color); if (this.firstRender) this.firstRender = false; } }; module.exports = Prompt; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/elements/text.js var require_text = /* @__PURE__ */ __commonJSMin(((exports, module) => { const color = require_kleur(); const Prompt = require_prompt(); const { erase, cursor } = require_src(); const { style, clear, lines, figures } = require_util(); /** * TextPrompt Base Element * @param {Object} opts Options * @param {String} opts.message Message * @param {String} [opts.style='default'] Render style * @param {String} [opts.initial] Default value * @param {Function} [opts.validate] Validate function * @param {Stream} [opts.stdin] The Readable stream to listen to * @param {Stream} [opts.stdout] The Writable stream to write readline data to * @param {String} [opts.error] The invalid error label */ var TextPrompt = class extends Prompt { constructor(opts = {}) { super(opts); this.transform = style.render(opts.style); this.scale = this.transform.scale; this.msg = opts.message; this.initial = opts.initial || ``; this.validator = opts.validate || (() => true); this.value = ``; this.errorMsg = opts.error || `Please Enter A Valid Value`; this.cursor = Number(!!this.initial); this.cursorOffset = 0; this.clear = clear(``, this.out.columns); this.render(); } set value(v) { if (!v && this.initial) { this.placeholder = true; this.rendered = color.gray(this.transform.render(this.initial)); } else { this.placeholder = false; this.rendered = this.transform.render(v); } this._value = v; this.fire(); } get value() { return this._value; } reset() { this.value = ``; this.cursor = Number(!!this.initial); this.cursorOffset = 0; this.fire(); this.render(); } exit() { this.abort(); } abort() { this.value = this.value || this.initial; this.done = this.aborted = true; this.error = false; this.red = false; this.fire(); this.render(); this.out.write("\n"); this.close(); } async validate() { let valid = await this.validator(this.value); if (typeof valid === `string`) { this.errorMsg = valid; valid = false; } this.error = !valid; } async submit() { this.value = this.value || this.initial; this.cursorOffset = 0; this.cursor = this.rendered.length; await this.validate(); if (this.error) { this.red = true; this.fire(); this.render(); return; } this.done = true; this.aborted = false; this.fire(); this.render(); this.out.write("\n"); this.close(); } next() { if (!this.placeholder) return this.bell(); this.value = this.initial; this.cursor = this.rendered.length; this.fire(); this.render(); } moveCursor(n) { if (this.placeholder) return; this.cursor = this.cursor + n; this.cursorOffset += n; } _(c, key) { let s1 = this.value.slice(0, this.cursor); this.value = `${s1}${c}${this.value.slice(this.cursor)}`; this.red = false; this.cursor = this.placeholder ? 0 : s1.length + 1; this.render(); } delete() { if (this.isCursorAtStart()) return this.bell(); this.value = `${this.value.slice(0, this.cursor - 1)}${this.value.slice(this.cursor)}`; this.red = false; if (this.isCursorAtStart()) this.cursorOffset = 0; else { this.cursorOffset++; this.moveCursor(-1); } this.render(); } deleteForward() { if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell(); this.value = `${this.value.slice(0, this.cursor)}${this.value.slice(this.cursor + 1)}`; this.red = false; if (this.isCursorAtEnd()) this.cursorOffset = 0; else this.cursorOffset++; this.render(); } first() { this.cursor = 0; this.render(); } last() { this.cursor = this.value.length; this.render(); } left() { if (this.cursor <= 0 || this.placeholder) return this.bell(); this.moveCursor(-1); this.render(); } right() { if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell(); this.moveCursor(1); this.render(); } isCursorAtStart() { return this.cursor === 0 || this.placeholder && this.cursor === 1; } isCursorAtEnd() { return this.cursor === this.rendered.length || this.placeholder && this.cursor === this.rendered.length + 1; } render() { if (this.closed) return; if (!this.firstRender) { if (this.outputError) this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns)); this.out.write(clear(this.outputText, this.out.columns)); } super.render(); this.outputError = ""; this.outputText = [ style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.red ? color.red(this.rendered) : this.rendered ].join(` `); if (this.error) this.outputError += this.errorMsg.split(`\n`).reduce((a, l, i) => a + `\n${i ? " " : figures.pointerSmall} ${color.red().italic(l)}`, ``); this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore + cursor.move(this.cursorOffset, 0)); } }; module.exports = TextPrompt; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/elements/select.js var require_select = /* @__PURE__ */ __commonJSMin(((exports, module) => { const color = require_kleur(); const Prompt = require_prompt(); const { style, clear, figures, wrap, entriesToDisplay } = require_util(); const { cursor } = require_src(); /** * SelectPrompt Base Element * @param {Object} opts Options * @param {String} opts.message Message * @param {Array} opts.choices Array of choice objects * @param {String} [opts.hint] Hint to display * @param {Number} [opts.initial] Index of default value * @param {Stream} [opts.stdin] The Readable stream to listen to * @param {Stream} [opts.stdout] The Writable stream to write readline data to * @param {Number} [opts.optionsPerPage=10] Max options to display at once */ var SelectPrompt = class extends Prompt { constructor(opts = {}) { super(opts); this.msg = opts.message; this.hint = opts.hint || "- Use arrow-keys. Return to submit."; this.warn = opts.warn || "- This option is disabled"; this.cursor = opts.initial || 0; this.choices = opts.choices.map((ch, idx) => { if (typeof ch === "string") ch = { title: ch, value: idx }; return { title: ch && (ch.title || ch.value || ch), value: ch && (ch.value === void 0 ? idx : ch.value), description: ch && ch.description, selected: ch && ch.selected, disabled: ch && ch.disabled }; }); this.optionsPerPage = opts.optionsPerPage || 10; this.value = (this.choices[this.cursor] || {}).value; this.clear = clear("", this.out.columns); this.render(); } moveCursor(n) { this.cursor = n; this.value = this.choices[n].value; this.fire(); } reset() { this.moveCursor(0); this.fire(); this.render(); } exit() { this.abort(); } abort() { this.done = this.aborted = true; this.fire(); this.render(); this.out.write("\n"); this.close(); } submit() { if (!this.selection.disabled) { this.done = true; this.aborted = false; this.fire(); this.render(); this.out.write("\n"); this.close(); } else this.bell(); } first() { this.moveCursor(0); this.render(); } last() { this.moveCursor(this.choices.length - 1); this.render(); } up() { if (this.cursor === 0) this.moveCursor(this.choices.length - 1); else this.moveCursor(this.cursor - 1); this.render(); } down() { if (this.cursor === this.choices.length - 1) this.moveCursor(0); else this.moveCursor(this.cursor + 1); this.render(); } next() { this.moveCursor((this.cursor + 1) % this.choices.length); this.render(); } _(c, key) { if (c === " ") return this.submit(); } get selection() { return this.choices[this.cursor]; } render() { if (this.closed) return; if (this.firstRender) this.out.write(cursor.hide); else this.out.write(clear(this.outputText, this.out.columns)); super.render(); let { startIndex, endIndex } = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage); this.outputText = [ style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint) ].join(" "); if (!this.done) { this.outputText += "\n"; for (let i = startIndex; i < endIndex; i++) { let title, prefix, desc = "", v = this.choices[i]; if (i === startIndex && startIndex > 0) prefix = figures.arrowUp; else if (i === endIndex - 1 && endIndex < this.choices.length) prefix = figures.arrowDown; else prefix = " "; if (v.disabled) { title = this.cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title); prefix = (this.cursor === i ? color.bold().gray(figures.pointer) + " " : " ") + prefix; } else { title = this.cursor === i ? color.cyan().underline(v.title) : v.title; prefix = (this.cursor === i ? color.cyan(figures.pointer) + " " : " ") + prefix; if (v.description && this.cursor === i) { desc = ` - ${v.description}`; if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) desc = "\n" + wrap(v.description, { margin: 3, width: this.out.columns }); } } this.outputText += `${prefix} ${title}${color.gray(desc)}\n`; } } this.out.write(this.outputText); } }; module.exports = SelectPrompt; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/elements/toggle.js var require_toggle = /* @__PURE__ */ __commonJSMin(((exports, module) => { const color = require_kleur(); const Prompt = require_prompt(); const { style, clear } = require_util(); const { cursor, erase } = require_src(); /** * TogglePrompt Base Element * @param {Object} opts Options * @param {String} opts.message Message * @param {Boolean} [opts.initial=false] Default value * @param {String} [opts.active='no'] Active label * @param {String} [opts.inactive='off'] Inactive label * @param {Stream} [opts.stdin] The Readable stream to listen to * @param {Stream} [opts.stdout] The Writable stream to write readline data to */ var TogglePrompt = class extends Prompt { constructor(opts = {}) { super(opts); this.msg = opts.message; this.value = !!opts.initial; this.active = opts.active || "on"; this.inactive = opts.inactive || "off"; this.initialValue = this.value; this.render(); } reset() { this.value = this.initialValue; this.fire(); this.render(); } exit() { this.abort(); } abort() { this.done = this.aborted = true; this.fire(); this.render(); this.out.write("\n"); this.close(); } submit() { this.done = true; this.aborted = false; this.fire(); this.render(); this.out.write("\n"); this.close(); } deactivate() { if (this.value === false) return this.bell(); this.value = false; this.render(); } activate() { if (this.value === true) return this.bell(); this.value = true; this.render(); } delete() { this.deactivate(); } left() { this.deactivate(); } right() { this.activate(); } down() { this.deactivate(); } up() { this.activate(); } next() { this.value = !this.value; this.fire(); this.render(); } _(c, key) { if (c === " ") this.value = !this.value; else if (c === "1") this.value = true; else if (c === "0") this.value = false; else return this.bell(); this.render(); } render() { if (this.closed) return; if (this.firstRender) this.out.write(cursor.hide); else this.out.write(clear(this.outputText, this.out.columns)); super.render(); this.outputText = [ style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.value ? this.inactive : color.cyan().underline(this.inactive), color.gray("/"), this.value ? color.cyan().underline(this.active) : this.active ].join(" "); this.out.write(erase.line + cursor.to(0) + this.outputText); } }; module.exports = TogglePrompt; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/datepart.js var require_datepart = /* @__PURE__ */ __commonJSMin(((exports, module) => { module.exports = class DatePart { constructor({ token, date, parts, locales }) { this.token = token; this.date = date || /* @__PURE__ */ new Date(); this.parts = parts || [this]; this.locales = locales || {}; } up() {} down() {} next() { const currentIdx = this.parts.indexOf(this); return this.parts.find((part, idx) => idx > currentIdx && part instanceof DatePart); } setTo(val) {} prev() { let parts = [].concat(this.parts).reverse(); const currentIdx = parts.indexOf(this); return parts.find((part, idx) => idx > currentIdx && part instanceof DatePart); } toString() { return String(this.date); } }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/meridiem.js var require_meridiem = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Meridiem = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setHours((this.date.getHours() + 12) % 24); } down() { this.up(); } toString() { let meridiem = this.date.getHours() > 12 ? "pm" : "am"; return /\A/.test(this.token) ? meridiem.toUpperCase() : meridiem; } }; module.exports = Meridiem; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/day.js var require_day = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); const pos = (n) => { n = n % 10; return n === 1 ? "st" : n === 2 ? "nd" : n === 3 ? "rd" : "th"; }; var Day = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setDate(this.date.getDate() + 1); } down() { this.date.setDate(this.date.getDate() - 1); } setTo(val) { this.date.setDate(parseInt(val.substr(-2))); } toString() { let date = this.date.getDate(); let day = this.date.getDay(); return this.token === "DD" ? String(date).padStart(2, "0") : this.token === "Do" ? date + pos(date) : this.token === "d" ? day + 1 : this.token === "ddd" ? this.locales.weekdaysShort[day] : this.token === "dddd" ? this.locales.weekdays[day] : date; } }; module.exports = Day; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/hours.js var require_hours = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Hours = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setHours(this.date.getHours() + 1); } down() { this.date.setHours(this.date.getHours() - 1); } setTo(val) { this.date.setHours(parseInt(val.substr(-2))); } toString() { let hours = this.date.getHours(); if (/h/.test(this.token)) hours = hours % 12 || 12; return this.token.length > 1 ? String(hours).padStart(2, "0") : hours; } }; module.exports = Hours; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/milliseconds.js var require_milliseconds = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Milliseconds = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setMilliseconds(this.date.getMilliseconds() + 1); } down() { this.date.setMilliseconds(this.date.getMilliseconds() - 1); } setTo(val) { this.date.setMilliseconds(parseInt(val.substr(-this.token.length))); } toString() { return String(this.date.getMilliseconds()).padStart(4, "0").substr(0, this.token.length); } }; module.exports = Milliseconds; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/minutes.js var require_minutes = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Minutes = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setMinutes(this.date.getMinutes() + 1); } down() { this.date.setMinutes(this.date.getMinutes() - 1); } setTo(val) { this.date.setMinutes(parseInt(val.substr(-2))); } toString() { let m = this.date.getMinutes(); return this.token.length > 1 ? String(m).padStart(2, "0") : m; } }; module.exports = Minutes; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/month.js var require_month = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Month = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setMonth(this.date.getMonth() + 1); } down() { this.date.setMonth(this.date.getMonth() - 1); } setTo(val) { val = parseInt(val.substr(-2)) - 1; this.date.setMonth(val < 0 ? 0 : val); } toString() { let month = this.date.getMonth(); let tl = this.token.length; return tl === 2 ? String(month + 1).padStart(2, "0") : tl === 3 ? this.locales.monthsShort[month] : tl === 4 ? this.locales.months[month] : String(month + 1); } }; module.exports = Month; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/seconds.js var require_seconds = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Seconds = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setSeconds(this.date.getSeconds() + 1); } down() { this.date.setSeconds(this.date.getSeconds() - 1); } setTo(val) { this.date.setSeconds(parseInt(val.substr(-2))); } toString() { let s = this.date.getSeconds(); return this.token.length > 1 ? String(s).padStart(2, "0") : s; } }; module.exports = Seconds; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/year.js var require_year = /* @__PURE__ */ __commonJSMin(((exports, module) => { const DatePart = require_datepart(); var Year = class extends DatePart { constructor(opts = {}) { super(opts); } up() { this.date.setFullYear(this.date.getFullYear() + 1); } down() { this.date.setFullYear(this.date.getFullYear() - 1); } setTo(val) { this.date.setFullYear(val.substr(-4)); } toString() { let year = String(this.date.getFullYear()).padStart(4, "0"); return this.token.length === 2 ? year.substr(-2) : year; } }; module.exports = Year; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/dateparts/index.js var require_dateparts = /* @__PURE__ */ __commonJSMin(((exports, module) => { module.exports = { DatePart: require_datepart(), Meridiem: require_meridiem(), Day: require_day(), Hours: require_hours(), Milliseconds: require_milliseconds(), Minutes: require_minutes(), Month: require_month(), Seconds: require_seconds(), Year: require_year() }; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/elements/date.js var require_date = /* @__PURE__ */ __commonJSMin(((exports, module) => { const color = require_kleur(); const Prompt = require_prompt(); const { style, clear, figures } = require_util(); const { erase, cursor } = require_src(); const { DatePart, Meridiem, Day, Hours, Milliseconds, Minutes, Month, Seconds, Year } = require_dateparts(); const regex = /\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g; const regexGroups = { 1: ({ token }) => token.replace(/\\(.)/g, "$1"), 2: (opts) => new Day(opts), 3: (opts) => new Month(opts), 4: (opts) => new Year(opts), 5: (opts) => new Meridiem(opts), 6: (opts) => new Hours(opts), 7: (opts) => new Minutes(opts), 8: (opts) => new Seconds(opts), 9: (opts) => new Milliseconds(opts) }; const dfltLocales = { months: "January,February,March,April,May,June,July,August,September,October,November,December".split(","), monthsShort: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","), weekdays: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","), weekdaysShort: "Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(",") }; /** * DatePrompt Base Element * @param {Object} opts Options * @param {String} opts.message Message * @param {Number} [opts.initial] Index of default value * @param {String} [opts.mask] The format mask * @param {object} [opts.locales] The date locales * @param {String} [opts.error] The error message shown on invalid value * @param {Function} [opts.validate] Function to validate the submitted value * @param {Stream} [opts.stdin] The Readable stream to listen to * @param {Stream} [opts.stdout] The Writable stream to write readline data to */ var DatePrompt = class extends Prompt { constructor(opts = {}) { super(opts); this.msg = opts.message; this.cursor = 0; this.typed = ""; this.locales = Object.assign(dfltLocales, opts.locales); this._date = opts.initial || /* @__PURE__ */ new Date(); this.errorMsg = opts.error || "Please Enter A Valid Value"; this.validator = opts.validate || (() => true); this.mask = opts.mask || "YYYY-MM-DD HH:mm:ss"; this.clear = clear("", this.out.columns); this.render(); } get value() { return this.date; } get date() { return this._date; } set date(date) { if (date) this._date.setTime(date.getTime()); } set mask(mask) { let result; this.parts = []; while (result = regex.exec(mask)) { let match = result.shift(); let idx = result.findIndex((gr) => gr != null); this.parts.push(idx in regexGroups ? regexGroups[idx]({ token: result[idx] || match, date: this.date, parts: this.parts, locales: this.locales }) : result[idx] || match); } let parts = this.parts.reduce((arr, i) => { if (typeof i === "string" && typeof arr[arr.length - 1] === "string") arr[arr.length - 1] += i; else arr.push(i); return arr; }, []); this.parts.splice(0); this.parts.push(...parts); this.reset(); } moveCursor(n) { this.typed = ""; this.cursor = n; this.fire(); } reset() { this.moveCursor(this.parts.findIndex((p) => p instanceof DatePart)); this.fire(); this.render(); } exit() { this.abort(); } abort() { this.done = this.aborted = true; this.error = false; this.fire(); this.render(); this.out.write("\n"); this.close(); } async validate() { let valid = await this.validator(this.value); if (typeof valid === "string") { this.errorMsg = valid; valid = false; } this.error = !valid; } async submit() { await this.validate(); if (this.error) { this.color = "red"; this.fire(); this.render(); return; } this.done = true; this.aborted = false; this.fire(); this.render(); this.out.write("\n"); this.close(); } up() { this.typed = ""; this.parts[this.cursor].up(); this.render(); } down() { this.typed = ""; this.parts[this.cursor].down(); this.render(); } left() { let prev = this.parts[this.cursor].prev(); if (prev == null) return this.bell(); this.moveCursor(this.parts.indexOf(prev)); this.render(); } right() { let next = this.parts[this.cursor].next(); if (next == null) return this.bell(); this.moveCursor(this.parts.indexOf(next)); this.render(); } next() { let next = this.parts[this.cursor].next(); this.moveCursor(next ? this.parts.indexOf(next) : this.parts.findIndex((part) => part instanceof DatePart)); this.render(); } _(c) { if (/\d/.test(c)) { this.typed += c; this.parts[this.cursor].setTo(this.typed); this.render(); } } render() { if (this.closed) return; if (this.firstRender) this.out.write(cursor.hide); else this.out.write(clear(this.outputText, this.out.columns)); super.render(); this.outputText = [ style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(false), this.parts.reduce((arr, p, idx) => arr.concat(idx === this.cursor && !this.done ? color.cyan().underline(p.toString()) : p), []).join("") ].join(" "); if (this.error) this.outputText += this.errorMsg.split("\n").reduce((a, l, i) => a + `\n${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``); this.out.write(erase.line + cursor.to(0) + this.outputText); } }; module.exports = DatePrompt; })); //#endregion //#region node_modules/.pnpm/@posva+prompts@2.4.4/node_modules/@posva/prompts/lib/elements/number.js var require_number = /* @__PURE__ */ __commonJSMin(((exports, module) => { const color = require_kleur(); const Prompt = require_prompt(); const { cursor, erase } = require_src(); const { style, figures, clear, lines } = require_util(); const isNumber = /[0-9]/; const isDef = (any) => any !== void 0; const round = (number, precision) => { let factor = Math.pow(10, precision); return Math.round(number * factor) / factor; }; /** * NumberPrompt Base Element * @param {Object} opts Options * @param {String} opts.message Message * @param {String} [opts.style='default'] Render style * @param {Number} [opts.initial] Default value * @param {Number} [opts.max=+Infinity] Max value * @param {Number} [opts.min=-Infinity] Min value * @param {Boolean} [opts.float=false] Parse input as floats * @param {Number} [opts.round=2] Round floats to x decimals * @param {Number} [opts.increment=1] Number to increment by when using arrow-keys * @param {Function} [opts.validate] Validate function * @param {Stream} [opts.stdin] The Readable stream to listen to * @param {Stream} [opts.stdout] The Writable stream to write readline data to * @param {String} [opts.error] The invalid error label */ var NumberPrompt = class extends Prompt { constructor(opts = {}) { super(opts); this.transform = style.render(opts.style); this.msg = opts.message; this.initial = isDef(opts.initial) ? opts.initial : ""; this.float = !!opts.float; this.round = opts.round || 2; this.inc = opts.increment || 1; this.min = isDef(opts.min) ? opts.min : -Infinity; this.max = isDef(opts.max) ? opts.max : Infinity; this.errorMsg = opts.error || `Please Enter A Valid Value`; this.validator = opts.validate || (() => true); this.color = `cyan`; this.value = ``; this.typed = ``; this.lastHit = 0; this.render(); } set value(v) { if (!v && v !== 0) { this.placeholder = true; this.rendered = color.gray(this.transform.render(`${this.initial}`)); this._value = ``; } else { this.placeholder = false; this.rendered = this.transform.render(`${round(v, this.round)}`); this._value = round(v, this.round); } this.fire(); } get value() { return this._value; } parse(x) { return this.float ? parseFloat(x) : parseInt(x); } valid(c) { return c === `-` || c === `.` && this.float || isNumber.test(c); } reset() { this.typed = ``; this.value = ``; this.fire(); this.render(); } exit() { this.abort(); } abort() { let x = this.value; this.value = x !== `` ? x : this.initial; this.done = this.aborted = true; this.error = false; this.fire(); this.render(); this.out.write(`\n`); this.close(); } async validate() { let valid = await this.validator(this.value); if (typeof valid === `string`) { this.errorMsg = valid; valid = false; } this.error = !valid; } async submit() { await this.validate(); if (this.error) { this.color = `red`; this.fire(); this.render(); return; } let x = this.value; this.value = x !== `` ? x : this.initial; this.done = true; this.aborted = false; this.error = false; this.fire(); this.render(); this.out.write(`\n`); this.close(); } up() { this.typed = ``; if (this.value === "") this.value = this.min - this.inc; if (this.value >= this.max) return this.bell(); this.value += this.inc; this.color = `cyan`; this.fire(); this.render(); } down() { this.typed = ``; if (this.value === "") this.value = this.min + this.inc; if (this.value <= this.min) return this.bell(); this.value -= this.inc; this.color = `cyan`; this.fire(); this.render(); } delete() { let val = this.value.toString(); if (val.length === 0) return this.bell(); this.value = this.parse(val = val.slice(0, -1)) || ``; if (this.value !== "" && this.value < this.min) this.value = this.min; this.color = `cyan`; this.fire(); this.render(); } next() { this.value = this.initial; this.fire(); this.render(); } _(c, key) { if (!this.valid(c)) return this.bell(); const now = Date.now(); if (now - this.lastHit > 1e3) this.typed = ``; this.typed += c; this.lastHit = now; this.color = `cyan`; if (c === `.`) return this.fire(); this.value = Math.min(this.parse(this.typed), this.max); if (this.value > this.max) this.value = this.max; if (this.value < this.min) this.value = this.min; this.fire(); this.render(); } render() { if (this.closed) return; if (!this.firstRender) { if (this.outputError) this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns)); this.out.write(clear(this.outputText, this.out.columns)); } super.render(); this.out