sv
Version:
A command line interface (CLI) for creating and maintaining Svelte applications
1,413 lines (1,411 loc) • 419 kB
JavaScript
import { createRequire } from "node:module";
import { AGENTS, COMMANDS, Walker, coerceVersion, color, constructCommand, createPrinter, dedent, defineEnv, detect, downloadJson, fileExists, isVersionUnsupportedBelow, js, loadFile, loadPackageJson, minVersion, parse, pnpm, resolveCommand, resolveCommandArray, sanitizeName, saveFile, svelte, svelteConfig, transforms } from "@sveltejs/sv-utils";
import fs, { closeSync, existsSync, openSync, readSync, statSync } from "node:fs";
import path, { basename, delimiter, dirname, isAbsolute, join, normalize, resolve } from "node:path";
import { promisify, stripVTControlCharacters, styleText } from "node:util";
import V, { cwd, stdin, stdout } from "node:process";
import * as b$1 from "node:readline";
import G from "node:readline";
import { ReadStream } from "node:tty";
import { fileURLToPath } from "node:url";
import childProcess, { exec, spawn } from "node:child_process";
import { pipeline } from "node:stream/promises";
import { PassThrough } from "node:stream";
import { EventEmitter } from "node:events";
import crypto from "node:crypto";
import { platform } from "node:os";
import { createGunzip } from "node:zlib";
//#region \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
//#endregion
//#region src/core/deprecated.ts
const warned = /* @__PURE__ */ new Set();
/** Emit a one-time deprecation warning. */
function svDeprecated(message) {
if (warned.has(message)) return;
warned.add(message);
console.warn();
console.warn(` ${color.dim("[sv] Deprecated:")} ${message}`);
console.warn(` Still works. ${color.warning("Warn add-on's author about it.")}`);
console.warn();
}
//#endregion
//#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
const getCodePointsLength = (() => {
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
return (input) => {
let surrogatePairsNr = 0;
SURROGATE_PAIR_RE.lastIndex = 0;
while (SURROGATE_PAIR_RE.test(input)) surrogatePairsNr += 1;
return input.length - surrogatePairsNr;
};
})();
const isFullWidth = (x) => {
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
};
const isWideNotCJKTNotEmoji = (x) => {
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
};
//#endregion
//#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy;
const TAB_RE = /\t{1,1000}/y;
const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
const MODIFIER_RE = /\p{M}+/gu;
const NO_TRUNCATION$1 = {
limit: Infinity,
ellipsis: ""
};
const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
const LIMIT = truncationOptions.limit ?? Infinity;
const ELLIPSIS = truncationOptions.ellipsis ?? "";
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
const ANSI_WIDTH = 0;
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
const FULL_WIDTH_WIDTH = 2;
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
const PARSE_BLOCKS = [
[LATIN_RE, REGULAR_WIDTH],
[ANSI_RE, ANSI_WIDTH],
[CONTROL_RE, CONTROL_WIDTH],
[TAB_RE, TAB_WIDTH],
[EMOJI_RE, EMOJI_WIDTH],
[CJKT_WIDE_RE, WIDE_WIDTH]
];
let indexPrev = 0;
let index = 0;
let length = input.length;
let lengthExtra = 0;
let truncationEnabled = false;
let truncationIndex = length;
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
let unmatchedStart = 0;
let unmatchedEnd = 0;
let width = 0;
let widthExtra = 0;
outer: while (true) {
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
lengthExtra = 0;
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
const codePoint = char.codePointAt(0) || 0;
if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
else if (isWideNotCJKTNotEmoji(codePoint)) widthExtra = WIDE_WIDTH;
else widthExtra = REGULAR_WIDTH;
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
if (width + widthExtra > LIMIT) {
truncationEnabled = true;
break outer;
}
lengthExtra += char.length;
width += widthExtra;
}
unmatchedStart = unmatchedEnd = 0;
}
if (index >= length) break outer;
for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
BLOCK_RE.lastIndex = index;
if (BLOCK_RE.test(input)) {
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
widthExtra = lengthExtra * BLOCK_WIDTH;
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
if (width + widthExtra > LIMIT) {
truncationEnabled = true;
break outer;
}
width += widthExtra;
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = BLOCK_RE.lastIndex;
continue outer;
}
}
index += 1;
}
return {
width: truncationEnabled ? truncationLimit : width,
index: truncationEnabled ? truncationIndex : length,
truncated: truncationEnabled,
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
};
};
//#endregion
//#region ../../node_modules/.pnpm/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
const NO_TRUNCATION = {
limit: Infinity,
ellipsis: "",
ellipsisWidth: 0
};
const fastStringWidth = (input, options = {}) => {
return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
};
//#endregion
//#region ../../node_modules/.pnpm/fast-wrap-ansi@0.2.2/node_modules/fast-wrap-ansi/lib/main.js
const ESC = "\x1B";
const CSI = "";
const END_CODE = 39;
const ANSI_ESCAPE_BELL = "\x07";
const ANSI_CSI = "[";
const ANSI_OSC = "]";
const ANSI_SGR_TERMINATOR = "m";
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
const getClosingCode = (openingCode) => {
if (openingCode >= 30 && openingCode <= 37) return 39;
if (openingCode >= 90 && openingCode <= 97) return 39;
if (openingCode >= 40 && openingCode <= 47) return 49;
if (openingCode >= 100 && openingCode <= 107) return 49;
if (openingCode === 1 || openingCode === 2) return 22;
if (openingCode === 3) return 23;
if (openingCode === 4) return 24;
if (openingCode === 7) return 27;
if (openingCode === 8) return 28;
if (openingCode === 9) return 29;
if (openingCode === 0) return 0;
};
const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
const wrapWord = (rows, word, columns) => {
const characters = word[Symbol.iterator]();
let isInsideEscape = false;
let isInsideLinkEscape = false;
let lastRow = rows.at(-1);
let visible = lastRow === void 0 ? 0 : fastStringWidth(lastRow);
let currentCharacter = characters.next();
let nextCharacter = characters.next();
let rawCharacterIndex = 0;
while (!currentCharacter.done) {
const character = currentCharacter.value;
const characterLength = fastStringWidth(character);
if (visible + characterLength <= columns) rows[rows.length - 1] += character;
else {
rows.push(character);
visible = 0;
}
if (character === ESC || character === CSI) {
isInsideEscape = true;
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
}
if (isInsideEscape) {
if (isInsideLinkEscape) {
if (character === ANSI_ESCAPE_BELL) {
isInsideEscape = false;
isInsideLinkEscape = false;
}
} else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
} else {
visible += characterLength;
if (visible === columns && !nextCharacter.done) {
rows.push("");
visible = 0;
}
}
currentCharacter = nextCharacter;
nextCharacter = characters.next();
rawCharacterIndex += character.length;
}
lastRow = rows.at(-1);
if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) rows[rows.length - 2] += rows.pop();
};
const stringVisibleTrimSpacesRight = (string) => {
const words = string.split(" ");
let last = words.length;
while (last) {
if (fastStringWidth(words[last - 1])) break;
last--;
}
if (last === words.length) return string;
return words.slice(0, last).join(" ") + words.slice(last).join("");
};
const exec$1 = (string, columns, options = {}) => {
if (options.trim !== false && string.trim() === "") return "";
let returnValue = "";
let escapeCode;
let escapeUrl;
const words = string.split(" ");
let rows = [""];
let rowLength = 0;
for (let index = 0; index < words.length; index++) {
const word = words[index];
if (options.trim !== false) {
const row = rows.at(-1) ?? "";
const trimmed = row.trimStart();
if (row.length !== trimmed.length) {
rows[rows.length - 1] = trimmed;
rowLength = fastStringWidth(trimmed);
}
}
if (index !== 0) {
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
rows.push("");
rowLength = 0;
}
if (rowLength || options.trim === false) {
rows[rows.length - 1] += " ";
rowLength++;
}
}
const wordLength = fastStringWidth(word);
if (options.hard && wordLength > columns) {
const remainingColumns = columns - rowLength;
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
wrapWord(rows, word, columns);
rowLength = fastStringWidth(rows.at(-1) ?? "");
continue;
}
if (rowLength + wordLength > columns && rowLength && wordLength) {
if (options.wordWrap === false && rowLength < columns) {
wrapWord(rows, word, columns);
rowLength = fastStringWidth(rows.at(-1) ?? "");
continue;
}
rows.push("");
rowLength = 0;
}
if (rowLength + wordLength > columns && options.wordWrap === false) {
wrapWord(rows, word, columns);
rowLength = fastStringWidth(rows.at(-1) ?? "");
continue;
}
rows[rows.length - 1] += word;
rowLength += wordLength;
}
if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
const preString = rows.join("\n");
let inSurrogate = false;
for (let i = 0; i < preString.length; i++) {
const character = preString[i];
returnValue += character;
if (!inSurrogate) {
inSurrogate = character >= "\ud800" && character <= "\udbff";
if (inSurrogate) continue;
} else inSurrogate = false;
if (character === ESC || character === CSI) {
GROUP_REGEX.lastIndex = i + 1;
const groups = GROUP_REGEX.exec(preString)?.groups;
if (groups?.code !== void 0) {
const code = Number.parseFloat(groups.code);
escapeCode = code === END_CODE ? void 0 : code;
} else if (groups?.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
}
if (preString[i + 1] === "\n") {
if (escapeUrl) returnValue += wrapAnsiHyperlink("");
const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
if (escapeCode && closingCode) returnValue += wrapAnsiCode(closingCode);
} else if (character === "\n") {
if (escapeCode && getClosingCode(escapeCode)) returnValue += wrapAnsiCode(escapeCode);
if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
}
}
return returnValue;
};
const CRLF_OR_LF = /\r?\n/;
function wrapAnsi(string, columns, options) {
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec$1(line, columns, options)).join("\n");
}
//#endregion
//#region ../../node_modules/.pnpm/@clack+core@1.4.0/node_modules/@clack/core/dist/index.mjs
var import_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
};
})))();
function f(r, t, s) {
if (!s.some((o) => !o.disabled)) return r;
const e = r + t, i = Math.max(s.length - 1, 0), n = e < 0 ? i : e > i ? 0 : e;
return s[n].disabled ? f(n, t < 0 ? -1 : 1, s) : n;
}
const h$1 = {
actions: /* @__PURE__ */ new Set([
"up",
"down",
"left",
"right",
"space",
"enter",
"cancel"
]),
aliases: /* @__PURE__ */ new Map([
["k", "up"],
["j", "down"],
["h", "left"],
["l", "right"],
["", "cancel"],
["escape", "cancel"]
]),
messages: {
cancel: "Canceled",
error: "Something went wrong"
},
withGuide: !0,
date: {
monthNames: [...[
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]],
messages: {
required: "Please enter a valid date",
invalidMonth: "There are only 12 months in a year",
invalidDay: (r, t) => `There are only ${r} days in ${t}`,
afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`,
beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}`
}
}
};
function C$1(r, t) {
if (typeof r == "string") return h$1.aliases.get(r) === t;
for (const s of r) if (s !== void 0 && C$1(s, t)) return !0;
return !1;
}
function Y$1(r, t) {
if (r === t) return;
const s = r.split(`
`), e = t.split(`
`), i = Math.max(s.length, e.length), n = [];
for (let o = 0; o < i; o++) s[o] !== e[o] && n.push(o);
return {
lines: n,
numLinesBefore: s.length,
numLinesAfter: e.length,
numLines: i
};
}
const q$1 = globalThis.process.platform.startsWith("win"), k$1 = Symbol("clack:cancel");
function R$2(r) {
return r === k$1;
}
function w$2(r, t) {
const s = r;
s.isTTY && s.setRawMode(t);
}
function W({ input: r = stdin, output: t = stdout, overwrite: s = !0, hideCursor: e = !0 } = {}) {
const i = b$1.createInterface({
input: r,
output: t,
prompt: "",
tabSize: 1
});
b$1.emitKeypressEvents(r, i), r instanceof ReadStream && r.isTTY && r.setRawMode(!0);
const n = (o, { name: u, sequence: a }) => {
if (C$1([
String(o),
u,
a
], "cancel")) {
e && t.write(import_src.cursor.show), process.exit(0);
return;
}
if (!s) return;
const c = u === "return" ? 0 : -1, y = u === "return" ? -1 : 0;
b$1.moveCursor(t, c, y, () => {
b$1.clearLine(t, 1, () => {
r.once("keypress", n);
});
});
};
return e && t.write(import_src.cursor.hide), r.once("keypress", n), () => {
r.off("keypress", n), e && t.write(import_src.cursor.show), r instanceof ReadStream && r.isTTY && !q$1 && r.setRawMode(!1), i.terminal = !1, i.close();
};
}
const A = (r) => "columns" in r && typeof r.columns == "number" ? r.columns : 80, L = (r) => "rows" in r && typeof r.rows == "number" ? r.rows : 20;
function B(r, t, s, e = s, i = s, n) {
return wrapAnsi(t, A(r ?? stdout) - s.length, {
hard: !0,
trim: !1
}).split(`
`).map((u, a, l) => {
const c = n ? n(u, a) : u;
return a === 0 ? `${e}${c}` : a === l.length - 1 ? `${i}${c}` : `${s}${c}`;
}).join(`
`);
}
function P$2(r, t) {
if ("~standard" in r) {
const s = r["~standard"].validate(t);
if (s instanceof Promise) throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
return s.issues?.at(0)?.message;
}
return r(t);
}
var m = class {
input;
output;
_abortSignal;
rl;
opts;
_render;
_track = !1;
_prevFrame = "";
_subscribers = /* @__PURE__ */ new Map();
_cursor = 0;
state = "initial";
error = "";
value;
userInput = "";
constructor(t, s = !0) {
const { input: e = stdin, output: i = stdout, render: n, signal: o, ...u } = t;
this.opts = u, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = o, this.input = e, this.output = i;
}
unsubscribe() {
this._subscribers.clear();
}
setSubscriber(t, s) {
const e = this._subscribers.get(t) ?? [];
e.push(s), this._subscribers.set(t, e);
}
on(t, s) {
this.setSubscriber(t, { cb: s });
}
once(t, s) {
this.setSubscriber(t, {
cb: s,
once: !0
});
}
emit(t, ...s) {
const e = this._subscribers.get(t) ?? [], i = [];
for (const n of e) n.cb(...s), n.once && i.push(() => e.splice(e.indexOf(n), 1));
for (const n of i) n();
}
prompt() {
return new Promise((t) => {
if (this._abortSignal) {
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(k$1);
this._abortSignal.addEventListener("abort", () => {
this.state = "cancel", this.close();
}, { once: !0 });
}
this.rl = G.createInterface({
input: this.input,
tabSize: 2,
prompt: "",
escapeCodeTimeout: 50,
terminal: !0
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, !0), this.input.on("keypress", this.onKeypress), w$2(this.input, !0), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), w$2(this.input, !1), t(this.value);
}), this.once("cancel", () => {
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), w$2(this.input, !1), t(k$1);
});
});
}
_isActionKey(t, s) {
return t === " ";
}
_shouldSubmit(t, s) {
return !0;
}
_setValue(t) {
this.value = t, this.emit("value", this.value);
}
_setUserInput(t, s) {
this.userInput = t ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
}
_clearUserInput() {
this.rl?.write(null, {
ctrl: !0,
name: "u"
}), this._setUserInput("");
}
onKeypress(t, s) {
if (this._track && s.name !== "return" && (s.name && this._isActionKey(t, s) && this.rl?.write(null, {
ctrl: !0,
name: "h"
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && h$1.aliases.has(s.name) && this.emit("cursor", h$1.aliases.get(s.name)), h$1.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, s), s?.name === "return" && this._shouldSubmit(t, s)) {
if (this.opts.validate) {
const e = P$2(this.opts.validate, this.value);
e && (this.error = e instanceof Error ? e.message : e, this.state = "error", this.rl?.write(this.userInput));
}
this.state !== "error" && (this.state = "submit");
}
C$1([
t,
s?.name,
s?.sequence
], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
}
close() {
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
`), w$2(this.input, !1), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
}
restoreCursor() {
const t = wrapAnsi(this._prevFrame, process.stdout.columns, {
hard: !0,
trim: !1
}).split(`
`).length - 1;
this.output.write(import_src.cursor.move(-999, t * -1));
}
render() {
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
hard: !0,
trim: !1
});
if (t !== this._prevFrame) {
if (this.state === "initial") this.output.write(import_src.cursor.hide);
else {
const s = Y$1(this._prevFrame, t), e = L(this.output);
if (this.restoreCursor(), s) {
const i = Math.max(0, s.numLinesAfter - e), n = Math.max(0, s.numLinesBefore - e);
let o = s.lines.find((u) => u >= i);
if (o === void 0) {
this._prevFrame = t;
return;
}
if (s.lines.length === 1) {
this.output.write(import_src.cursor.move(0, o - n)), this.output.write(import_src.erase.lines(1));
const u = t.split(`
`);
this.output.write(u[o]), this._prevFrame = t, this.output.write(import_src.cursor.move(0, u.length - o - 1));
return;
} else if (s.lines.length > 1) {
if (i < n) o = i;
else {
const a = o - n;
a > 0 && this.output.write(import_src.cursor.move(0, a));
}
this.output.write(import_src.erase.down());
const u = t.split(`
`).slice(o);
this.output.write(u.join(`
`)), this._prevFrame = t;
return;
}
}
this.output.write(import_src.erase.down());
}
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
}
}
};
var Z = class extends m {
get cursor() {
return this.value ? 0 : 1;
}
get _value() {
return this.cursor === 0;
}
constructor(t) {
super(t, !1), this.value = !!t.initialValue, this.on("userInput", () => {
this.value = this._value;
}), this.on("confirm", (s) => {
this.output.write(import_src.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
}), this.on("cursor", () => {
this.value = !this.value;
});
}
};
let ut$1 = class extends m {
options;
cursor = 0;
get _value() {
return this.options[this.cursor].value;
}
get _enabledOptions() {
return this.options.filter((t) => t.disabled !== !0);
}
toggleAll() {
const t = this._enabledOptions, s = this.value !== void 0 && this.value.length === t.length;
this.value = s ? [] : t.map((e) => e.value);
}
toggleInvert() {
const t = this.value;
if (!t) return;
const s = this._enabledOptions.filter((e) => !t.includes(e.value));
this.value = s.map((e) => e.value);
}
toggleValue() {
this.value === void 0 && (this.value = []);
const t = this.value.includes(this._value);
this.value = t ? this.value.filter((s) => s !== this._value) : [...this.value, this._value];
}
constructor(t) {
super(t, !1), this.options = t.options, this.value = [...t.initialValues ?? []];
const s = Math.max(this.options.findIndex(({ value: e }) => e === t.cursorAt), 0);
this.cursor = this.options[s].disabled ? f(s, 1, this.options) : s, this.on("key", (e, i) => {
i.name === "a" && this.toggleAll(), i.name === "i" && this.toggleInvert();
}), this.on("cursor", (e) => {
switch (e) {
case "left":
case "up":
this.cursor = f(this.cursor, -1, this.options);
break;
case "down":
case "right":
this.cursor = f(this.cursor, 1, this.options);
break;
case "space":
this.toggleValue();
break;
}
});
}
};
var ht$1 = class extends m {
options;
cursor = 0;
get _selectedValue() {
return this.options[this.cursor];
}
changeValue() {
this.value = this._selectedValue.value;
}
constructor(t) {
super(t, !1), this.options = t.options;
const s = this.options.findIndex(({ value: i }) => i === t.initialValue), e = s === -1 ? 0 : s;
this.cursor = this.options[e].disabled ? f(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (i) => {
switch (i) {
case "left":
case "up":
this.cursor = f(this.cursor, -1, this.options);
break;
case "down":
case "right":
this.cursor = f(this.cursor, 1, this.options);
break;
}
this.changeValue();
});
}
};
var ct$1 = class extends m {
get userInputWithCursor() {
if (this.state === "submit") return this.userInput;
const t = this.userInput;
if (this.cursor >= t.length) return `${this.userInput}\u2588`;
const s = t.slice(0, this.cursor), [e, ...i] = t.slice(this.cursor);
return `${s}${styleText("inverse", e)}${i.join("")}`;
}
get cursor() {
return this._cursor;
}
constructor(t) {
super({
...t,
initialUserInput: t.initialUserInput ?? t.initialValue
}), this.on("userInput", (s) => {
this._setValue(s);
}), this.on("finalize", () => {
this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
});
}
};
//#endregion
//#region ../../node_modules/.pnpm/@clack+prompts@1.5.0/node_modules/@clack/prompts/dist/index.mjs
function se() {
return V.platform !== "win32" ? V.env.TERM !== "linux" : !!V.env.CI || !!V.env.WT_SESSION || !!V.env.TERMINUS_SUBLIME || V.env.ConEmuTask === "{cmd::Cmder}" || V.env.TERM_PROGRAM === "Terminus-Sublime" || V.env.TERM_PROGRAM === "vscode" || V.env.TERM === "xterm-256color" || V.env.TERM === "alacritty" || V.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
}
const tt = se(), at = () => process.env.CI === "true", Tt = (t) => t.isTTY === !0, w$1 = (t, i) => tt ? t : i, _t = w$1("◆", "*"), ut = w$1("■", "x"), lt = w$1("▲", "x"), H = w$1("◇", "o"), ct = w$1("┌", "T"), $ = w$1("│", "|"), x$1 = w$1("└", "—"), z$1 = w$1("●", ">"), U = w$1("○", " "), et = w$1("◻", "[•]"), K = w$1("◼", "[+]"), Y = w$1("◻", "[ ]"), st = w$1("─", "-"), $t = w$1("╮", "+"), Mt = w$1("├", "+"), dt = w$1("╯", "+"), ht = w$1("╰", "+"), pt = w$1("●", "•"), mt = w$1("◆", "*"), gt = w$1("▲", "!"), yt = w$1("■", "x"), P$1 = (t) => {
switch (t) {
case "initial":
case "active": return styleText("cyan", _t);
case "cancel": return styleText("red", ut);
case "error": return styleText("yellow", lt);
case "submit": return styleText("green", H);
}
}, ft = (t) => {
switch (t) {
case "initial":
case "active": return styleText("cyan", $);
case "cancel": return styleText("red", $);
case "error": return styleText("yellow", $);
case "submit": return styleText("green", $);
}
}, Pt = (t, i, s, r, u, n = !1) => {
let a = i, c = 0;
if (n) for (let o = r - 1; o >= s && (a -= t[o].length, c++, !(a <= u)); o--);
else for (let o = s; o < r && (a -= t[o].length, c++, !(a <= u)); o++);
return {
lineCount: a,
removals: c
};
}, F$1 = ({ cursor: t, options: i, style: s, output: r = process.stdout, maxItems: u = Number.POSITIVE_INFINITY, columnPadding: n = 0, rowPadding: a = 4 }) => {
const c = A(r) - n, o = L(r), l = styleText("dim", "..."), d = Math.max(o - a, 0), g = Math.max(Math.min(u, d), 5);
let p = 0;
t >= g - 3 && (p = Math.max(Math.min(t - g + 3, i.length - g), 0));
let f = g < i.length && p > 0, h = g < i.length && p + g < i.length;
const I = Math.min(p + g, i.length), m = [];
let y = 0;
f && y++, h && y++;
const v = p + (f ? 1 : 0), C = I - (h ? 1 : 0);
for (let b = v; b < C; b++) {
const G = wrapAnsi(s(i[b], b === t), c, {
hard: !0,
trim: !1
}).split(`
`);
m.push(G), y += G.length;
}
if (y > d) {
let b = 0, G = 0, M = y;
const N = t - v;
let O = d;
const j = () => Pt(m, M, 0, N, O), k = () => Pt(m, M, N + 1, m.length, O, !0);
f ? ({lineCount: M, removals: b} = j(), M > O && (h || (O -= 1), {lineCount: M, removals: G} = k())) : (h || (O -= 1), {lineCount: M, removals: G} = k(), M > O && (O -= 1, {lineCount: M, removals: b} = j())), b > 0 && (f = !0, m.splice(0, b)), G > 0 && (h = !0, m.splice(m.length - G, G));
}
const S = [];
f && S.push(l);
for (const b of m) for (const G of b) S.push(G);
return h && S.push(l), S;
};
const le = (t) => {
const i = t.active ?? "Yes", s = t.inactive ?? "No";
return new Z({
active: i,
inactive: s,
signal: t.signal,
input: t.input,
output: t.output,
initialValue: t.initialValue ?? !0,
render() {
const r = t.withGuide ?? h$1.withGuide, u = `${P$1(this.state)} `, n = r ? `${styleText("gray", $)} ` : "", a = B(t.output, t.message, n, u), c = `${r ? `${styleText("gray", $)}
` : ""}${a}
`, o = this.value ? i : s;
switch (this.state) {
case "submit": return `${c}${r ? `${styleText("gray", $)} ` : ""}${styleText("dim", o)}`;
case "cancel": return `${c}${r ? `${styleText("gray", $)} ` : ""}${styleText(["strikethrough", "dim"], o)}${r ? `
${styleText("gray", $)}` : ""}`;
default: {
const l = r ? `${styleText("cyan", $)} ` : "", d = r ? styleText("cyan", x$1) : "";
return `${c}${l}${this.value ? `${styleText("green", z$1)} ${i}` : `${styleText("dim", U)} ${styleText("dim", i)}`}${t.vertical ? r ? `
${styleText("cyan", $)} ` : `
` : ` ${styleText("dim", "/")} `}${this.value ? `${styleText("dim", U)} ${styleText("dim", s)}` : `${styleText("green", z$1)} ${s}`}
${d}
`;
}
}
}
}).prompt();
}, pe = async (t, i) => {
const s = {}, r = Object.keys(t);
for (const u of r) {
const n = t[u], a = await n({ results: s })?.catch((c) => {
throw c;
});
if (typeof i?.onCancel == "function" && R$2(a)) {
s[u] = "canceled", i.onCancel({ results: s });
continue;
}
s[u] = a;
}
return s;
}, R$1 = {
message: (t = [], { symbol: i = styleText("gray", $), secondarySymbol: s = styleText("gray", $), output: r = process.stdout, spacing: u = 1, withGuide: n } = {}) => {
const a = [], c = n ?? h$1.withGuide, o = c ? s : "", l = c ? `${i} ` : "", d = c ? `${s} ` : "";
for (let p = 0; p < u; p++) a.push(o);
const g = Array.isArray(t) ? t : t.split(`
`);
if (g.length > 0) {
const [p, ...f] = g;
p.length > 0 ? a.push(`${l}${p}`) : a.push(c ? i : "");
for (const h of f) h.length > 0 ? a.push(`${d}${h}`) : a.push(c ? s : "");
}
r.write(`${a.join(`
`)}
`);
},
info: (t, i) => {
R$1.message(t, {
...i,
symbol: styleText("blue", pt)
});
},
success: (t, i) => {
R$1.message(t, {
...i,
symbol: styleText("green", mt)
});
},
step: (t, i) => {
R$1.message(t, {
...i,
symbol: styleText("green", H)
});
},
warn: (t, i) => {
R$1.message(t, {
...i,
symbol: styleText("yellow", gt)
});
},
warning: (t, i) => {
R$1.warn(t, i);
},
error: (t, i) => {
R$1.message(t, {
...i,
symbol: styleText("red", yt)
});
}
}, ge = (t = "", i) => {
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h$1.withGuide ? `${styleText("gray", x$1)} ` : "";
s.write(`${r}${styleText("red", t)}
`);
}, ye = (t = "", i) => {
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h$1.withGuide ? `${styleText("gray", ct)} ` : "";
s.write(`${r}${t}
`);
}, fe = (t = "", i) => {
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h$1.withGuide ? `${styleText("gray", $)}
${styleText("gray", x$1)} ` : "";
s.write(`${r}${t}
`);
}, Q = (t, i) => t.split(`
`).map((s) => i(s)).join(`
`), we = (t) => {
const i = (r, u) => {
const n = r.label ?? String(r.value);
return u === "disabled" ? `${styleText("gray", Y)} ${Q(n, (a) => styleText(["strikethrough", "gray"], a))}${r.hint ? ` ${styleText("dim", `(${r.hint ?? "disabled"})`)}` : ""}` : u === "active" ? `${styleText("cyan", et)} ${n}${r.hint ? ` ${styleText("dim", `(${r.hint})`)}` : ""}` : u === "selected" ? `${styleText("green", K)} ${Q(n, (a) => styleText("dim", a))}${r.hint ? ` ${styleText("dim", `(${r.hint})`)}` : ""}` : u === "cancelled" ? `${Q(n, (a) => styleText(["strikethrough", "dim"], a))}` : u === "active-selected" ? `${styleText("green", K)} ${n}${r.hint ? ` ${styleText("dim", `(${r.hint})`)}` : ""}` : u === "submitted" ? `${Q(n, (a) => styleText("dim", a))}` : `${styleText("dim", Y)} ${Q(n, (a) => styleText("dim", a))}`;
}, s = t.required ?? !0;
return new ut$1({
options: t.options,
signal: t.signal,
input: t.input,
output: t.output,
initialValues: t.initialValues,
required: s,
cursorAt: t.cursorAt,
validate(r) {
if (s && (r === void 0 || r.length === 0)) return `Please select at least one option.
${styleText("reset", styleText("dim", `Press ${styleText([
"gray",
"bgWhite",
"inverse"
], " space ")} to select, ${styleText("gray", styleText("bgWhite", styleText("inverse", " enter ")))} to submit`))}`;
},
render() {
const r = t.withGuide ?? h$1.withGuide, u = B(t.output, t.message, r ? `${ft(this.state)} ` : "", `${P$1(this.state)} `), n = `${r ? `${styleText("gray", $)}
` : ""}${u}
`, a = this.value ?? [], c = (o, l) => {
if (o.disabled) return i(o, "disabled");
const d = a.includes(o.value);
return l && d ? i(o, "active-selected") : d ? i(o, "selected") : i(o, l ? "active" : "inactive");
};
switch (this.state) {
case "submit": {
const o = this.options.filter(({ value: d }) => a.includes(d)).map((d) => i(d, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none");
return `${n}${B(t.output, o, r ? `${styleText("gray", $)} ` : "")}`;
}
case "cancel": {
const o = this.options.filter(({ value: d }) => a.includes(d)).map((d) => i(d, "cancelled")).join(styleText("dim", ", "));
if (o.trim() === "") return `${n}${styleText("gray", $)}`;
return `${n}${B(t.output, o, r ? `${styleText("gray", $)} ` : "")}${r ? `
${styleText("gray", $)}` : ""}`;
}
case "error": {
const o = r ? `${styleText("yellow", $)} ` : "", l = this.error.split(`
`).map((p, f) => f === 0 ? `${r ? `${styleText("yellow", x$1)} ` : ""}${styleText("yellow", p)}` : ` ${p}`).join(`
`), d = n.split(`
`).length, g = l.split(`
`).length + 1;
return `${n}${o}${F$1({
output: t.output,
options: this.options,
cursor: this.cursor,
maxItems: t.maxItems,
columnPadding: o.length,
rowPadding: d + g,
style: c
}).join(`
${o}`)}
${l}
`;
}
default: {
const o = r ? `${styleText("cyan", $)} ` : "", l = n.split(`
`).length, d = r ? 2 : 1;
return `${n}${o}${F$1({
output: t.output,
options: this.options,
cursor: this.cursor,
maxItems: t.maxItems,
columnPadding: o.length,
rowPadding: l + d,
style: c
}).join(`
${o}`)}
${r ? styleText("cyan", x$1) : ""}
`;
}
}
}
}).prompt();
}, be = (t) => styleText("dim", t), Se = (t, i, s) => {
const r = {
hard: !0,
trim: !1
}, u = wrapAnsi(t, i, r).split(`
`), n = u.reduce((o, l) => Math.max(fastStringWidth(l), o), 0);
return wrapAnsi(t, i - (u.map(s).reduce((o, l) => Math.max(fastStringWidth(l), o), 0) - n), r);
}, Ce = (t = "", i = "", s) => {
const r = s?.output ?? V.stdout, u = s?.withGuide ?? h$1.withGuide, n = s?.format ?? be, a = [
"",
...Se(t, A(r) - 6, n).split(`
`).map(n),
""
], c = fastStringWidth(i), o = Math.max(a.reduce((p, f) => {
const h = fastStringWidth(f);
return h > p ? h : p;
}, 0), c) + 2, l = a.map((p) => `${styleText("gray", $)} ${p}${" ".repeat(o - fastStringWidth(p))}${styleText("gray", $)}`).join(`
`), d = u ? `${styleText("gray", $)}
` : "", g = u ? Mt : ht;
r.write(`${d}${styleText("green", H)} ${styleText("reset", i)} ${styleText("gray", st.repeat(Math.max(o - c - 1, 1)) + $t)}
${l}
${styleText("gray", g + st.repeat(o + 2) + dt)}
`);
}, _e = (t) => styleText("magenta", t), vt = ({ indicator: t = "dots", onCancel: i, output: s = process.stdout, cancelMessage: r, errorMessage: u, frames: n = tt ? [
"◒",
"◐",
"◓",
"◑"
] : [
"•",
"o",
"O",
"0"
], delay: a = tt ? 80 : 120, signal: c, ...o } = {}) => {
const l = at();
let d, g, p = !1, f = !1, h = "", I, m = performance.now();
const y = A(s), v = o?.styleFrame ?? _e, C = (_) => {
const A = _ > 1 ? u ?? h$1.messages.error : r ?? h$1.messages.cancel;
f = _ === 1, p && (W$1(A, _), f && typeof i == "function" && i());
}, S = () => C(2), b = () => C(1), G = () => {
process.on("uncaughtExceptionMonitor", S), process.on("unhandledRejection", S), process.on("SIGINT", b), process.on("SIGTERM", b), process.on("exit", C), c && c.addEventListener("abort", b);
}, M = () => {
process.removeListener("uncaughtExceptionMonitor", S), process.removeListener("unhandledRejection", S), process.removeListener("SIGINT", b), process.removeListener("SIGTERM", b), process.removeListener("exit", C), c && c.removeEventListener("abort", b);
}, N = () => {
if (I === void 0) return;
l && s.write(`
`);
const _ = wrapAnsi(I, y, {
hard: !0,
trim: !1
}).split(`
`);
_.length > 1 && s.write(import_src.cursor.up(_.length - 1)), s.write(import_src.cursor.to(0)), s.write(import_src.erase.down());
}, O = (_) => _.replace(/\.+$/, ""), j = (_) => {
const A = (performance.now() - _) / 1e3, L = Math.floor(A / 60), D = Math.floor(A % 60);
return L > 0 ? `[${L}m ${D}s]` : `[${D}s]`;
}, k = o.withGuide ?? h$1.withGuide, rt = (_ = "") => {
p = !0, d = W({ output: s }), h = O(_), m = performance.now(), k && s.write(`${styleText("gray", $)}
`);
let A = 0, L = 0;
G(), g = setInterval(() => {
if (l && h === I) return;
N(), I = h;
const D = v(n[A]);
let Z;
if (l) Z = `${D} ${h}...`;
else if (t === "timer") Z = `${D} ${h} ${j(m)}`;
else {
const Lt = ".".repeat(Math.floor(L)).slice(0, 3);
Z = `${D} ${h}${Lt}`;
}
const kt = wrapAnsi(Z, y, {
hard: !0,
trim: !1
});
s.write(kt), A = A + 1 < n.length ? A + 1 : 0, L = L < 4 ? L + .125 : 0;
}, a);
}, W$1 = (_ = "", A = 0, L = !1) => {
if (!p) return;
p = !1, clearInterval(g), N();
const D = A === 0 ? styleText("green", H) : A === 1 ? styleText("red", ut) : styleText("red", lt);
h = _ ?? h, L || (t === "timer" ? s.write(`${D} ${h} ${j(m)}
`) : s.write(`${D} ${h}
`)), M(), d();
};
return {
start: rt,
stop: (_ = "") => W$1(_, 0),
message: (_ = "") => {
h = O(_ ?? h);
},
cancel: (_ = "") => W$1(_, 1),
error: (_ = "") => W$1(_, 2),
clear: () => W$1("", 0, !0),
get isCancelled() {
return f;
}
};
}, it = (t, i) => t.includes(`
`) ? t.split(`
`).map((s) => i(s)).join(`
`) : i(t), Ee = (t) => {
const i = (s, r) => {
const u = s.label ?? String(s.value);
switch (r) {
case "disabled": return `${styleText("gray", U)} ${it(u, (n) => styleText("gray", n))}${s.hint ? ` ${styleText("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
case "selected": return `${it(u, (n) => styleText("dim", n))}`;
case "active": return `${styleText("green", z$1)} ${u}${s.hint ? ` ${styleText("dim", `(${s.hint})`)}` : ""}`;
case "cancelled": return `${it(u, (n) => styleText(["strikethrough", "dim"], n))}`;
default: return `${styleText("dim", U)} ${it(u, (n) => styleText("dim", n))}`;
}
};
return new ht$1({
options: t.options,
signal: t.signal,
input: t.input,
output: t.output,
initialValue: t.initialValue,
render() {
const s = t.withGuide ?? h$1.withGuide, r = `${P$1(this.state)} `, u = `${ft(this.state)} `, n = B(t.output, t.message, u, r), a = `${s ? `${styleText("gray", $)}
` : ""}${n}
`;
switch (this.state) {
case "submit": {
const c = s ? `${styleText("gray", $)} ` : "";
return `${a}${B(t.output, i(this.options[this.cursor], "selected"), c)}`;
}
case "cancel": {
const c = s ? `${styleText("gray", $)} ` : "";
return `${a}${B(t.output, i(this.options[this.cursor], "cancelled"), c)}${s ? `
${styleText("gray", $)}` : ""}`;
}
default: {
const c = s ? `${styleText("cyan", $)} ` : "", o = s ? styleText("cyan", x$1) : "", l = a.split(`
`).length, d = s ? 2 : 1;
return `${a}${c}${F$1({
output: t.output,
cursor: this.cursor,
options: this.options,
maxItems: t.maxItems,
columnPadding: c.length,
rowPadding: l + d,
style: (g, p) => i(g, g.disabled ? "disabled" : p ? "active" : "inactive")
}).join(`
${c}`)}
${o}
`;
}
}
}
}).prompt();
}, Bt = `${styleText("gray", $)} `, q = {
message: async (t, { symbol: i = styleText("gray", $) } = {}) => {
process.stdout.write(`${styleText("gray", $)}
${i} `);
let s = 3;
for await (let r of t) {
r = r.replace(/\n/g, `
${Bt}`), r.includes(`
`) && (s = 3 + stripVTControlCharacters(r.slice(r.lastIndexOf(`
`))).length);
const u = stripVTControlCharacters(r).length;
s + u < process.stdout.columns ? (s += u, process.stdout.write(r)) : (process.stdout.write(`
${Bt}${r.trimStart()}`), s = 3 + stripVTControlCharacters(r.trimStart()).length);
}
process.stdout.write(`
`);
},
info: (t) => q.message(t, { symbol: styleText("blue", pt) }),
success: (t) => q.message(t, { symbol: styleText("green", mt) }),
step: (t) => q.message(t, { symbol: styleText("green", H) }),
warn: (t) => q.message(t, { symbol: styleText("yellow", gt) }),
warning: (t) => q.warn(t),
error: (t) => q.message(t, { symbol: styleText("red", yt) })
}, Oe = (t) => t.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g, ""), Pe = (t) => {
const i = t.output ?? process.stdout, s = A(i), r = styleText("gray", $), u = t.spacing ?? 1, n = 3, a = t.retainLog === !0, c = !at() && Tt(i);
i.write(`${r}
`), i.write(`${styleText("green", H)} ${t.title}
`);
for (let m = 0; m < u; m++) i.write(`${r}
`);
const o = [{
value: "",
full: ""
}];
let l = !1;
const d = (m) => {
if (o.length === 0) return;
let y = 0;
m && (y += u + 2);
for (const v of o) {
const { value: C, result: S } = v;
let b = S?.message ?? C;
if (b.length === 0) continue;
S === void 0 && v.header !== void 0 && v.header !== "" && (b += `
${v.header}`);
const G = b.split(`
`).reduce((M, N) => N === "" ? M + 1 : M + Math.ceil((N.length + n) / s), 0);
y += G;
}
y > 0 && (y += 1, i.write(import_src.erase.lines(y)));
}, g = (m, y, v) => {
const C = v ? `${m.full}
${m.value}` : m.value;
m.header !== void 0 && m.header !== "" && R$1.message(m.header.split(`
`).map((S) => styleText("bold", S)), {
output: i,
secondarySymbol: r,
symbol: r,
spacing: 0
}), R$1.message(C.split(`
`).map((S) => styleText("dim", S)), {
output: i,
secondarySymbol: r,
symbol: r,
spacing: y ?? u
});
}, p = () => {
for (const m of o) {
const { header: y, value: v, full: C } = m;
(y === void 0 || y.length === 0) && v.length === 0 || g(m, void 0, a === !0 && C.length > 0);
}
}, f = (m, y, v) => {
if (d(!1), (v?.raw !== !0 || !l) && m.value !== "" && (m.value += `
`), m.value += Oe(y), l = v?.raw === !0, t.limit !== void 0) {
const C = m.value.split(`
`), S = C.length - t.limit;
if (S > 0) {
const b = C.splice(0, S);
a && (m.full += (m.full === "" ? "" : `
`) + b.join(`
`));
}
m.value = C.join(`
`);
}
c && h();
}, h = () => {
for (const m of o) m.result ? m.result.status === "error" ? R$1.error(m.result.message, {
output: i,
secondarySymbol: r,
spacing: 0
}) : R$1.success(m.result.message, {
output: i,
secondarySymbol: r,
spacing: 0
}) : m.value !== "" && g(m, 0);
}, I = (m, y) => {
d(!1), m.result = y, c && h();
};
return {
message(m, y) {
f(o[0], m, y);
},
group(m) {
const y = {
header: m,
value: "",
full: ""
};
return o.push(y), {
message(v, C) {
f(y, v, C);
},
error(v) {
I(y, {
status: "error",
message: v
});
},
success(v) {
I(y, {
status: "success",
message: v
});
}
};
},
error(m, y) {
d(!0), R$1.error(m, {
output: i,
secondarySymbol: r,
spacing: 1
}), y?.showLog !== !1 && p(), o.splice(1, o.length - 1), o[0].value = "", o[0].full = "";
},
success(m, y) {
d(!0), R$1.success(m, {
output: i,
secondarySymbol: r,
spacing: 1
}), y?.showLog === !0 && p(), o.splice(1, o.length - 1), o[0].value = "", o[0].full = "";
}
};
}, Re = (t) => new ct$1({
validate: t.validate,
placeholder: t.placeholder,
defaultValue: t.defaultValue,
initialValue: t.initialValue,
output: t.output,
signal: t.signal,
input: t.input,
render() {
const i = t?.withGuide ?? h$1.withGuide, s = `${`${i ? `${styleText("gray", $)}
` : ""}${P$1(this.state)} `}${t.message}
`, r = t.placeholder ? styleText("inverse", t.placeholder[0]) + styleText("dim", t.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), u = this.userInput ? this.userInputWithCursor : r, n = this.value ?? "";
switch (this.state) {
case "error": {
const a = this.error ? ` ${styleText("yellow", this.error)}` : "", c = i ? `${styleText("yellow", $)} ` : "", o = i ? styleText("yellow", x$1) : "";
return `${s.trim()}
${c}${u}
${o}${a}
`;
}
case "submit": {
const a = n ? ` ${styleText("dim", n)}` : "";
return `${s}${i ? styleText("gray", $) : ""}${a}`;
}
case "cancel": {
const a = n ? ` ${styleText(["strikethrough", "dim"], n)}` : "", c = i ? styleText("gray", $) : "";
return `${s}${c}${a}${n.trim() ? `
${c}` : ""}`;
}
default: return `${s}${i ? `${styleText("cyan", $)} ` : ""}${u}
${i ? styleText("cyan", x$1) : ""}
`;
}
}
}).prompt();
//#endregion
//#region package.json
var name = "sv";
var version = "0.16.2";
//#endregion
//#region src/core/errors.ts
var UnsupportedError = class extends Error {
constructor(reasons) {
super();
this.name = "Unsupported Environment";
this.reasons = [];
this.reasons = reasons;
}
};
//#endregion
//#region src/core/common.ts
const NO_PREFIX = "--no-";
let options$8 = [];
function getLongFlag(flags) {
return flags.split(",").map((f) => f.trim()).find((f) => f.startsWith("--"));
}
const helpConfig = {
argumentDescription: formatDescription,
optionDescription: formatDescription,
visibleOptions(cmd) {
options$8 = cmd.options;
const visible = cmd.options.filter((o) => !o.hidden);
const show = [];
for (const option of visible) {
const flag = getLongFlag(option.flags);
if (flag?.startsWith(NO_PREFIX)) {
const stripped = flag.slice(5);
if (visible.some((o) => getLongFlag(o.flags)?.startsWith(`--${stripped}`))) continue;
}
show.push(option);
}
return show;
},
optionTerm(option) {
const longFlag = getLongFlag(option.flags);
const flag = longFlag?.split(" ").at(0);
if (!flag || !longFlag) return option.flags;
const noVariant = `--no-${flag.slice(2)}`;
if (options$8.some((o) => getLongFlag(o.flags) === noVariant)) return `--[no-]${longFlag.slice(2)}`;
return option.flags;
},
styleCommandText: (str) => color.success(str),
styleDescriptionText: (str) => color.optional(str)
};
function formatDescription(arg) {
let output = arg.description;
if (arg.defaultValue !== void 0 && String(arg.defaultValue)) output += color.dim(` (default: ${JSON.stringify(arg.defaultValue)})`);
if (arg.argChoices !== void 0 && String(arg.argChoices)) output += color.dim(` (choices: ${arg.argChoices.join(", ")})`);
return output;
}
/**
* Returns standard help sections and a formatItem helper.
* Used by `add` and `create` custom `formatHelp` to avoid duplicating boilerplate.
*/
function getHelpSections(cmd, helper) {
const termWidth = helper.padWidth(cmd, helper);
const helpWidth = helper.helpWidth ?? 80;
function formatItem(term, description) {
return helper.formatItem(term, termWidth, description, helper);
}
const usage