nry 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/bin.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Npm RegistrY
|
|
2
2
|
|
|
3
|
-
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/nry) [?logo=github>)](https://github.com/
|
|
3
|
+
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/nry) [?logo=github>)](https://github.com/gleanings/nry/issues)
|
|
4
4
|
|
|
5
5
|
一个用于 npm、yarn、pnpm registry 切换及管理的工具。
|
|
6
6
|
|
package/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{statSync as e,readFileSync as t,readdirSync as n,writeFileSync as r,unlinkSync as o,mkdirSync as i}from"node:fs";import{arch as s,homedir as a}from"node:os";import{dirname as c,normalize as l,join as u,resolve as f}from"node:path";import"node:fs/promises";import{fileURLToPath as h}from"node:url";import{spawn as d}from"node:child_process";import{emitKeypressEvents as g}from"node:readline";import{resolve as p}from"node:path/posix";function b(e){return e.prototype.apply=Function.apply,e.prototype.bind=Function.bind,e.prototype.call=Function.call,e.prototype.length=Function.length,e.prototype.name=Function.name,e.prototype.toString=Function.toString,e}function m(e,t){return Object.keys(t).forEach(n=>e[n]=t[n]),e}function w(e){const t=typeof e;if("object"!==t&&"function"!==t)return t;const n=Reflect.apply(Object.prototype.toString,e,[]).replace(/^.*\s(.*)]$/,"$1").toLowerCase();return"error"!==n?n:e instanceof SyntaxError?"syntaxerror":e instanceof TypeError?"typeerror":e instanceof URIError?"urierror":e instanceof ReferenceError?"referenceerror":e instanceof AggregateError?"aggregateerror":e instanceof RangeError?"rangeerror":e instanceof EvalError?"evalerror":"error"}function y(e){return"string"===w(e)}function v(e){return"regexp"===w(e)}function x(e){return y(e)&&""===e.valueOf()}function $(e){return y(e)&&""===e.valueOf().trim()}function k(e){return"number"===w(e)}function E(e){return 0===e}function C(e){return"boolean"===w(e)}function I(e){return!0===e}function O(e){return!1===e}function T(e){return null===e}function S(e){return void 0===e}function j(e){return"function"===w(e)}function R(e){return Array.isArray(e)}function N(e){if(R(e))return 0===e.length;throw new TypeError("参数必须为数组")}function M(e){return"object"===w(e)}function D(e){return M(e)&&0===Reflect.ownKeys(e).length}function L(e){return"symbol"===w(e)}function B(e,t){return void 0===t||("function"==typeof t?t(e):t)}function P(e=1,t=0){if(!isFinite(e)||!isFinite(t)||isNaN(e)||isNaN(t)||!k(e)||!k(t))throw new TypeError("getRandomInt: max or min is NaN or is not a number");let n=Math.ceil(Number(t)),r=Math.floor(Number(e));return r===n?r:(n>r&&([r,n]=[n,r]),Math.round(Math.random()*(r-n)+n))}function F(e){if(!M(e)&&!k(e)||k(e)&&isNaN(e)||k(e)&&!isFinite(e)||k(e)&&!Number.isInteger(e)||k(e)&&Number.isInteger(e)&&e<1||k(e)&&e<1||M(e)&&(!k(e.length)||e.length<1||!Number.isInteger(e.length)))throw new TypeError("参数类型错误 ❌ (getRandomString)");const t={length:32,chars:"abcdefghijklmnopqrstuvwxyz",chars2:"0123456789",chars3:"!@#$%^&*()_+~`|}{[]:;?><,./-=",type:"string",includeUppercaseLetters:!1,includeNumbers:!1,includeSpecial:!1};if("uuid"===t.type)return crypto.randomUUID();k(e)&&Number.isInteger(e)&&e>0&&m(t,{length:e}),M(e)&&(m(t,e),t.length=t.length<1?32:t.length);const n=t.chars.split("");t.includeUppercaseLetters&&s(n,t.chars.toUpperCase()),t.includeNumbers&&s(n,t.chars2),t.includeSpecial&&s(n,t.chars3);let r="";const o=n.join(""),i=o.length;if(globalThis&&globalThis.crypto&&globalThis.crypto.getRandomValues){globalThis.crypto.getRandomValues(new Uint8Array(t.length)).forEach(e=>r+=o[e%i])}else for(let e=0;e<t.length;e++)r+=o[P(i-1)];function s(e,t){const n=e.length,r=t.length,o=Math.max(n,r);for(let i=0;i<o;i++)i<n&&!S(t[i])?e[i]+=t[i]:i<r&&(e[i]=t[i])}if(!/[a-zA-Z]/.test(r))return String.fromCharCode(P(97,122)).concat(r.slice(1));for(;!/^[a-zA-Z]$/.test(r[0]);)r=r.slice(1)+r[0];return r}function W(e,t=200){if(!j(e))throw new TypeError("callback must be a function");let n;k(t)&&(t={delay:t,this:null}),(S(t.delay)||!isFinite(t.delay)||t.delay<0)&&(t.delay=200);const r=()=>{n&&(clearTimeout(n),n=void 0)},o=(...o)=>{r(),n=setTimeout(()=>{try{const n=t&&t.this?t.this:null;e.apply(n,o)}catch(e){console.log("Debounce callback throw an error",e)}},Math.max(t.delay||5,5))};return o.cancel=()=>r(),o}function A(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(){return!S(globalThis&&globalThis.process&&globalThis.process.versions&&globalThis.process.versions.node||void 0)}async function _(e=1e3){if(!isFinite(e)||e<4)throw new TypeError("delay 应该是一个正常的数值");return E(e)?Promise.resolve():new Promise(t=>setTimeout(t,e))}const z="",V=`${z}[`;function G(){return new RegExp(`(\\x1b\\[(${["([1-4]?[0-9])(;([1-4]?[0-9]+))*m","[m]","\\?(25|7)[hl]","\\d*;?\\d*[HFr]","6n","\\d{0,4}[A-DTS]","[0-3]?[JKg]","[0-6]?W"].map(e=>`(${e})`).join("|")}))`.concat("|(\\x1b[78DMc])"),"g")}const J=`${V}0m`;function H(e,t=!0){if(I(t)){if(!y(e))throw new TypeError("`color` must be a string or number but not number[] when isHex is true");if(e.startsWith("0x"))e=e.replace(/0x/,"#");else if(!e.startsWith("#"))throw new TypeError("`color` must be a string or number but not number[] when isHex is true")}else{if(!O(t))throw new TypeError("The second variable `isHex` must be boolean");if(R(e)){if(e.some(e=>!isFinite(e))||3!==e.length)throw new TypeError("If the `color` is an array, it must be 3 in length and be of numeric type");e=`rgb(${e.join(",")})`}else{if(k(e))throw new TypeError("If the `color` is not number when isHex is false");if(y(e)){if(!e.startsWith("rgb(")||!e.endsWith(")"))throw new TypeError("If the `color` is a string, it must be rgb(r, g, b)");{const t=e.replace(/.*\((.*)\).*/,"$1").split(",");if(3!==t.length||t.some(e=>!isFinite(Number(e))||Number(e)<0||Number(e)>255))throw new TypeError("If the `color` is a string, it must be rgb(r, g, b)")}}}}let n=0,r=0,o=0;if(e.startsWith("#"))if(6==(e=e.slice(1)).length)n=K(parseInt(e.slice(0,2),16)),r=K(parseInt(e.slice(2,4),16)),o=K(parseInt(e.slice(4,6),16));else{if(3!=e.length)return P(255);n=K(parseInt(e.slice(0,1).repeat(2),16)),r=K(parseInt(e.slice(1,2).repeat(2),16)),o=K(parseInt(e.slice(2,3).repeat(2),16))}else if(e.startsWith("rgb")){const t=e.replace(/.*\((.*)\).*/,"$1").split(",");n=K(Number(t[0])),r=K(Number(t[1])),o=K(Number(t[2]))}return 16+36*n+6*r+o}function K(e){const t=isFinite(e)?Math.floor(6*e/256):P(6);return Math.min(5,Math.max(0,t))}function U(e,t,n,r=!0){const o=r?"38":"48";if(k(e)&&k(t)&&k(n))return`${o};5;${H([e,t,n],!1)}`;if(y(e)&&S(t)&&S(n)){if(e.startsWith("rgb"))return`${o};5;${H(e,!1)}`;if(e.startsWith("#")||e.startsWith("0x"))return`${o};5;${H(e,!0)}`;Y()}else{if(k(e)&&S(t)&&S(n))return`${o};5;${H(e,!0)}`;Y()}}function Y(){throw new TypeError(' 使用 color() 或 bgColor() 时,可使用三整数 `r , g , b` 或单字符串 `"rgb(r , g, b)"` 或十六进制数值 `0xrgb`、`0xrrggbb` 或十六进制字符串表达 `"#rgb"`、`"#rrggbb"` ,不接受其他格式的参数')}function Z(e,t,n,r=!0){try{return U(e,t,n,r)}catch(e){throw console.error(e),new TypeError('使用 rgb() 或 bgRgb() 时,参数可以为单字符串 `"rgb(r, g, b)"` 或三个数值 `r , g ,b`。不接受其他格式')}}function Q(e,t=!0){try{return U(e,void 0,void 0,t)}catch(e){throw console.error(e),new TypeError('使用 hex() 或 bgHex() 时,参数可以为单字符串 `"0xnnnnnn"`、`"#rgb"` 、`"#rrggbb"` 或一个数值 `0xrrggbb`。不接受其他格式')}}function X(e,t=!1){return e<0&&(e=0),e>255&&(e=255),e=isFinite(e)?Math.round(e):P(255),`${[48,38][Number(t)]};5;${e}`}const ee={black:"38;5;0",red:"38;5;1",green:"38;5;2",yellow:"38;5;3",blue:"38;5;4",magenta:"38;5;5",cyan:"38;5;6",white:"38;5;7",brightBlack:"38;5;8",brightRed:"38;5;9",brightGreen:"38;5;10",brightYellow:"38;5;11",brightBlue:"38;5;12",brightMagenta:"38;5;13",brightCyan:"38;5;14",brightWhite:"38;5;15",bgBlack:"48;5;0",bgRed:"48;5;1",bgGreen:"48;5;2",bgYellow:"48;5;3",bgBlue:"48;5;4",bgMagenta:"48;5;5",bgCyan:"48;5;6",bgWhite:"48;5;7",bgBrightBlack:"48;5;8",bgBrightRed:"48;5;9",bgBrightGreen:"48;5;10",bgBrightYellow:"48;5;11",bgBrightBlue:"48;5;12",bgBrightMagenta:"48;5;13",bgBrightCyan:"48;5;14",bgBrightWhite:"48;5;15",bold:"1",dim:"2",italic:"3",underline:"4",blink:"5",reversed:"7",hide:"8",random:"random",bgRandom:"bgRandom",rgb:(e,t,n)=>Z(e,t,n),hex:e=>Q(e),color:(e,t,n)=>U(e,t,n),number:e=>X(e,!0),bgRgb:(e,t,n)=>Z(e,t,n,!1),bgHex:e=>Q(e,!1),bgColor:(e,t,n)=>U(e,t,n,!1),bgNumber:e=>X(e)};Object.freeze(ee);const te=["#000000","#c23621","#25bc24","#adad29","#492ee1","#dd38dd","#33bbc8","#cbcccd","#818383","#fc391f","#31e722","#eaec23","#5833ff","#f93578","#14f0f0","#ebeded"];function ne(e){let t=Number(e);if(!isFinite(t))throw new TypeError("色值反向解析出错");if(t<16){return te[t]}const n=e=>Math.floor(256*e/6+P(42)).toString(16).padStart(2,"0");t-=16;const r=t%36;return`#${n(Math.floor(t/36))}${n(Math.floor(r/6))}${n(r%6)}`}class re{constructor(e){this.parse(e),this.build()}build(){this.hide&&(this.color="transparent"),this.reversed&&([this.color,this.bgColor]=[this.bgColor,this.color]),S(this.color)||(this.str+=`color: ${this.color};`),S(this.bgColor)||(this.str+=`background: ${this.bgColor};`),0!==this.bold&&(this.str+=`font-weight: ${1===this.bold?800:200};`),this.italic&&(this.str+="font-style: italic;"),this.underline&&(this.str+="border-bottom: 1px #666 solid;")}color=void 0;bgColor=void 0;bold=0;italic=!1;underline=!1;reversed=!1;hide=!1;str="";parse(e){e.replace(/38;5;(\d+)/g,"c-$1").replace(/48;5;(\d+)/g,"b-$1").split(";").reverse().forEach(e=>{0===this.bold&&e===ee.bold?this.bold=1:0===this.bold&&e===ee.dim?this.bold=-1:e===ee.italic?this.italic=!0:e===ee.underline?this.underline=!0:e===ee.reversed?this.reversed=!0:e===ee.hide?this.hide=!0:S(this.color)&&e.startsWith("c")?this.color=ne(e.split("-")[1]):S(this.bgColor)&&e.startsWith("b")&&(this.bgColor=ne(e.split("-")[1]))})}}function oe(e){return q()?[e]:function(e){e=e.replace(new RegExp("\\\\[0m","g"),"[m");const t=G(),n=[""];let r,o=0,i="";const s=()=>{const t=e.substring(o,r?.index??e.length);n[0]+="%c".concat(t),n.push(i)};for(;!T(r=t.exec(e));)s(),i=S(r[7])?new re(r[3].slice(0,-1)).str:"",o=t.lastIndex;return s(),n}(e)}function ie(e,t){if(x(e=T(e)||S(e)?"":e.toString()))return"";if(N(t))return e;const n=e.indexOf(V),r=e.indexOf(`${V}0m`);return t=function(e){return e.map(e=>"random"===e?`38;5;${P(255)}`:"bgRandom"===e?`48;5;${P(255)}`:e)}(t),n>-1&&r>-1?ie(e.substring(0,n),t).concat(e.substring(n,r+4)).concat(ie(e.substring(r+4),t)):e.endsWith("\r\n")?(e=e.substring(0,e.length-2),`${V}${t.join(";")}m${e}${V}0m\r\n`):e.endsWith("\n")?(e=e.substring(0,e.length-1),`${V}${t.join(";")}m${e}${V}0m\n`):`${V}${t.join(";")}m${e}${V}0m`}function se(e,t){const n=parseInt(t);if(n>10){const r=I(38===n)?"38;5;":"48;5;",o=e.findIndex(e=>e.startsWith(r));return o>-1?e.toSpliced(o,1,t):[...e,t]}return e.includes(t)?[...e]:[...e,t]}const ae=b(function(e=[]){const t=(t,...n)=>{if(B(t,()=>R(t)&&t.every(e=>y(e)))){let r="";for(let o=0;o<t.length;o++)r+=ie(t[o],e),o<n.length&&(r+=ie(n[o],e));return r}if(N(n))return ie(t,e);throw new Error("pen: 缺少参数")},n=Object.keys(ee).map(t=>[t,{get:()=>function(e,t){let n=[];if(B(e,y(ee[e])))return n=se(t,ee[e]),new ae(n);if("hex"===e||"bgHex"===e)return r=>(n=se(t,ee[e](r)),new ae(n));if("rgb"===e||"bgRgb"===e)return(r,o,i)=>{if(y(r)&&S(o)&&S(i))n=se(t,ee[e](r));else{if(!(k(r)&&k(o)&&k(i)))throw new Error(`${e} 的参数类型不正确,请使用 'rgb' 或 'hex' 函数`);n=se(t,ee[e](r,o,i))}return new ae(n)};if("color"===e||"bgColor"===e)return(r,o,i)=>{if(y(r)&&S(o)&&S(i))n=se(t,ee[e](r));else{if(!(k(r)&&k(o)&&k(i)))throw new Error(`${e} 的参数类型不正确,请使用 'rgb' 或 'hex' 函数`);n=se(t,ee[e](r,o,i))}return new ae(n)};if("number"===e||"bgNumber"===e)return r=>{if(k(r))return n=se(t,ee[e](r)),new ae(n);throw new TypeError(`${e} 的参数应为有效正整数数值,范围 0 - 255`)};throw new Error(`${e} 函数不存在`)}(t,e)}]),r=Object.fromEntries(n);return Object.defineProperties(t,r),t});const ce=new ae([]),le=new ae([ee.red]),ue=new ae([ee.green]),fe=new ae([ee.yellow]),he=new ae([ee.blue]),de=new ae([ee.magenta]),ge=new ae([ee.cyan]);new ae([ee.white]);const pe=new ae([ee.brightBlack]),be=new ae([ee.brightRed]),me=new ae([ee.brightGreen]),we=new ae([ee.brightYellow]);new ae([ee.brightBlue]);new ae([ee.brightMagenta]);const ye=new ae([ee.brightCyan]);new ae([ee.brightWhite]);const ve=new ae([ee.bgBlack]);new ae([ee.bgRed]),new ae([ee.bgGreen]),new ae([ee.bgYellow]),new ae([ee.bgBlue]),new ae([ee.bgMagenta]);const xe=new ae([ee.bgCyan]);new ae([ee.bgWhite]),new ae([ee.bgBrightBlack]),new ae([ee.bgBrightRed]),new ae([ee.bgBrightGreen]);const $e=new ae([ee.bgBrightYellow]);new ae([ee.bgBrightBlue]);const ke=new ae([ee.bgBrightMagenta]);new ae([ee.bgBrightCyan]),new ae([ee.bgBrightWhite]);const Ee=new ae([ee.bold]),Ce=new ae([ee.italic]),Ie=new ae([ee.underline]),Oe=new ae([ee.hide]);new ae([ee.dim]),new ae([ee.blink]);const Te=new ae([ee.reversed]);ce.rgb;const Se=ce.hex;ce.color,ce.bgRgb;const je=ce.bgHex;function Re(e){const t=G(),n=e.replace(t,"");let r=0;for(let e=0,t=n.length;e<t;e++)r+=1+Number(Ne(n[e]));return r}function Ne(e){const t=e.codePointAt(0)||0;return t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=191471||t>=63744&&t<=64255||t>=65280&&t<=65519||t>=65381&&t<=65439||t>=127744&&t<=129750||t>=128512&&t<=128591||t>=128640&&t<=128767||t>=9728&&t<=9983||t>=9984&&t<=10175||t>=44032&&t<=55215||t>=12288&&t<=12351}function Me(e,t,n=!0){const r=t,o=e;if(0===r)return"";let i=!1;const s=Re(o);if(s<=r)return o.concat(" ".repeat(r-s));const a=r>0,c=G();c.lastIndex=0;const l=[...o.replaceAll(c,"")],u=a?l:l.reverse(),f=u.length,h=Math.abs(r);let d=Math.floor(h/2),g=u.slice(0,d).join(""),p=Re(g);for(;d<f;){if(p+=Re(u[d]),p===h){g+=u[d];break}if(p===h+1){n&&(i=!0);break}if(p>h+1)break;g+=u[d],d++}if(a&&o.startsWith(g)||!a&&o.endsWith(g=[...g].reverse().join("")))return i?g+" ":g;if(a){let e;for(c.lastIndex=0;null!==(e=c.exec(o));){const t=g;if(g=t.slice(0,e.index).concat(e[0]).concat(t.slice(e.index)),o.startsWith(g))break}g+=J}else{const e=[...g];let t=e.length-1;g="";const n=[...o].reverse();for(let r=0,o=n.length;r<o;r++){const o=n[r];if(o===e[t])--t;else if(t<0)break;g=o+g}g=J+g}return i?g+" ":g}function De(e){return`${V}?7l${e.toString()}${V}?7h`}ce.bgColor,ce.random,ce.bgRandom,ce.number,ce.bgNumber;const Le=[!1,!0,"all","info","error","warn"];const Be=q()?"node":"browser";const Pe=b(Fe);function Fe(e){const t=function(e){const t={name:F(10),type:!1,fold:!1};return S(e)?t:C(e)?(t.type=e,t):y(e)?(t.name=e.trim().replace(/\s+/g,"_"),t):(y(e.name)&&(e.name=e.name.trim().replace(/\s+/g,"_")),e.fold=Boolean(e.fold),e)}(e);this.name=t.name||F(12),this.fold=Boolean(t.fold);const n=function(e=F(10)){let t=!1;if("node"===Be&&globalThis?.process?.env){const n=process.env;t=n[e.toUpperCase().concat("_DEV")]||n[e.toLowerCase().concat("_dev")]||!1}return"false"!==t&&("true"===t||t)}(this.name);let r=t.type||!1;this.mark="",this.type="node"!==Be||function(e){return!!Le.includes(e)&&e}(n??r);const o=e=>{try{throw new Error}catch(t){const n=(t.stack?.split("\n")||[]).map(e=>{const t=/at\s(.*)\s\((.*):(\d*):(\d*)\)/.exec(e);return t?{name:t[1],path:t[2],line:t[3],column:t[4]}:{name:""}}),r=n.filter(e=>""!==e.name&&void 0!==e.path),o=r[3]??r[2]??r[1]??r[0],i=` ${"info"===e?"💡":"error"===e?"❌":"⚠️ "} ${(new Date).toLocaleString()} `,s=("info"===e?xe.brightWhite:"error"===e?ve.red:$e.brightGreen)(i),a=o?.name??"";this.fold&&a&&(a===this.mark||(this.mark&&console.groupEnd(),console.groupCollapsed(a))),this.mark=a;return oe(`${s} ${a} ${o?.line?.concat(" 行")} ${o?.column?.concat(" 列")}`)}};this.info=(...e)=>{if("all"===this.type||"info"===this.type||!0===this.type){const t=o("info");console.log(...t),console.log(...e)}},this.warn=(...e)=>{if("all"===this.type||"warn"===this.type||!0===this.type){const t=o("warn");console.log(...t),console.warn.apply(console,e)}},this.error=(...e)=>{if("all"===this.type||"error"===this.type||!0===this.type){const t=o("error");console.log(...t),console.error.apply(console,e)}};const i=(...e)=>{this.info(...e)};Object.setPrototypeOf(i,this);const s=this;return new Proxy(i,{get:(e,t,n)=>"apply"===t?e:Reflect.get(e,t,n),set:(e,t,n)=>(Reflect.set(s,t,n),!0)})}Fe.prototype.clear=()=>{"browser"===Be?console.clear():console.log(z.concat("c"))};const We=new Pe({name:"nry",type:!1}),Ae=O(We.type);function qe(t){return e(t,{throwIfNoEntry:!1})}const _e=new Pe({type:"error",name:"a node tools"});function ze(...e){return l(u(...e))}function Ve(e,t="file",...n){n=n.filter(e=>y(e));let r=f(...n);const o=qe(r);if(_e("当前工作目录",r),!o)return _e("🎯 工作目录不存在"),"";if(o.isFile())r=c(r);else if(!o.isDirectory())return;let i=20;const s=()=>{const n=qe(ze(r,e));if(n&&("file"==t&&n.isFile()||"directory"==t&&n.isDirectory()))return r;if(E(i))return;i--,_e("♻️ 查找中...",r);const o=ze(r,"..");return o!==r?(r=o,s()):void 0};return s()}function Ge(n){if(!/.json^/.test(n)&&!e(n,{throwIfNoEntry:!1}))return null;try{const e=t(n,{encoding:"utf-8"});return JSON.parse(e||"null")}catch(e){return _e.error(e),null}}function Je(e,t){try{return r(e,JSON.stringify(t,null,2),{encoding:"utf-8",flag:"w"}),!0}catch(e){return _e.error(e),!1}}const He=()=>q()&&process&&process.stdout&&process.stdout.isTTY||!1,Ke=q()&&"win32"===process.platform||!q()&&window.navigator.userAgent.includes("Windows");function Ue(e){const t=new RegExp(e);let n;try{throw new Error}catch(e){n=e}const r=(n.stack?.replace(/\\/gm,"/").split("\n")).reverse(),o=r.findIndex((e,n,r)=>!t.test(e)&&t.test(r[n+1]));if(-1==o)return{name:"",line:0,row:0,originArr:r};let i=r[o];return/\(.*\)/.test(i)&&(i=i.replace(/^.*\((.*)\).*/,"$1")),/file:\/*/.test(i)&&(i=i.replace(/^.*file:\/*(.*)/,"$1")),Ke||i.startsWith("/")||(i="/"+i),{name:i.replace(/^(.*):\d+:\d+$/,"$1"),line:Number(i.replace(/^.*:(\d+):\d+$/,"$")),row:Number(i.replace(/^.*:\d+:(\d+)$/,"$1")),originArr:r}}function Ye(){let e;try{new Function('import("")'),e=h(import.meta.url)}catch(t){_e.error(t),e=__filename}Ke&&(e=e.replace(/\\/gm,"/")),e=Ue(e).name;return[e,c(e)]}const{stdin:Ze}=process,Qe={list:[],listened:!1,on(e,t,n){O(this.listened)&&(this.listened=!0,g(process.stdin),He()&&process.stdin.setRawMode(!0),process.stdin.resume(),Ze.on("keypress",tt),process.on("beforeExit",Xe),process.stdin.on("end",et));const r=this.list,o={key:e,callback:t,resolve:n};return N(r)&&_e("当前执行的栈中没有数据",o),r.push(e),this[e]=o,o},remove(){const e=this.list,t=e.shift();return t&&this.del(t),_e("执行完毕一项,还有:",e),!(e.length>0)&&(this.listened=!1,Xe(),_e("代理已移除"),!0)},del(e){_e("开始移除",e);const t=this.list[0]===e&&!S(this[e]);if(_e("当前 key 是否为当前执行项",t),t)return this.remove(),!0;{const t=this.list.includes(e),n=!S(this[e]);return t&&n?(this.list.splice(this.list.indexOf(e),1),this[e].resolve(!0),delete this[e],!0):t?(this.list.splice(this.list.indexOf(e),1),!0):!!n&&(this.list.splice(this.list.indexOf(e),1),this[e].resolve(!0),!0)}}};function Xe(){Ze.removeListener("keypress",tt),process.removeListener("beforeExit",Xe),process.stdin.removeListener("end",et),He()&&Ze?.setRawMode(!1),Ze.pause()}function et(){Xe()}function tt(e,t){const n=Qe[Qe.list[0]],{callback:r,resolve:o}=n;_e("当前执行的回调是",{...n,rl:"原始值为 readline 的 Interface 对象"}),j(r)?I(Reflect.apply(r,null,[e,t]))&&(_e("回调遇见了想待的键,执行了退出操作,keyValue: < ",e,"> key: <",t,">"),Qe.remove(),o(!0)):(Qe.remove(),o(!1))}const nt=(e,t)=>async function(e,t){if(!q())throw new RangeError("当前环境不支持 readInput");const n=t??Symbol(F(3));return new Promise(t=>{Qe.on(n,e,t)})}(e,t);function rt(e="",t=!0){let n="";const r=w(e);if(!C(t))throw _e.error(""),new TypeError("lineFeed 的类型必须是 boolean ");if("bigint"===r){const r=Object.prototype.toString.call(e).concat("n");n=t?`${r}\n`:`${r}`}else if(["string","number","boolean","function","null"].includes(r))n=t?`${e}\n`:`${e}`;else{const r=JSON.stringify(e,(e,t)=>j(t)?`${t}`:null==t?"undefined":t,2);n=t?`${r}\n`:`${r}`}q()?process.stdout.write(n):console.log(...oe(n.replace(/\n$/,"")))}function ot(e,t=!0){rt(`${t?V:z}${e}`,!1)}function it(){ot("?25l")}function st(){ot("?25h")}function at(e=!1){e&<(1/0),ot("0J")}function ct(e=1,t=!1){ot(`${ft(e,"vertical")}A`),t&<(1/0)}function lt(e=1){ot(`${ft(e)}D`)}function ut(e=1){ot(`${ft(e)}C`)}function ft(e,t="horizontal"){(!k(e=Number(e))||isNaN(e)||e<1||!1===Number.isInteger(e)&&e!==1/0)&&(e=1);const n=q()?"horizontal"===t?process.stdout.columns:process.stdout.rows:80;return(1/0===e||e>n)&&(e=n),e}function ht(){st()}function dt(e){const t=e[e.length-1];y(t)&&!t.endsWith("\n")&&e.push("\n"),e.forEach(e=>rt(e,!1))}function gt(e,t){const{show:n,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}=t??{show:!0,info:"请等待",prefix:0,interval:20,canCtrlCExit:!1,canCtrlDExit:!1,beforeDestroyed:()=>{}},l=C(e)?{show:e,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:y(e)?{show:n,info:e,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:S(e)?{show:n,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:k(e)?{show:!0,info:"请等待",prefix:isNaN(e)?o:Math.min(Math.max(0,e),2),interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:{show:n,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c,...e};return l.interval=isFinite(l.interval)?Math.max(20,Math.min(2e3,l.interval)):i,l.info=l.info.replace(/\n/g,"\\n"),l}function pt(){st()}Object.defineProperties(nt,{remove:{value:e=>Qe.del(e)}});const bt=[".","..","...","....","...",".."],mt=[["⋯","⋱","⋮","⋰","⋯","⋱","⋮","⋰"],["🕐","🕑","🕒","🕓","🕔","🕕","🕖","🕗","🕘","🕙","🕚","🕛"],["🕜","🕝","🕞","🕟","🕠","🕡","🕢","🕣","🕤","🕥","🕦","🕧"],["👈","👆","👉","👇","🤘","🤟","🫳","🫴","👊"],["🌞","🌕","🌖","🌗","🌜","🌘","🌑","🌒","🌓","🌛","🌔","🌔","🌔","🌝"]];class wt{#e;#t=void 0;#n=Symbol("waiting-tips");#r=[];#o=(...e)=>dt(e);state="destroyed";#i=0;#s=4e4;#a=!1;async destroyed(){"destroyed"!==this.state&&(this.state="destroyed",this.#i=0,S(this.#t)||clearInterval(this.#t),nt.remove(this.#n),lt(1/0),at(),process.removeListener("exit",ht),process.removeListener("SIGINT",pt),st(),this.#r.forEach(e=>this.#o(...e)),this.#r.length=0,this.log=this.#o,"promise"!==w(this.#e.beforeDestroyed)?this.#e.beforeDestroyed(this.#a):await this.#e.beforeDestroyed(this.#a),this.#a=!1)}log=this.#o;run(e){"run"===this.state&&this.destroyed(),this.#a=!1,this.state="run",this.#i=Date.now(),this.#e=S(e)?this.#e:gt(e,this.#e);const{prefix:t,info:n,interval:r,canCtrlCExit:o,canCtrlDExit:i}=this.#e;this.log=(...e)=>this.#r.push(e);const s=bt.length,a=mt[Math.min(mt.length-1,Math.max(t,0))],c=a.length,l=a.reduce((e,t)=>Math.max(e,Re(t)),0);let u=0;it(),process.on("exit",ht),process.on("SIGINT",pt),this.#t=setInterval(()=>{at(!0),this.#r.forEach(e=>dt(e)),this.#r.length=0,rt("\n".repeat(2)),ct(3),ot(7,!1);const e=Me(a[++u%c],l);Date.now()-this.#i<this.#s?rt(De(`${e} ${n.replace(/\n/,"\\n")}${bt[Math.floor(u/10)%s]}`),!1):rt(De(`${e} ${n} ${de`当前已执行 ${Math.ceil((Date.now()-this.#i)/1e3)} 秒`}\n \n\r${ge`可使用双击 esc 键退出(确保执行完成,若执行仍在期望时间内,请忽略)`}`),!1),ot(8,!1)},r),nt((e,t)=>!!(t?.meta&&t?.sequence===z.repeat(2)||I(t?.ctrl)&&(o&&"c"===t?.name||i&&"d"===t?.name))&&(this.#a=!0,this.destroyed(),!0),this.#n)}set timeout(e){this.#i=Date.now(),this.#s=!isFinite(e)||e<0?4e4:e<600?1e3*e:e}get timeout(){return this.#s}constructor(e){this.#e=gt(e),I(this.#e.show)&&this.run()}}function yt(e,t,n){let r=e.toString().trim();return/\n$/.test(r)||(r=r.concat(Ke?"\r\n":"\n")),r=r.replace(/\n+/g,"\n"),at(),t&&n.log(r),r}function vt(e,t){if(O(q()))throw new RangeError("当前环境不支持 node 环境");const{env:r}=t;y(e)&&(r.code=e,e={code:e,waiting:!1});const o=process.cwd();let i=p(o,e.cwd||"");-1===function(e){try{const t=qe(e);if(t&&t.isDirectory())return 0==n(e,{withFileTypes:!0}).length?1:0}catch(e){return _e.error("is ",e),-1}return-1}(i)&&(_e(`执行目录 ${le(i)} 不存在,使用命令执行目录 ${ge(o)}`),i=o);const s=e.code.replace(/\s{2,}/g," ").trim().split(" ");Object.assign(t.env,{shell:!0,hideWaiting:!0,waitingMessage:"请稍等",printLog:!1,...e,cmd:s,cwd:i})}function xt(e){const t={result:{success:!1,data:"",error:"",status:1,isSIGINT:!1,runCode:"",runCwd:""},env:{cmd:[],code:"",cwd:"",printLog:!1,shell:!0,callBack:()=>{},waiting:{show:!1,info:"",prefix:0,interval:10,canCtrlDExit:!1,canCtrlCExit:!1,async beforeDestroyed(){}}}},{env:n,result:r}=t;_e("runOtherCode 方法 开始执行 "),vt(e,t),_e("执行参数",t);const{cmd:o,waiting:i,cwd:s,shell:a,code:c}=n,[l,u]=(()=>{if(i instanceof wt)return[i,"run"===i.state];const e=gt(i);return[(t=e,new wt(t)),e.show];var t})();r.runCode=c,r.runCwd=s||process.cwd();try{return new Promise(e=>{const n=I(a)?d(c,[],{cwd:s,shell:a}):d(o[0],o.slice(1),{cwd:s,shell:a});u&&l.run({beforeDestroyed:e=>{if(e){if(_e("执行退出前"),Ke){try{n.killed||n.kill(-1)}catch(e){_e.error("使用 child.kill(child.pid, -1 ) 关闭子进程失败",e),d("taskkill",["/pid",n.pid?.toString()||"","/T","/F"],{stdio:"pipe"})}_e("终结在 windows 下的子进程")}else n.kill("SIGTERM"),_e("终结在非 windows 下的子进程");t.result.isSIGINT=!0}}}),n.on("spawn",()=>function(e){const{result:t}=e;_e("子线程已启动,运行状态良好"),t.success=!0,t.status=1}(t)),n.stdout.on("data",e=>function(e,t,n){const{env:r,result:o}=t,i=yt(e,r.printLog,n);_e(ke`stdout on data`,i),o.data+=i}(e,t,l)),n.on("exit",(e,t)=>{_e("子进程已退出了,退出码为 <",e,">"),T(t)||_e.error("子进程被其他信号中断执行,执行的退出信号为:",t)}),n.stderr.on("data",e=>function(e,t,n){const{env:r,result:o}=t,i=yt(e,r.printLog,n);_e(ke`stderr on data`,i),o.error+=i}(e,t,l)),n.on("error",e=>function(e,t,n){const{env:r,result:o}=t;{const t=yt(e,r.printLog,n);_e(ke`error`,t),_e.error("error",t),o.success=!1,o.status=""!==o.data?2:3,o.error+=t}}(e,t,l)),n.on("close",(n,r)=>function(e,t,n,r,o){const{env:i,result:s}=r,{callBack:a}=i;_e("进行正常关闭",e),setTimeout(async()=>{a&&j(a)&&await Promise.resolve(Reflect.apply(a,null,[])),await o.destroyed(),0!==e&&"SIGINT"!==t&&"SIGTERM"!==t?(s.success=!1,s.status=3):"SIGINT"!==t&&"SIGTERM"!==t||(s.success=!1,s.status=4,s.isSIGINT=!0),n(s)})}(n??0,r??"",e,t,l))})}catch(e){const t=e.toString();return _e.error("创建(但是确是非 node 无法创建子进程,而是更上游的 node 创建的错误)子进程出错",e),new Promise(e=>{(async()=>{await l.destroyed()})(),r.error=t,r.success=!1,r.status=0,e(r)})}}const $t=e=>xt(e);async function kt(e,t=10){if(!y(e))throw new TypeError("str 需是一个字符串");if(!isFinite(t)||t<0||t>1e4)throw new RangeError("delay 需是一个 0 到 10000 之间(不包括两端)的数值");const n=Array.from(e);if(0!==n.length){for(const r of n)await _(t),_e(`当前字符 ${Ee(r)} 长度为:`,r.length),_e(`当前字符 ${ce.reversed(r)} 在 charCodeAt`,r.charCodeAt(0),r.charCodeAt(1),r.charCodeAt(2)),1===r.length&&isNaN(r.charCodeAt(1))?rt(r,!1):2===e.length&&e.charCodeAt(0)>=55296&&e.charCodeAt(0)<=56319&&e.charCodeAt(1)>=56320&&e.charCodeAt(1)<=57343?(rt(r,!1),rt(" ",!1)):2===e.length&&65039===e.charCodeAt(1)?(rt(r,!1),rt(" ",!1)):(rt(r,!1),rt(" ",!1));rt()}else rt()}const Et=process.argv.slice(2);Object.freeze(Et);class Ct{originalArg=Et.slice();name="";__filename="";get state(){return this._state}set state(e){this._state=[void 0,{code:1,text:"start"},{code:2,text:"bind over"},{code:3,text:"run over"},{code:4,text:"over",overCode:e}][k(e)?e:4]}_state={code:1,text:"start"};args=new It;abbr={};helpInfo="";hasShowVersion=!1;originalBind={};values=[]}class It extends Array{get $nomatch(){return[]}get $map(){return{}}get $arrMap(){return[]}get $only(){return[]}get $original(){return[]}get $isVoid(){return!1}}const Ot={},Tt=new Pe({name:"a command"}),St=O(Tt.type);function jt(e){return[e.replace(/^(.*?)\s.*/gm,"$1")||"",/<.+>/.test(e)&&e.replace(/.*<(.+)>.*/,"$1")||"",e.replace(/.*?\((.*)\).*?/,"$1")||""]}function Rt(e,t){switch(t.state.code){case 3:return void Tt.warn("执行绑定","但是已经执行过 `run`");case 4:return void Tt.warn("执行绑定,但是 command 已完成全部应做动作");default:t.state=2}if(y(e)){const[n,r,o]=jt(e);return Rt({name:n,abbr:r,info:o},t)}if(R(e))return e.forEach(e=>Rt(e,t));if(!S(e)&&!e.name&&!e.info)return function(e,t){const n={name:"",info:"",abbr:"",options:[]},r=Object.keys(e),o=Object.keys(n);return r.forEach(n=>{if(!o.includes(n)){const[r,o,i]=jt(n);return Rt({name:r,info:i,abbr:o,options:e[n]},t)}})}(e,t);const n=e;n.abbr&&(t.abbr[n.abbr]=n.name),n.options?n.options=function(e,t,n){R(e)||(e=[e]);const r={};return e.forEach(e=>{let o={name:"",abbr:"",info:""};y(e)?[o.name,o.abbr,o.info]=jt(e):o=Object.assign(o,e),o.abbr&&(n.abbr[`${t}^${o.abbr}`]=o.name),r[o.name]=o}),r}(n.options,n.name,t):n.options={},t.originalBind[n.name]={abbr:"",...n}}function Nt(){return new Proxy(new Ct,{get(e,t,n){if("args"===t){const t=JSON.parse(JSON.stringify(e[Symbol.for("_args")]||[]));return new Proxy(t,{get(n,r,o){return"$nomatch"===r?e.values.slice():"$map"===r?function(e){if(N(e))return{};const t=new Object;return e.forEach(e=>{const n=t[e.name]||{};n.value=[...n.value||[],...e.value||[]],e.options&&e.options.forEach(e=>{n[e.name]=[...n[e.name]||[],...e.value||[]]}),t[e.name]=n}),t}(t):"$arrMap"===r?N(i=t)?[]:i.map(e=>{const t={},n=t[e.name]||{};return e.value&&!N(e.value)&&(n.value=e.value),S(e)||S(e.options)||N(e.options)||(n.options=[],e.options.forEach(e=>{n.options?.push(Object.fromEntries([[e.name,e.value]]))})),t[e.name]=n,t}):"$only"===r?[...new Set(t.map(e=>e.name))]:"$original"===r?Et.slice():"$isVoid"===r?0==Et.slice().length:Reflect.get(n,r,o);var i},set:(e,t,n,r)=>(Reflect.set(e,t,n,r),!0)})}return Reflect.get(e,t,n)},set:(e,t,n,r)=>("args"===t?e[Symbol.for("_args")]=n:Reflect.set(e,t,n,r),!0)})}const Mt=" ".repeat(4);function Dt(e){return e.state="help",y(e.helpInfo)&&"help"!==e.helpInfo?function(e,t){const n=e.originalBind[t];if(rt(`${Mt}${n.name}${Mt}${de(n.info)}\n`),n.options&&!D(n.options)){rt(`${fe(`${Mt}使用:`)} ${e.name} ${t} [subOptions/subAbbr [value]]\n`),rt(`${ge(`${Mt}subOptions:`)} \n`),Lt(n.options||{})}else{rt(`${ue(`${Mt}使用:`)} ${e.name} ${t} [value]\n`)}}(e,e.helpInfo):R(e.helpInfo)&&2==e.helpInfo.length?function(e){const t=e.name,n=e.helpInfo.join(" "),r=e.originalBind[e.helpInfo[0]].options[e.helpInfo[1]].info;rt(`${ge(" 可使用:")} ${t} ${n} [value]\n${ue(" 描述:")} ${r}`)}(e):function(e){rt(`${be(" 可使用:")} ${e.name} options/abbr [subOptions/subAbbr [value]]\n\n选项:\n`);const t=Lt(e.originalBind);!function(e){["version -v 版本描述","help -h 帮助查看"].forEach(t=>{const[n,r,o]=t.split(" ");rt(Bt({len:e,name:n,info:o,abbr:r})),rt("")})}(t)}(e)}function Lt(e){const t=Object.keys(e).sort();let n=8;t.forEach(e=>n=Math.max(n,e.length));const r=Math.min(15,n+1);return rt(Bt({len:r,name:"子命令",info:"描述",abbr:"缩写",color:!1})),rt(""),t.forEach(t=>{const{name:n,abbr:o,info:i}=e[t];let s=!1;"options"in e[t]&&!D(e[t].options)&&(s=!0),rt(Bt({len:r,name:n,info:i,abbr:o,textDecoration:s})),rt("")}),r}function Bt(e){const t=Object.assign({name:"",info:"",abbr:"",len:15,color:!0,textDecoration:!1},e);let n=ce[t.color?"green":"black"](Mt);return n+=ce[t.textDecoration?"blue":"black"](t.name.slice(0,t.len)),n+=" ".repeat(t.len+1-Pt(t.name,t.len)),n+=ce[t.color?"yellow":"black"]`${t.abbr?.slice(0,6)||""}${" ".repeat(7-Pt(t.abbr||"",6))}`,n+=t.color?de(t.info):t.info,n}function Pt(e,t){return Math.min(e.replace(/[^\x00-\x7f]/,"11").length,t)}const Ft="";function Wt(e){const{name:t,object:n,item:r,result:o}=e;$(t)||(r.name&&n.options?.push(r),o.push(JSON.parse(JSON.stringify(n))))}function At(e,t){"true"==e?e=!0:"false"==e?e=!1:e==Number(e)&&(e=Number(e)),$(t.name)?t.values.push(e):t[t.item.name?"item":"object"].value.push(e)}function qt(e,t){const n=[];let r="";const o=(e,t)=>S(t)||$(t)?n.push(e):n.push(e,t);function i(e,s){if(!$(r)){if(t.originalBind[r].options[e])return o(e,s);const n=t.abbr[`${r}^${e}`];if(!S(n))return o(n,s)}if(t.originalBind[e])return r=e,o(e,s);if(t.abbr[e])return e=t.abbr[e],r=e,o(e,s);if(e.includes("=")){const t=e.indexOf("=");if(0===t||t===e.length-1)return n.push(e);const[r,o]=[e.slice(0,t),e.slice(t+1)||"true"];return i(r,o)}return S(s)||$(s)?n.push(e):n.push(`${e}=${s}`)}return e.forEach(e=>i(e)),n}function _t(e,t,n){n.init(),(e=qt(e.filter(e=>""!==e),t)).forEach(e=>{const{name:r}=n;return e=e.trim(),/^([a-z]|[A-Z]|-|\$|_)/.test(e)?!$(r)&&t.originalBind[r].options&&t.originalBind[r].options[e]?function(e,t){const{item:n,object:r}=t;n.name&&r.options.push(n),t.resetItem(e)}(e,n):t.originalBind[e]?function(e,t){$(t.name)||(Wt(t),t.resetItem("")),t.resetObject(e)}(e,n):At(e,n):At(e,n)}),Wt(n)}function zt(e){switch(e.state.code){case 3:return void rt("已经执行过 `run`");case 4:return void rt("已完成全部");default:e.state=3}!function(e){if(2==process.argv.length)return;const t=e.originalArg,n=`${Ft}${t.join(Ft)}${Ft}`,r=t.findIndex(e=>/^(-h|help)$/.test(e));if(new RegExp(`${Ft}(-v|version)${Ft}`,"i").test(n))return void(e.hasShowVersion=!0);if(E(r))return void(e.helpInfo="help");let o=[];const i={result:[],values:[],name:"",object:{name:"",value:[],options:[]},item:{name:"",value:[]},resetObject(e){this.name=e,this.object={name:e,value:[],options:[]}},resetItem(e){this.item={name:e,value:[]}},init(){this.result=[],this.values=[],this.resetItem(""),this.resetObject("")}};r>0?(_t(t.slice(0,r+1),e,i),e.values=i.values,e.args=i.result,o=e.args,N(o)?e.helpInfo="help":[S,N].some(e=>e(o[0].options))?e.helpInfo=o[0].name:e.helpInfo=[o[0].name,o[0].options[0].name]):(_t(t,e,i),e.values=i.values,e.args=i.result)}(e),function(e){["name","originBind","abbr"].forEach(t=>{const n=t;e[n]&&(Object.freeze(e[n]),Object.defineProperty(e,t,{value:e[n],writable:!1,enumerable:!0,configurable:!1}))})}(e)}function Vt(e){e.state="version";const t=Ve("package.json","file",Ue(e.__filename).name);if(S(t))return Gt();const n=ze(t,"package.json");if(!qe(n))return Gt();const r=Ge(n);if(T(r))return Gt();const{platform:o}=process,i=ce.brightCyan(r.name),a=r.version,c="win32"==o?"Windows":"darwin"==o?"mac":o,l=ce.brightMagenta(s());rt(`${i} 版本 ${ce.brightRed(a)} (${c} ${l})`)}function Gt(){rt("抱歉,未找到版本定义说明")}const Jt=Se("#333"),Ht=Se("#666"),Kt=Se("#aaa"),Ut=je("#666"),Yt=Ht(".".repeat(3)),Zt=(e="❖")=>me(e),Qt=(e="▶︎")=>we(e),Xt=(e="⚉")=>be(e),en=(e="◦")=>Ht(e),tn=(e="●")=>me.blink(e),nn=(e="□")=>Ht(e),rn=(e="□")=>me.blink(e),on=(e="■")=>Ht(e),sn=(e="■")=>me.blink(e);function an(e,t="⚉"){rt(`${Xt(t)} ${Se("#612").italic(e)}`)}function cn(e,t="❖"){rt(`${Zt(t)} ${e}`)}const ln={callList:[],on(e,t){const n=this.callList;N(n)&&(Tt("当前执行列表为空,直接执行任务",e),Reflect.apply(t,void 0,[])),n.push([e,t])},remove(e){const t=this.callList,n=t.findIndex(([t])=>t===e);return t.splice(n,1),N(t)?(Tt("当前执行列表为空,返回 true 结束执行"),!0):(Reflect.apply(t[0][1],null,[]),!1)}};function un(e=!0){return process.stdout.rows-4*(1+Number(e))}function fn(e){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];if(B(r,e=>[y,k].some(t=>t(e))))t.push({value:r,label:r,checked:!1,tip:"",disable:!1});else{if(!B(r,e=>[y,y].some(t=>t(e.label))&&[y,k,L].some(t=>t(e.value))))throw new TypeError(`${r} 的类型非法(有可能是返回值类型更改后未在解析中兼容)`);{let e=r.checked;!S(e)&&C(e)||(e=!1);let n=r.tip;!S(n)&&y(n)||(n="");const o=r.value;if(S(o)||T(o))throw new TypeError("value 值类型非法");const i=r.label,s=I(r.disable);t.push({checked:e,tip:n,value:o,label:i,disable:s})}}}return t}const hn="请使用键盘选择,请使用 Enter 键进行选择",dn=!1,gn="radio",pn={drawData:[],info:hn,focus:0,renderInfo:{rows:0,renderRows:0,otherInfoRows:0,allowBelow:!1,size:{width:0,height:0}},resultText:"",errorText:"",private:dn,required:dn,kind:gn,canCtrlCExit:dn,canCtrlDExit:dn,mustInfo:dn,maxRows:un(),data:[],initData(e){Tt("初始化数据"),this.reset(),R(e)?this.data=fn(e):Object.keys(e).forEach(t=>{const n=e[t];switch(t){case"data":this.data=R(n)?fn(n):[];break;case"info":this.info=y(n)?n:hn;break;case"resultText":this.resultText=y(n)?n:this.info||"";break;case"errorText":this.errorText=y(n)?n:this.resultText||this.info||"";break;case"private":this.private=C(n)?n:dn;break;case"required":this.required=C(n)?n:dn;break;case"kind":this.kind="check"===n?"check":gn;break;case"canCtrlCExit":this.canCtrlCExit=C(n)?n:dn;break;case"canCtrlDExit":this.canCtrlDExit=C(n)?n:dn;break;case"maxRows":this.maxRows=isFinite(n)&&Number.isInteger(n)&&n>0?n+4:un()}});const t=this.data;for(const e in t){if(!t[e].disable)return this.focus=Number(e),!1}return!0},reset(){this.drawData.length=this.data.length=this.focus=0,this.maxRows=un(),this.renderInfo={rows:0,renderRows:0,otherInfoRows:0,allowBelow:!1,size:{width:0,height:0}},this.info=hn,this.kind=gn,this.resultText=this.errorText="",this.private=!0,this.required=this.canCtrlCExit=this.canCtrlDExit=this.mustInfo=dn}};function bn(e){const{data:t}=pn,n=process.stdout.columns-7,r=n-3,o=t[e].label.toString();return Re(o)<=n?o:Me(o,r,!1).concat(Yt)}const mn=()=>{!function(){const{focus:e,drawData:t,data:n,kind:r}=pn;for(let o=0,i=n.length;o<i;o++){const i=n[o];if(S(t[o])){const n=Re(i.label.toString());t[o]={index:o,text:bn(o),length:n,checked:"radio"!==r&&i.checked,focus:o===e,changed:!0,show:!0,disable:i.disable}}else o===e?(t[o].changed=!0,t[o].focus=!0):o!==e&&I(t[o].focus)&&(t[o].changed=!0,t[o].focus=!1)}}(),function(){const{drawData:e,renderInfo:t,focus:n}=pn,{renderRows:r}=t,o=e.length;if(o===r)return void e.forEach(e=>e.show=!0);const i=o-1,s=Math.floor((r-1)/2);let a=1&r?n-s:n-s-1;a=a<0?0:a;let c=r+a-1;c>i&&(c=i,a=c-r+1);e.forEach(e=>{const{index:t}=e;t>c||t<a?e.show=!1:t===c&&t!==i||t===a&&0!==t?(e.show=!0,e.text=Yt):e.text===Yt?(e.show=!0,e.text=bn(t)):e.show=!0})}();const{info:e,mustInfo:t,renderInfo:n,focus:r,data:o}=pn,{rows:i,allowBelow:s,size:a}=n,{width:c}=a;let l=`${V}${c}D`;l+="\n".repeat(i),l+=`${V}${i}A`,l+=`${V}J`,l+=De(`${Qt()} ${e} \n\n`),l+=function(){const{drawData:e,kind:t}=pn;let n="";for(let r=0,o=e.length;r<o;r++){const o=e[r];o.show&&(o.focus?(n+=De(` ${"radio"===t?tn():o.checked?sn():rn()} ${o.text}`),n+="\n"):o.text===Yt?(n+=` ${Yt}`,n+="\n"):o.disable?(n+=De(` ${"radio"===t?Kt`⊗`:o.checked?Kt`▣`:Kt`☒`} ${Kt(o.text)}`),n+="\n"):(n+=De(` ${"radio"===t?en():o.checked?on():nn()} ${Jt(o.text||"")}`),n+="\n"))}return n}(),l+=`${V}J`,s&&(t?l+=function(){const e=process.stdout.columns-7;pn.mustInfo=!1;const t="抱歉,该项至少选择一项!!!请使用空格键或是左右键切换选择状态",n=Re(t)<e?t:Me(t,e);return"\n".concat(le(n))}():o[r].tip?(l+="\n",l+=De(`${ge(o[r].tip)}`)):l+="\n",l+="\n"),St&&(l+=`${V}${c}D${V}${i}A`),rt(l,!1)},wn=W(mn,66),yn=W(mn,600);function vn(){const{data:e,renderInfo:t,maxRows:n}=pn,[r,o]=[process.stdout.columns,process.stdout.rows],i=e.length;t.size={width:r,height:o};const s=t.rows=Math.max(Math.min(i+4,un(!1),n),5),a=t.allowBelow=un()>e.length||s>6,c=t.otherInfoRows=a?4:2;t.renderRows=s-c}async function xn(){const{data:e,required:t,kind:n,drawData:r,canCtrlCExit:o,canCtrlDExit:i}=pn,s={exit:!1};return await nt((a,c)=>{const{focus:l}=pn;switch(c.name){case"return":return Tt("用户已选择,返回真值告诉等待程序可终结当前输入"),"check"!==n||!t||!N(r.filter(e=>e.checked))||(pn.mustInfo=!0,wn(),!1);case"up":Tt("用户使用了键盘键的 up 键"),kn(!1),wn();break;case"down":Tt("用户使用了键盘键的 down 键"),kn(),wn();break;case"right":Tt("用户使用了键盘键的右键");case"left":Tt("用户使用了键盘键的左键");case"space":Tt("用户使用了键盘键的空格键"),"check"===n&&(e[l].checked=r[l].checked=!r[l].checked,wn());break;case"escape":if(c?.sequence===z.repeat(2))return s.exit=!0,!0;break;default:if(Tt("用户使用了键盘键的非方向键 <",a,">, <",c,">"),I(c?.ctrl)&&("check"===pn.kind&&("a"===c?.name&&($n(),wn()),"z"===c?.name&&($n(!1),wn()),"r"===c?.name&&(pn.data.forEach(e=>{e.disable||(e.checked=!e.checked)}),pn.drawData.forEach(e=>{e.disable||(e.checked=!e.checked)}),wn())),I(o)&&"c"===c?.name||I(i)&&"d"===c?.name))return s.exit=!0,!0}return!1}),s.exit}function $n(e=!0){pn.data.forEach(t=>{t.disable||(t.checked=e)}),pn.drawData.forEach(t=>{t.disable||(t.checked=e)})}function kn(e=!0){const{focus:t,drawData:n}=pn,r=n.length-1,o=e?t===r?n:[...n.slice(t+1),...n.slice(0,t+1)]:0===t?n.toReversed():[...n.slice(t),...n.slice(0,t)].toReversed();for(const e of o)if(!e.disable)return void(pn.focus=e.index)}async function En(e,t){const n=Symbol("selection");return new Promise((r,o)=>{ln.on(n,async()=>{try{const o=await async function(e,t){if(process.stdout.removeListener("resize",Cn),process.stdout.on("resize",Cn),pn.initData(e))return;it(),Tt("初始绘制问题选项"),vn(),wn(),Tt("绘制完成,等待用户操作");const n=await xn();rt(J,!1),process.stdout.removeListener("resize",Cn);const{resultText:r,info:o,focus:i,kind:s,drawData:a,errorText:c}=pn;if(st(),at(!0),n)return void(pn.private||an(c||r||o));const l=a.filter(e=>e.checked);if(!pn.private){const e="radio"===s?[a[i].text]:l.map(e=>e.text);cn(`${Ht.italic.dim(r||o)}: ${Ht(e.join("、"))}`)}const u="radio"===s?pn.data[i].value:l.map(e=>pn.data[e.index].value),f="radio"===s?i:l.map(e=>e.index),h="string"==t||S(t)?u:f;return h}(e,t);ln.remove(n),r(o)}catch(e){Tt.error(e),ln.remove(n),o()}})})}const Cn=W(()=>{const{drawData:e,renderInfo:t}=pn,n=t.size.height;e.length=0,rt(J,!1),at(),vn(),process.stdout.rows!==n?yn():wn()},33);function In(e,t){return En(e,t)}const On={data:"",kind:0,multi:!1,progressCount:0,indexOfCursor:0,init:function(e){this.data=e,this.multi=R(e)}},Tn={get kind(){return On.kind},set kind(e){(!isFinite(e)||0!=e&&1!=e)&&(e=0),On.kind=e},get multi(){return On.multi},enterText:[],get progressCount(){return On.progressCount},set progressCount(e){On.progressCount=e,e<0&&Reflect.apply(Sn,this,[])},get indexOfCursor(){return On.indexOfCursor},set indexOfCursor(e){On.indexOfCursor=e},currentIssue:{text:"请更换为你自己的问题",tip:"",type:"text",private:!0,errorText:"",resultText:"",required:!0,defaultValue:"",mustInfo:!1,canCtrlCExit:!1,canCtrlDExit:!1,isWrapLine:!1,usableLength:0,mustInfoLen:0,row:0,cum:0,maxLen:0,minLen:0,len:0,verify:[]},results:[],assign(e){Object.keys(e).forEach(t=>{if(!Object.hasOwn(this,t)||S(e[t]))throw rt(`${t} is not exist`),new Error(`${t} is not exist`);this[t]=e[t]})},beforeStart(){this.results.length=this.enterText.length=this.indexOfCursor=0,this.progressCount=On.multi?-On.data.length:-1}};function Sn(){const{multi:e,progressCount:t}=this,n=e&&R(On.data)?On.data[On.data.length+t]:On.data,r={text:"请更换为你自己的问题",tip:"",type:"text",private:!0,errorText:"",resultText:"",required:!0,defaultValue:"",mustInfo:!1,canCtrlCExit:!1,canCtrlDExit:!1,isWrapLine:!1,usableLength:0,mustInfoLen:0,row:0,cum:0,maxLen:0,minLen:0,len:0,verify:[]};Object.assign(r,y(n)||k(n)?{text:n}:n);const o=R(r.tip)?1:0;let i;1==o?i=[r.tip[0]]:(i=[],[r.tip,r.defaultValue].every(e=>x(e))&&(r.required=!0),!$(r.defaultValue)&&x(r.tip)&&(r.tip=r.defaultValue)),r.text=$(r.text.toString())?"请使用你自己的问题":r.text,this.assign({indexOfCursor:0,kind:o,enterText:i,currentIssue:r})}const jn=W(()=>{const{kind:e,currentIssue:t,enterText:n}=Tn,{mustInfo:r,text:o,required:i,tip:s,verify:a}=t;it();let c="",l=!1;if(E(t.row)||(c+=`${V}${t.row}A`,t.row=0),c+=`\r${V}0J${J}`,r)c=Rn(c),l=!0;else if(!N(n)){const e=n.join("");for(const n of a)if(v(n.reg)&&y(n.info)&&[S,C].some(e=>e(n.inverse))){n.reg.lastIndex=0;const r=n.reg.test(e);if(I(n.inverse)&&I(r)||I(!n.inverse)&&O(r)){t.mustInfo=n.warn?we(n.info):n.info,c=Rn(c),l=!0;break}}}const u=0===e&&i?be.blink("*"):"";c+=`${Qt()} ${u}${o}${u}: `,t.row+=Number(t.isWrapLine),c+="\n".repeat(Number(t.isWrapLine)),E(e)?N(n)&&y(s)?x(s)?c+=Ce.dim.blink("I"):c+=" ".concat(Ut.italic.dim(s[0])).concat(Ce.dim(s.slice(1))):(c+=" ",c=function(e){const{type:t,usableLength:n}=Tn.currentIssue;e="text"===t?function(e,t){const{enterText:n,indexOfCursor:r}=Tn,o=Re(n.join(""))>t;r===n.length?(o?e=function(e,t){const{enterText:n}=Tn;return e+=Yt.concat([...Me(n.toReversed().join(""),t-3,!1)].reverse().join("")),e}(e,t):e+=n.join(""),e+=Ut.hide(" ")):o?e=function(e,t){const{indexOfCursor:n,enterText:r}=Tn,o=r.join(""),i=r.length,s=Math.floor(t/2),a=Me(o,s),c=a.length-1,l=a[c]===o[c]?c:c-1,u=Me(o,-s),f=u.length-1,h=u[f]===o[i-1-f]?i-1-f:i-f,d=r.map((e,t)=>t===n?Ut(e):e).join("");if(n>=h)e+=Yt,e+=Me(d,3-t,!1);else if(n<l)e+=Me(d,t-3,!1),e+=Yt;else{const t=s-Re(r[n])-3;e+=Yt,e+=Me(o.slice(0,n),-t,!1),e+=Ut(r[n]),e+=Me(o.slice(n+1),t,!1),e+=Yt}return e}(e,t):e+=`${n.map((e,t)=>t===r?Ut(e):e).join("")}`;return e}(e,n):function(e){const{enterText:t,indexOfCursor:n}=Tn;n===t.length?(e+=` ${t.map(()=>"*").join("")}`,e+=Ut.hide("1")):e+=` ${t.map((e,t)=>t===n?Ut("*"):"*").join("")}`;return e}(e);return e}(c)):c=function(e){const{currentIssue:t,enterText:n}=Tn;return e+t.tip.map(e=>e===n[0]?Ie.bold.blink.cyan(e):de(e)).join(" ")}(c),Tt("计算完成的文本为",c),rt(De(c)),t.row++,function(e){const{currentIssue:t,indexOfCursor:n,enterText:r}=Tn,{text:o,required:i,mustInfoLen:s}=t;if(e)return ut(s);const a=r.slice(0,n).join(""),c=o.toString().concat(a),l=Re(c),u=l+7+2*Number(i),f=u%process.stdout.columns;Tt("用户输入",r.join("")),Tt("光标所在的位置",n),Tt("实际参与计算的用户输入的文本为",a),Tt("计算总文本",c),Tt("计算文本长度",l),Tt("计算可用长度",u),Tt("屏幕宽",process.stdout.columns),Tt("光标偏移量",u%process.stdout.columns),ut(f)}(l),l||rt(Oe("I"),!1),ot("8m")},66);function Rn(e){const{currentIssue:t}=Tn;e+="\n\r",t.row++;let n="";if(C(t.mustInfo)){const e=t.required?" ":"";n+=" ".repeat(2).concat(e).concat(le(t.text)).concat(e).concat(" ".repeat(3)),n+=le.blink`👆`}else n+=de(t.mustInfo);let r=Re(n);const o=process.stderr.columns-4;return o<r&&(r=o,n=Me(n,o)),t.mustInfoLen=r,e+=n,e+=`\r${V}1A`,t.row--,t.mustInfo=!1,e}function Nn(){const{currentIssue:e}=Tn;!function(){const{currentIssue:e}=Tn,t=process.stdout.columns;let n=t-Re(e.text.toString())-2*Number(e.required)-4-7;const r=n<5;r&&(n=t-4);e.isWrapLine=r,e.usableLength=n}();const{isWrapLine:t}=e,n=2+Number(t);rt("\n".repeat(n),!1),e.row+=n,ct(n),e.row-=n}async function Mn(){try{await nt((e=this,(t,n)=>{const{kind:r,currentIssue:o,enterText:i,results:s}=e,{tip:a,text:c,canCtrlCExit:l,canCtrlDExit:u}=o;let f=[],h=0,d=0,g=!0;switch(E(r)||(f=a,h=f.length-1,d=f.indexOf(i[0])),Tt("\n 用户使用了",t,n),n.name){case"return":if(function(){const{enterText:e,currentIssue:t,results:n}=Tn,r=t.text;let o=e.join("").trim();if(x(o)&&t.required)return t.mustInfo=!0,!1;const{len:i,minLen:s,maxLen:a,verify:c}=t,l=o.length;if(E(Tn.kind)){if(c.length>0)for(const e of c)if([S,O].some(t=>t(e.warn))&&v(e.reg)&&y(e.info)&&[S,C].some(t=>t(e.inverse))){e.reg.lastIndex=0;const t=e.reg.test(o);if(I(e.inverse)&&t||!e.inverse&&!t)return!1}if(!E(i)&&l!==i)return t.mustInfo=`您输入的长度 ${ue(l)} 不符合要求值 ${ge(i)}`,!1;if(!E(s)&&l<s)return t.mustInfo=`您输入的长度 ${ue(l)} 小于最低要求${ge(s)}`,!1;if(a>s&&l>a)return t.mustInfo=`您输入的长度 ${ue(l)} 大于最低要求${ge(a)}`,!1}return x(o)&&O(t.required)&&(o=t.defaultValue||t.tip||""),n.push({q:r,r:o}),!0}())return g=!1,!0;break;case"left":!function(e,t,n){const{kind:r,enterText:o}=Tn;E(r)?Tn.indexOfCursor=0===Tn.indexOfCursor?o.length:Tn.indexOfCursor-1:o[0]=e[0===t?n:t-1]}(f,d,h);break;case"right":!function(e,t,n){const{kind:r,enterText:o}=Tn;E(r)?Tn.indexOfCursor=Tn.indexOfCursor==Tn.enterText.length?0:Tn.indexOfCursor+1:o[0]=e[t==n?0:t+1]}(f,d,h);break;case"delete":case"backspace":!function(){const{enterText:e,kind:t}=Tn;E(t)&&!E(Tn.indexOfCursor)&&(e.splice(Tn.indexOfCursor-1,1),Tn.indexOfCursor--)}();break;case"escape":if(n?.sequence===z.repeat(2))return s.push({q:c,r:void 0}),g=!1,!0;break;default:if(Tt("[0m当前触发为含 ctrl 键的功能键",t,n),O(n?.ctrl))!function(e){const{enterText:t,kind:n}=Tn;S(e)||0!==n||(Tn.indexOfCursor==t.length?t.push(e):t.splice(Tn.indexOfCursor,0,e),Tn.indexOfCursor+=1)}(t);else if(g=!1,ot("m"),I(l)&&"c"===n?.name||I(u)&&"d"===n?.name)return s.push({q:c,r:void 0}),!0}return g&&jn(),!1}))}catch(e){Tt.error("接收用户输入出错",e),rt(e)}var e}function Dn(e,t){const n=Symbol("question");try{return new Promise((r,o)=>{ln.on(n,async()=>{try{const o=await async function(e,t){process.stdout.removeListener("resize",Ln),process.stdout.on("resize",Ln),Tt("初始化问题"),On.init(e),Tt("初始化当前问题"),Tn.beforeStart(),Tt("开始绘制问题");do{Nn(),jn();try{await Reflect.apply(Mn,Tn,[])}catch(e){Tt.error(e)}const{currentIssue:e,results:t}=Tn;E(e.row)||(ct(e.row,!0),e.row=0),ot("m"),st(),at(!0);const n=e.resultText||e.text,r=t[t.length-1].r;e.private||(S(r)?an(e.errorText||n):cn(`${Ht(n)}: ${"text"===e.type?r:r.replace(/./gm,"*")}`)),++Tn.progressCount}while(Tn.progressCount<0);return process.stdout.removeListener("resize",Ln),ot("m"),st(),at(!0),Tn.multi?I(t)&&R(e)?Tn.results.map(e=>e.r):Tn.results:Tn.results[0].r}(e,t);ln.remove(n),r(o)}catch(e){Tt.error("\n\n\n\n\n执行出现错误",e),ln.remove(n),o(e)}})})}catch(e){return Tt.error("系统故障",e),rt("系统故障",!1),rt(e),new Promise((t,n)=>{n(e)})}}const Ln=W(()=>{const{currentIssue:e}=Tn;E(e.row)||(ct(e.row,!0),e.row=0),rt(J,!1),at(!0),Nn(),jn()}),Bn=async function(e,t){return Dn(e,t)},Pn=new Pe({name:"qqi",type:!1});O(Pn.type);const Fn=new class{#c;#l;constructor(e=""){if(y(e)||(e=`${e}`),this.#c=Symbol(e),Ot[this.#c])throw new Error(`${e} 已经存在,请更换初始化命令名称,若仍想在原命令上操作,请抽离为单独的文件做数据共享`);this.#l=Ot[this.#c]=Nt(),[this.#l.__filename]=Ye(),this.#l.name=e||y(process.argv[1])&&process.argv.slice(1,2)[0].replace(/.*\/.*?$/,"$1")||"",Object.defineProperty(this,"#uniKey",{value:this.#c,writable:!1,enumerable:!1,configurable:!1})}get name(){return this.#l.name}get state(){return this.#l.state}isEnd(e=!1){const t=4===this.#l.state.code;return t&&I(e)&&this.end(),t}end(){return this.#l.state="end",process.exit()}error(){return this.#l.state="error",process.exit(1)}bind(e){return Rt(e,this.#l),this}run(){const e=this.#l;return zt(e),$(e.helpInfo)||Dt(e),e.hasShowVersion&&Vt(e),this}get args(){return this.#l.args}get values(){return this.#l.values.slice()}help(e,t){const n=this.#l;y(e)&&n.originalBind[e]?y(t)&&n.originalBind[e].options&&n.originalBind[e].options[t]?n.helpInfo=[e,t]:n.helpInfo=e:n.helpInfo="help",Dt(this.#l)}version(){Vt(this.#l)}}("nry");async function Wn(e="好的,即将退出"){return $(e)||await kt(e),st(),Fn.end()}function An(e){return e.endsWith("/")?e:e+"/"}async function qn(e){return new Promise(t=>{let n;try{return n=new URL(e),t(!0)}catch{return We.error("当前传入的",e,"有误"),t(!1)}})}Fn.bind(["add <a> (用于添加一个自定义的 npm、yarn、pnpm 源)","edit <ed> (用于编辑源) ",Ae?"":"clean (移除本地数据)","delete <del> (用于移除某个或多个自定义的项)","list <ls> (用于展示当前的所有的源)","manage <mg> (用于管理当前源在列表中的显隐)",`reset <rs> (重制当前的源,将${be`永久移除自定义源`}、${ye`恢复已更改的源`})`]).run().isEnd(!0);const _n={npm:"https://registry.npmjs.org/","tao-bao":"https://registry.npmmirror.com/","ten-xun":"https://mirrors.tencent.com/npm/",ustclug:"https://npmreg.proxy.ustclug.org/",yarn:"https://registry.yarnpkg.com/"},{npm:zn,"tao-bao":Vn,"ten-xun":Gn,ustclug:Jn,yarn:Hn}=_n,Kn=[{value:zn,label:"官方",tip:zn},{value:Vn,label:"淘宝",tip:Vn},{value:Gn,label:"腾讯",tip:Gn},{value:Jn,label:"中科大",tip:Jn},{value:Hn,label:"yarn",tip:Hn}];function Un(e=!1){if(e)return[...Kn];if(!Qn.available)return[...Kn];const t=Qn.read();if(R(t)&&t.every(e=>y(e.value)&&!$(e.label)&&y(e.value)&&!$(e.value))){return t.map(e=>(e.value=An(e.value),e.tip=An(e.tip),e))}return[...Kn]}const Yn=new class{#u;#f=!0;get available(){return this.#f}constructor(e){const t=function(){const e=a();if(Pn("当前获取用户主目录为",e),!e||"/"===e||e.includes("Default"))throw new Error("未能获取到主目录路径 <"+e+">");try{const t=ze(e,"test_write"+Date.now());return Je(t,{}),o(t),e}catch(e){return void Pn.error(e)}}();if(S(t))return this.#f=!1,void(this.#u="");this.#f=!0,this.#u=ze(t,".earthnut.dev.data",`${e}`)}read(e){if(!this.available)return null;const t=ze(this.#u,e);return S(qe(t))?{}:Ge(t)||{}}write(e,t){if(!this.available)return!1;const n=ze(this.#u,e),r=ze(n,"../");Pn("创建的文件路径为"),i(r,{recursive:!0}),Pn("写入的文件路径为:",n),Pn("写入文件内容为",t);const o=Je(n,t);return Pn("写入反馈",o),o}getPath(e){return ze(this.#u,e)}}("nry"),Zn="config",Qn={available:Yn.available,read(){if(Yn.available){const e=Yn.read(Zn);if(R(e))return e}return Un(!0)},addNew(e){if(Yn.available){const t=this.read();return t.push(e),We("新写入的数据为",e),this.write(t)}return!1},write:e=>!!Yn.available&&Yn.write(Zn,e),getPath:()=>Yn.getPath(Zn),clean(){const e=this.getPath();We("将要移除的文件",e),o(e)}},Xn={add:!1,edit:!1,delete:!1,manage:!1,list:!1,noMatch:!1,reset:!1,clean:!1},er={pkgManager:function(e=!1){if(O(e)){const e=e=>Boolean(Ve(e,"file"));if(e("pnpm-lock.yaml"))return"pnpm";if(e("yarn.lock"))return"yarn";if(e("package-lock.json"))return"npm"}const t=process.env.npm_config_user_agent||"";return t.includes("pnpm")?"pnpm":t.includes("yarn")?"yarn":t.includes("npm")?"npm":process.env.PNPM_HOME?"pnpm":process.env.YARN_IGNORE_PATH?"yarn":"npm"}(!0)};function tr(e){if(!Qn.available)return!1;const t=An(e.value);return Qn.addNew({value:t,label:e.label.toString(),tip:t,disable:!1})}const nr=b(function(e){return this.data=[],Object.setPrototypeOf(this,e),this});function rr(e,t){if(t.align&&(e.align=t.align),t.bgColor&&(e.bgColor=t.bgColor),t.color&&(e.color=t.color),t.italic&&(e.italic=t.italic),t.underline&&(e.underline=t.underline),t.border)if(B(t.border,e=>y(e))){const n=t.border;e.border={left:{color:void 0,style:n},right:{color:void 0,style:n},top:{color:void 0,style:n},bottom:{color:void 0,style:n}}}else if(B(t.border,e=>["color","style"].some(t=>!S(e[t])))){const n=t.border,r=n.style,o=n.color||void 0;e.border=JSON.parse(JSON.stringify({left:{color:o,style:r},right:{color:o,style:r},top:{color:o,style:r},bottom:{color:o,style:r}},(e,t)=>""===t?void 0:t))}else B(t.border,e=>["left","right","top","bottom"].some(t=>!S(e[t])))&&(e.border=t.border)}class or{}function ir(e,t){R(e)&&(e={data:e});const n=new or;rr(n,e);const r=new nr(n);return Object.setPrototypeOf(n,t),e.data?.forEach(e=>{e&&r.data.push(function(e,t){if(S(e))return;B(e,e=>!M(e))&&(e={content:e});const n={content:e.content};return rr(n,e),Object.setPrototypeOf(n,t),n}(e,n))}),r}class sr extends or{border={left:{style:"bold",color:void 0},right:{style:"bold",color:void 0},top:{style:"bold",color:void 0},bottom:{style:"bold",color:void 0}}}function ar(e){const t=new sr;return Object.setPrototypeOf(t,e),t}const cr=!q(),lr={emojiLength:2.08,emojiRegex:/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}]/gu,chineseLength:1.8,chineseRegex:/[\u4E00-\u9FFF]/g};const ur=new class{align="left";color="";bgColor="";bold=!1;underline=!1;italic=!1;border={left:{color:void 0,style:"simple"},right:{color:void 0,style:"simple"},top:{color:void 0,style:"simple"},bottom:{color:void 0,style:"simple"}}},fr=b(function(e){return this.body=[],this.header=void 0,Object.setPrototypeOf(this,e),this});class hr{}function dr(e){let t=ce;return B(e)&&(e.bold&&(t=t.bold),$(e.bgColor)||S(e.bgColor)||(t=t.bgColor(e.bgColor)),$(e.color)||S(e.color)||(t=t.color(e.color)),e.italic&&(t=t.italic),e.underline&&(t=t.underline)),t}const gr={fine:{lt:"┌",ct:"┬",rt:"┐",lc:"├",c:"┼",rc:"┤",lb:"└",cb:"┴",rb:"┘",l:"─",v:"│"}};function pr(e){let t=0;return[...e].forEach(e=>{lr.emojiRegex.lastIndex=0,lr.chineseRegex.lastIndex=0,e.match(lr.emojiRegex)?t+=lr.emojiLength:e.match(lr.chineseRegex)?t+=lr.chineseLength:t++}),Math.ceil(t)}function br(e,t){const n=function(e){const t=[];return e.header&&e.header.data.forEach((e,n)=>{const r=e?.content?.toString()??"";t[n]=Math.max(t[n]??0,cr?pr(r):Re(r))}),e.body&&e.body.forEach(e=>{e.data.forEach((e,n)=>{const r=e?.content?.toString()??"";t[n]=Math.max(t[n]??0,cr?pr(r):Re(r))})}),t}(e);let r=!1,o="";e.header&&(r=!0,o+=function(e,t){let n="";const r=t.length-1,{fine:o}=gr,i=dr(e);return t.forEach((e,t)=>{0===t&&(n+=o.lt),n+=J,n+=o.l.repeat(e+2),t===r?(n+=J,n+=o.rt):(n+=J,n+=o.ct)}),n+="\n",t.forEach((t,s)=>{n+=J,n+=o.v;const a=e.data[s];if(S(a)||T(a))n+=J,n+=i(" ".repeat(t+2));else{const e=dr(a);let r=a.content?.toString()??"";r=r.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),n+=J,n+=e`\u2002${Me(r,t)}\u2002`}s===r&&(n+=o.v)}),n+="\n",n}(e.header,n)),o+=function(e,t,n){let r="";const o=t.length-1,{fine:i}=gr;return t.forEach((e,t)=>{0===t&&(r+=J,r+=n?i.lc:i.lt),r+=J,r+=i.l.repeat(e+2),t===o?(r+=J,r+=n?i.rc:i.rt):(r+=J,r+=n?i.c:i.ct)}),r+="\n",e.forEach((n,s)=>{const a=dr(n);t.forEach((e,t)=>{r+=J,r+=i.v;const s=n.data[t];if(S(s)||T(s))r+=a`${" ".repeat(e+2)}`;else{const t=dr(s);let n=s.content?.toString()||"";n=n.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),r+=J,r+=t`\u2002${Me(n,e)}\u2002`}t===o&&(r+=J,r+=i.v)}),r+="\n";const c=e.length-1===s;t.forEach((e,t)=>{0===t&&(r+=J,r+=c?i.lb:i.lc),r+=J,r+=i.l.repeat(e+2),t===o?(r+=J,r+=c?i.rb:i.rc):(r+=J,r+=c?i.cb:i.c)}),r+="\n"}),r}(e.body,n,r);const i=oe(o);if(cr){const e=i[0].split("%c"),n=i.map((n,r)=>{if(r>0){const o=[...e[r]].reduce((e,t)=>Re(t)>1?(lr.emojiRegex.lastIndex=0,t.match(lr.emojiRegex)?e-(lr.emojiLength-2):e+(2-lr.chineseLength)):e,0);return n+"font-family: Consolas,Monaco,Courier,'Courier New','等宽字体',monospace; font-size:"+t+"px;word-spacing:normal;padding:0;margin:0;padding-right:"+o*t+"px"}return n});console.log(...n)}else console.log(...i)}const mr=b(function(e){const[t,n]=function(e){S(e)&&(e={}),R(e)&&(e={body:e});const t=new hr;rr(t,e),Object.setPrototypeOf(t,ur);const n=new fr(t);return e.header&&(n.header=ir(e.header,ar(t))),e.body?.forEach(e=>n.body.push(ir(e,t))),[n,t]}(e);let r=12;const o=()=>br(t,r);return Object.setPrototypeOf(o,this),Object.defineProperties(o,{addRow:{value:e=>(t.body.push(ir(e,n)),o),configurable:!1,writable:!1,enumerable:!1},setHeader:{value:e=>(t.header=ir(e,ar(n)),o),configurable:!1,writable:!1,enumerable:!1},setFontSize:{value:e=>(r=e,o)}}),o});async function wr(){const{pkgManager:e}=er,t=`${e} config get registry`;We("执行可写代码",t);const n=await $t(t);if(We("获取当前的本地配置为",n),n.success)return n.data.replace(/\s/gm,"")}async function yr(){const{pkgManager:e}=er,t=Un(),n=await wr(),r=new mr({header:[`${e} registry 源`,"别名","当前可见"]});!(t.findIndex(e=>e.value===n)>-1)&&y(n)&&t.push({value:n,tip:n,label:"曾用值"}),t.forEach(e=>r.addRow([(n===e.value?de`* `:" ").concat(e.value),(n===e.value?de`* `:" ").concat(ue(e.label)),e.disable?"❌":"✅"])),r(),rt(pe`注:当前可见状态仅影响 npx nry 选择项`)}const{npm:vr,yarn:xr}=_n;async function $r(e){const{pkgManager:t}=er,n=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}];e.forEach(e=>{n.push({reg:new RegExp(`^${A(e.value)}/*$`,"mg"),info:`${ue(e.value)}(${ge(e.label)}) 已存在`,inverse:!0})});const r=await Bn({text:"请输入自定义的源地址",tip:"yarn"===t?xr:vr,minLen:5,maxLen:120,verify:n,required:!1});return We("用户输入的地址",r),S(r)?await Wn():await qn(r)?An(r):(rt(`当前设置 registry 「${Te(r)}」 不可用`),rt("请使用正确的源设置"),await $r(e))}async function kr(){if(!Qn.available)return await Wn("读写受限,正在退出");const{pkgManager:e}=er,t=Un(),n=await $r(t),r=await async function(e){const t=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}],{pkgManager:n}=er;e.forEach(e=>{t.push({reg:new RegExp(`^${A(e.label)}$`,"mg"),info:`${ue(e.label)}(${ge(e.value)}) 已存在`,inverse:!0})});const r=await Bn({text:`请输入自定义的 ${n} 的别名`,tip:"任意别名",minLen:1,maxLen:120,verify:t,defaultValue:"",required:!1});return We("用户输入的别名为",r),S(r)?await Wn():r}(t);if(tr({value:n,label:r})){rt(pe`当前的 ${e} registry 源列表为`),await yr();const t=["退出","继续添加"],n=await Bn({text:"添加完成,是否持续添加",tip:t});return S(n)||n===t[0]?await Wn(""):await kr()}return await Wn(`写入${be`失败`},原因未知`)}async function Er(e="",t=!0,n=!0){$(e)&&(e=`请选择想使用的新的 ${er.pkgManager} registry 源`);let r=!1;const o=Un(),i=await wr();if(!S(i)){for(const e of o)if(e.value===i){e.label=e.label.toString()+`(${de`当前使用`})`,e.disable=!n,r=!0;break}if(O(r)){const e={value:i,label:"当前使用值",disable:!n};o.push(e),Qn.available&&tr({value:i,label:"曾用值"})}}We("处理完的数据",o);const s=t?o.filter(e=>!e.disable||e.disable&&e.value===i):o.map(e=>(e.value===i?e.disable=!n:e.disable=!1,e)),a=await In({data:s,info:e},"number");return We("用户选择的项",a),S(a)?await Wn():(We("当前用户选择为",s[a]),s[a])}async function Cr(){const e=await Er();await async function(e){const{pkgManager:t}=er,n=An(e.value);if(!await qn(n))return await Wn(`选择的项 「${de(n)}」 不可连接,无法被设置`);const r=`${t} config set registry "${n}"`;We("设置源执行代码",r);(await $t(r)).success||await Wn();rt(`已将 ${t} registry 更改为 ${ue(e.value)}(${he(e.label)})`)}(e)}async function Ir(){if(!Qn.available)return await Wn("当前读写受限,即将退出程序");const e=await Er("请选择要删除的项",!1,!1),{value:t,label:n}=e,r=Un();for(const e in r){const o=Number(e),i=r[o];if(i.value===t&&i.label===n){r.splice(o,1);break}}if(Qn.write(r)){rt("删除项后的列表为:"),await yr();const e=["退出","继续删除"],t=await Bn({text:"是否继续删除其他项",tip:e});return S(t)||t===e[0]?await Wn(""):await Ir()}}async function Or(){if(!Qn.available)return await Wn("当前读写权限不足,即将退出程序");const e=await Er("请选择你想要修改的项",!1),{value:t,label:n}=e;We("获取用户的选择",e),We("原始的值",t),We("原始的标签",n),await async function(e){const{pkgManager:t}=er,n=await Bn({text:`请更改为新的 ${t} registry 值`,tip:e.value,defaultValue:e.value,required:!1});if(We("新值为",n),S(n))return;e.value=e.tip=An(n)}(e),await async function(e){const{pkgManager:t}=er,n=await Bn({text:`请更改为新的 ${t} registry 别名`,tip:e.label,defaultValue:e.label.toString(),required:!1});if(We("新值为",n),S(n))return;e.label=n}(e);const{value:r,label:o}=e;We("更改后的值",r),We("更改的标签",o);const i=Un();for(const e of i)if(e.value===t&&e.label===n){e.value=r,e.label=o.toString();break}if(Qn.write(i)){rt("更改后的列表为:"),await yr();const e=["退出","继续修改"],t=await Bn({text:"是否继续修改其他项",tip:e});return S(t)||t===e[0]?await Wn(""):await Or()}}async function Tr(){return function(){const e=Fn.args,t=e.$map;We("源解析值",e),We("源解析值没有匹配项",e.$isVoid),["add","delete","edit","list","manage","reset","clean"].forEach(e=>Xn[e]=O(S(t[e]))),Xn.noMatch=e.$isVoid,We("解析完的值",Xn)}(),We("解析参数完毕,开始执行",Xn),Xn.noMatch?(We("当前没有匹配值"),await Cr()):Xn.reset?(We("重置项"),await async function(){if(!Qn.available)return await Wn("当前读写权限受限,正在退出程序");const e=["退出","重置"],t=await Bn({text:"请确认是否执行覆盖原数据,该操作无法复原",tip:e});return S(t)||t===e[0]?await Wn("好的,这就退出重置"):Qn.write(Un(!0))?(await kt("写入"+ue`成功`,60),await yr()):await Wn("重置未能完成,原因未知")}()):Xn.list?(We("当前为展示项"),await yr()):Xn.manage?(We("当前执行状态更改"),await async function(){if(!Qn.available)return await Wn("当前读写受限,即将退出程序。");const e=Un(),t=await wr(),n=await In({data:e.map(e=>({...e,checked:!e.disable,disable:e.value===t})),kind:"check"},"number");if(We("交互结果",n),S(n))return await Wn("好的,将退出状态显隐管理");e.forEach((e,t)=>{e.disable=!n.includes(t)}),We("保存前的数据",e),Qn.write(e)&&await yr()}()):Xn.add?(We("添加新的项"),await kr()):Xn.edit?(We("编辑项"),await Or()):Xn.delete?(We("删除项"),await Ir()):Xn.clean?(We("当前执行清理"),Qn.clean()):await Cr()}(async()=>{try{await Tr()}catch(e){We.error("系统级捕获 错误",e),console.log("当前出现未知错误",e)}})();
|
|
2
|
+
import{statSync as e,readFileSync as t,readdirSync as n,writeFileSync as r,mkdirSync as o,unlinkSync as i}from"node:fs";import{homedir as s,arch as a}from"node:os";import c,{dirname as l,normalize as u,join as f,resolve as h}from"node:path";import"node:fs/promises";import{fileURLToPath as d}from"node:url";import{spawn as g}from"node:child_process";import{emitKeypressEvents as p}from"node:readline";import{resolve as b}from"node:path/posix";function m(e){return e.prototype.apply=Function.apply,e.prototype.bind=Function.bind,e.prototype.call=Function.call,e.prototype.length=Function.length,e.prototype.name=Function.name,e.prototype.toString=Function.toString,e}function w(e,t){return Object.keys(t).forEach(n=>e[n]=t[n]),e}function y(e){const t=typeof e;if("object"!==t&&"function"!==t)return t;const n=Reflect.apply(Object.prototype.toString,e,[]).replace(/^.*\s(.*)]$/,"$1").toLowerCase();return"error"!==n?n:e instanceof SyntaxError?"syntaxerror":e instanceof TypeError?"typeerror":e instanceof URIError?"urierror":e instanceof ReferenceError?"referenceerror":e instanceof AggregateError?"aggregateerror":e instanceof RangeError?"rangeerror":e instanceof EvalError?"evalerror":"error"}function v(e){return"string"===y(e)}function x(e){return"regexp"===y(e)}function $(e){return v(e)&&""===e.valueOf()}function k(e){return v(e)&&""===e.valueOf().trim()}function E(e){return"number"===y(e)}function I(e){return 0===e}function C(e){return"boolean"===y(e)}function T(e){return!0===e}function O(e){return!1===e}function S(e){return null===e}function j(e){return void 0===e}function R(e){return"function"===y(e)}function N(e){return Array.isArray(e)}function M(e){if(N(e))return 0===e.length;throw new TypeError("参数必须为数组")}function L(e){return"object"===y(e)}function D(e){return L(e)&&0===Reflect.ownKeys(e).length}function B(e){return"symbol"===y(e)}function P(e,t){return void 0===t||("function"==typeof t?t(e):t)}function F(e=1,t=0){if(!isFinite(e)||!isFinite(t)||isNaN(e)||isNaN(t)||!E(e)||!E(t))throw new TypeError("getRandomInt: max or min is NaN or is not a number");let n=Math.ceil(Number(t)),r=Math.floor(Number(e));return r===n?r:(n>r&&([r,n]=[n,r]),Math.round(Math.random()*(r-n)+n))}function A(e){if(!L(e)&&!E(e)||E(e)&&isNaN(e)||E(e)&&!isFinite(e)||E(e)&&!Number.isInteger(e)||E(e)&&Number.isInteger(e)&&e<1||E(e)&&e<1||L(e)&&(!E(e.length)||e.length<1||!Number.isInteger(e.length)))throw new TypeError("参数类型错误 ❌ (getRandomString)");const t={length:32,chars:"abcdefghijklmnopqrstuvwxyz",chars2:"0123456789",chars3:"!@#$%^&*()_+~`|}{[]:;?><,./-=",type:"string",includeUppercaseLetters:!1,includeNumbers:!1,includeSpecial:!1};if("uuid"===t.type)return crypto.randomUUID();E(e)&&Number.isInteger(e)&&e>0&&w(t,{length:e}),L(e)&&(w(t,e),t.length=t.length<1?32:t.length);const n=t.chars.split("");t.includeUppercaseLetters&&s(n,t.chars.toUpperCase()),t.includeNumbers&&s(n,t.chars2),t.includeSpecial&&s(n,t.chars3);let r="";const o=n.join(""),i=o.length;if(globalThis&&globalThis.crypto&&globalThis.crypto.getRandomValues){globalThis.crypto.getRandomValues(new Uint8Array(t.length)).forEach(e=>r+=o[e%i])}else for(let e=0;e<t.length;e++)r+=o[F(i-1)];function s(e,t){const n=e.length,r=t.length,o=Math.max(n,r);for(let i=0;i<o;i++)i<n&&!j(t[i])?e[i]+=t[i]:i<r&&(e[i]=t[i])}if(!/[a-zA-Z]/.test(r))return String.fromCharCode(F(97,122)).concat(r.slice(1));for(;!/^[a-zA-Z]$/.test(r[0]);)r=r.slice(1)+r[0];return r}function W(e,t=200){if(!R(e))throw new TypeError("callback must be a function");let n;E(t)&&(t={delay:t,this:null}),(j(t.delay)||!isFinite(t.delay)||t.delay<0)&&(t.delay=200);const r=()=>{n&&(clearTimeout(n),n=void 0)},o=(...o)=>{r(),n=setTimeout(()=>{try{const n=t&&t.this?t.this:null;e.apply(n,o)}catch(e){console.log("Debounce callback throw an error",e)}},Math.max(t.delay||5,5))};return o.cancel=()=>r(),o}function _(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(e,t){if(!v(e))throw new TypeError("pattern must be a 字符串");return e=_(e),j(t)?new RegExp(e):(t=function(e){if(v(e)&&(e={flags:e}),v(e.flags)){const t=/[migsuy]/g,n=e.flags.match(t);S(n)?e.flags="":e.flags=[...new Set(n)].join("")}else e.flags="";return e}(t),new RegExp(`${t.start?"^":""}${e}${t.end?"$":""}`,t.flags))}function z(){return!j(globalThis&&globalThis.process&&globalThis.process.versions&&globalThis.process.versions.node||void 0)}async function V(e=1e3){if(!isFinite(e)||e<4)throw new TypeError("delay 应该是一个正常的数值");return I(e)?Promise.resolve():new Promise(t=>setTimeout(t,e))}const G="",J=`${G}[`;function H(){return new RegExp(`(\\x1b\\[(${["([1-4]?[0-9])(;([1-4]?[0-9]+))*m","[m]","\\?(25|7)[hl]","\\d*;?\\d*[HFr]","6n","\\d{0,4}[A-DTS]","[0-3]?[JKg]","[0-6]?W"].map(e=>`(${e})`).join("|")}))`.concat("|(\\x1b[78DMc])"),"g")}const K=`${J}0m`;function U(e,t=!0){if(T(t)){if(!v(e))throw new TypeError("`color` must be a string or number but not number[] when isHex is true");if(e.startsWith("0x"))e=e.replace(/0x/,"#");else if(!e.startsWith("#"))throw new TypeError("`color` must be a string or number but not number[] when isHex is true")}else{if(!O(t))throw new TypeError("The second variable `isHex` must be boolean");if(N(e)){if(e.some(e=>!isFinite(e))||3!==e.length)throw new TypeError("If the `color` is an array, it must be 3 in length and be of numeric type");e=`rgb(${e.join(",")})`}else{if(E(e))throw new TypeError("If the `color` is not number when isHex is false");if(v(e)){if(!e.startsWith("rgb(")||!e.endsWith(")"))throw new TypeError("If the `color` is a string, it must be rgb(r, g, b)");{const t=e.replace(/.*\((.*)\).*/,"$1").split(",");if(3!==t.length||t.some(e=>!isFinite(Number(e))||Number(e)<0||Number(e)>255))throw new TypeError("If the `color` is a string, it must be rgb(r, g, b)")}}}}let n=0,r=0,o=0;if(e.startsWith("#"))if(6==(e=e.slice(1)).length)n=Y(parseInt(e.slice(0,2),16)),r=Y(parseInt(e.slice(2,4),16)),o=Y(parseInt(e.slice(4,6),16));else{if(3!=e.length)return F(255);n=Y(parseInt(e.slice(0,1).repeat(2),16)),r=Y(parseInt(e.slice(1,2).repeat(2),16)),o=Y(parseInt(e.slice(2,3).repeat(2),16))}else if(e.startsWith("rgb")){const t=e.replace(/.*\((.*)\).*/,"$1").split(",");n=Y(Number(t[0])),r=Y(Number(t[1])),o=Y(Number(t[2]))}return 16+36*n+6*r+o}function Y(e){const t=isFinite(e)?Math.floor(6*e/256):F(6);return Math.min(5,Math.max(0,t))}function Z(e,t,n,r=!0){const o=r?"38":"48";if(E(e)&&E(t)&&E(n))return`${o};5;${U([e,t,n],!1)}`;if(v(e)&&j(t)&&j(n)){if(e.startsWith("rgb"))return`${o};5;${U(e,!1)}`;if(e.startsWith("#")||e.startsWith("0x"))return`${o};5;${U(e,!0)}`;Q()}else{if(E(e)&&j(t)&&j(n))return`${o};5;${U(e,!0)}`;Q()}}function Q(){throw new TypeError(' 使用 color() 或 bgColor() 时,可使用三整数 `r , g , b` 或单字符串 `"rgb(r , g, b)"` 或十六进制数值 `0xrgb`、`0xrrggbb` 或十六进制字符串表达 `"#rgb"`、`"#rrggbb"` ,不接受其他格式的参数')}function X(e,t=!0){try{return Z(e,void 0,void 0,t)}catch(e){throw console.error(e),new TypeError('使用 hex() 或 bgHex() 时,参数可以为单字符串 `"0xnnnnnn"`、`"#rgb"` 、`"#rrggbb"` 或一个数值 `0xrrggbb`。不接受其他格式')}}function ee(e,t=!1){return e<0&&(e=0),e>255&&(e=255),e=isFinite(e)?Math.round(e):F(255),`${[48,38][Number(t)]};5;${e}`}function te(e,t,n,r=!0){try{return Z(e,t,n,r)}catch(e){throw console.error(e),new TypeError('使用 rgb() 或 bgRgb() 时,参数可以为单字符串 `"rgb(r, g, b)"` 或三个数值 `r , g ,b`。不接受其他格式')}}const ne={black:"38;5;0",red:"38;5;1",green:"38;5;2",yellow:"38;5;3",blue:"38;5;4",magenta:"38;5;5",cyan:"38;5;6",white:"38;5;7",brightBlack:"38;5;8",brightRed:"38;5;9",brightGreen:"38;5;10",brightYellow:"38;5;11",brightBlue:"38;5;12",brightMagenta:"38;5;13",brightCyan:"38;5;14",brightWhite:"38;5;15",bgBlack:"48;5;0",bgRed:"48;5;1",bgGreen:"48;5;2",bgYellow:"48;5;3",bgBlue:"48;5;4",bgMagenta:"48;5;5",bgCyan:"48;5;6",bgWhite:"48;5;7",bgBrightBlack:"48;5;8",bgBrightRed:"48;5;9",bgBrightGreen:"48;5;10",bgBrightYellow:"48;5;11",bgBrightBlue:"48;5;12",bgBrightMagenta:"48;5;13",bgBrightCyan:"48;5;14",bgBrightWhite:"48;5;15",bold:"1",dim:"2",italic:"3",underline:"4",blink:"5",reversed:"7",hide:"8",random:"random",bgRandom:"bgRandom",rgb:(e,t,n)=>te(e,t,n),hex:e=>X(e),color:(e,t,n)=>Z(e,t,n),number:e=>ee(e,!0),bgRgb:(e,t,n)=>te(e,t,n,!1),bgHex:e=>X(e,!1),bgColor:(e,t,n)=>Z(e,t,n,!1),bgNumber:e=>ee(e)};Object.freeze(ne);const re=["#000000","#c23621","#25bc24","#adad29","#492ee1","#dd38dd","#33bbc8","#cbcccd","#818383","#fc391f","#31e722","#eaec23","#5833ff","#f93578","#14f0f0","#ebeded"];function oe(e){let t=Number(e);if(!isFinite(t))throw new TypeError("色值反向解析出错");if(t<16){return re[t]}const n=e=>Math.floor(256*e/6+F(42)).toString(16).padStart(2,"0");t-=16;const r=t%36;return`#${n(Math.floor(t/36))}${n(Math.floor(r/6))}${n(r%6)}`}class ie{constructor(e){this.parse(e),this.build()}build(){this.hide&&(this.color="transparent"),this.reversed&&([this.color,this.bgColor]=[this.bgColor,this.color]),j(this.color)||(this.str+=`color: ${this.color};`),j(this.bgColor)||(this.str+=`background: ${this.bgColor};`),0!==this.bold&&(this.str+=`font-weight: ${1===this.bold?800:200};`),this.italic&&(this.str+="font-style: italic;"),this.underline&&(this.str+="border-bottom: 1px #666 solid;")}color=void 0;bgColor=void 0;bold=0;italic=!1;underline=!1;reversed=!1;hide=!1;str="";parse(e){e.replace(/38;5;(\d+)/g,"c-$1").replace(/48;5;(\d+)/g,"b-$1").split(";").reverse().forEach(e=>{0===this.bold&&e===ne.bold?this.bold=1:0===this.bold&&e===ne.dim?this.bold=-1:e===ne.italic?this.italic=!0:e===ne.underline?this.underline=!0:e===ne.reversed?this.reversed=!0:e===ne.hide?this.hide=!0:j(this.color)&&e.startsWith("c")?this.color=oe(e.split("-")[1]):j(this.bgColor)&&e.startsWith("b")&&(this.bgColor=oe(e.split("-")[1]))})}}function se(e){return z()?[e]:function(e){e=e.replace(new RegExp("\\\\[0m","g"),"[m");const t=H(),n=[""];let r,o=0,i="";const s=()=>{const t=e.substring(o,r?.index??e.length);n[0]+="%c".concat(t),n.push(i)};for(;!S(r=t.exec(e));)s(),i=j(r[7])?new ie(r[3].slice(0,-1)).str:"",o=t.lastIndex;return s(),n}(e)}function ae(e,t){if($(e=S(e)||j(e)?"":e.toString()))return"";if(M(t))return e;const n=e.indexOf(J),r=e.indexOf(`${J}0m`);return t=function(e){return e.map(e=>"random"===e?`38;5;${F(255)}`:"bgRandom"===e?`48;5;${F(255)}`:e)}(t),n>-1&&r>-1?ae(e.substring(0,n),t).concat(e.substring(n,r+4)).concat(ae(e.substring(r+4),t)):e.endsWith("\r\n")?(e=e.substring(0,e.length-2),`${J}${t.join(";")}m${e}${J}0m\r\n`):e.endsWith("\n")?(e=e.substring(0,e.length-1),`${J}${t.join(";")}m${e}${J}0m\n`):`${J}${t.join(";")}m${e}${J}0m`}function ce(e,t){const n=parseInt(t);if(n>10){const r=T(38===n)?"38;5;":"48;5;",o=e.findIndex(e=>e.startsWith(r));return o>-1?e.toSpliced(o,1,t):[...e,t]}return e.includes(t)?[...e]:[...e,t]}const le=m(function(e=[]){const t=(t,...n)=>{if(P(t,()=>N(t)&&t.every(e=>v(e)))){let r="";for(let o=0;o<t.length;o++)r+=ae(t[o],e),o<n.length&&(r+=ae(n[o],e));return r}if(M(n))return ae(t,e);throw new Error("pen: 缺少参数")},n=Object.keys(ne).map(t=>[t,{get:()=>function(e,t){let n=[];if(P(e,v(ne[e])))return n=ce(t,ne[e]),new le(n);if("hex"===e||"bgHex"===e)return r=>(n=ce(t,ne[e](r)),new le(n));if("rgb"===e||"bgRgb"===e)return(r,o,i)=>{if(v(r)&&j(o)&&j(i))n=ce(t,ne[e](r));else{if(!(E(r)&&E(o)&&E(i)))throw new Error(`${e} 的参数类型不正确,请使用 'rgb' 或 'hex' 函数`);n=ce(t,ne[e](r,o,i))}return new le(n)};if("color"===e||"bgColor"===e)return(r,o,i)=>{if(v(r)&&j(o)&&j(i))n=ce(t,ne[e](r));else{if(!(E(r)&&E(o)&&E(i)))throw new Error(`${e} 的参数类型不正确,请使用 'rgb' 或 'hex' 函数`);n=ce(t,ne[e](r,o,i))}return new le(n)};if("number"===e||"bgNumber"===e)return r=>{if(E(r))return n=ce(t,ne[e](r)),new le(n);throw new TypeError(`${e} 的参数应为有效正整数数值,范围 0 - 255`)};throw new Error(`${e} 函数不存在`)}(t,e)}]),r=Object.fromEntries(n);return Object.defineProperties(t,r),t});const ue=new le([]),fe=new le([ne.red]),he=new le([ne.green]),de=new le([ne.yellow]),ge=new le([ne.blue]),pe=new le([ne.magenta]),be=new le([ne.cyan]);new le([ne.white]);const me=new le([ne.brightBlack]),we=new le([ne.brightRed]),ye=new le([ne.brightGreen]),ve=new le([ne.brightYellow]);new le([ne.brightBlue]);new le([ne.brightMagenta]);const xe=new le([ne.brightCyan]);new le([ne.brightWhite]);const $e=new le([ne.bgBlack]);new le([ne.bgRed]),new le([ne.bgGreen]),new le([ne.bgYellow]),new le([ne.bgBlue]),new le([ne.bgMagenta]);const ke=new le([ne.bgCyan]);new le([ne.bgWhite]),new le([ne.bgBrightBlack]),new le([ne.bgBrightRed]),new le([ne.bgBrightGreen]);const Ee=new le([ne.bgBrightYellow]);new le([ne.bgBrightBlue]);const Ie=new le([ne.bgBrightMagenta]);new le([ne.bgBrightCyan]),new le([ne.bgBrightWhite]);const Ce=new le([ne.bold]),Te=new le([ne.italic]),Oe=new le([ne.underline]),Se=new le([ne.hide]);new le([ne.dim]),new le([ne.blink]);const je=new le([ne.reversed]);ue.rgb;const Re=ue.hex;ue.color,ue.bgRgb;const Ne=ue.bgHex;function Me(e){const t=H(),n=e.replace(t,"");let r=0;for(let e=0,t=n.length;e<t;e++)r+=1+Number(Le(n[e]));return r}function Le(e){const t=e.codePointAt(0)||0;return t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=191471||t>=63744&&t<=64255||t>=65280&&t<=65519||t>=65381&&t<=65439||t>=127744&&t<=129750||t>=128512&&t<=128591||t>=128640&&t<=128767||t>=9728&&t<=9983||t>=9984&&t<=10175||t>=44032&&t<=55215||t>=12288&&t<=12351}function De(e,t,n=!0){const r=t,o=e;if(0===r)return"";let i=!1;const s=Me(o);if(s<=r)return o.concat(" ".repeat(r-s));const a=r>0,c=H();c.lastIndex=0;const l=[...o.replaceAll(c,"")],u=a?l:l.reverse(),f=u.length,h=Math.abs(r);let d=Math.floor(h/2),g=u.slice(0,d).join(""),p=Me(g);for(;d<f;){if(p+=Me(u[d]),p===h){g+=u[d];break}if(p===h+1){n&&(i=!0);break}if(p>h+1)break;g+=u[d],d++}if(a&&o.startsWith(g)||!a&&o.endsWith(g=[...g].reverse().join("")))return i?g+" ":g;if(a){let e;for(c.lastIndex=0;null!==(e=c.exec(o));){const t=g;if(g=t.slice(0,e.index).concat(e[0]).concat(t.slice(e.index)),o.startsWith(g))break}g+=K}else{const e=[...g];let t=e.length-1;g="";const n=[...o].reverse();for(let r=0,o=n.length;r<o;r++){const o=n[r];if(o===e[t])--t;else if(t<0)break;g=o+g}g=K+g}return i?g+" ":g}function Be(e){return`${J}?7l${e.toString()}${J}?7h`}ue.bgColor,ue.random,ue.bgRandom,ue.number,ue.bgNumber;const Pe=[!1,!0,"all","info","error","warn"];const Fe=z()?"node":"browser";const Ae=m(We);function We(e){const t=function(e){const t={name:A(10),type:!1,fold:!1};return j(e)?t:C(e)?(t.type=e,t):v(e)?(t.name=e.trim().replace(/\s+/g,"_"),t):(v(e.name)&&(e.name=e.name.trim().replace(/\s+/g,"_")),e.fold=Boolean(e.fold),e)}(e);this.name=t.name||A(12),this.fold=Boolean(t.fold);const n=function(e=A(10)){let t=!1;if("node"===Fe&&globalThis?.process?.env){const n=process.env;t=n[e.toUpperCase().concat("_DEV")]||n[e.toLowerCase().concat("_dev")]||!1}return"false"!==t&&("true"===t||t)}(this.name);let r=t.type||!1;this.mark="",this.type="node"!==Fe||function(e){return!!Pe.includes(e)&&e}(n??r);const o=e=>{try{throw new Error}catch(t){const n=(t.stack?.split("\n")||[]).map(e=>{const t=/at\s(.*)\s\((.*):(\d*):(\d*)\)/.exec(e);return t?{name:t[1],path:t[2],line:t[3],column:t[4]}:{name:""}}),r=n.filter(e=>""!==e.name&&void 0!==e.path),o=r[3]??r[2]??r[1]??r[0],i=` ${"info"===e?"💡":"error"===e?"❌":"⚠️ "} ${(new Date).toLocaleString()} `,s=("info"===e?ke.brightWhite:"error"===e?$e.red:Ee.brightGreen)(i),a=o?.name??"";this.fold&&a&&(a===this.mark||(this.mark&&console.groupEnd(),console.groupCollapsed(a))),this.mark=a;return se(`${s} ${a} ${o?.line?.concat(" 行")} ${o?.column?.concat(" 列")}`)}};this.info=(...e)=>{if("all"===this.type||"info"===this.type||!0===this.type){const t=o("info");console.log(...t),console.log(...e)}},this.warn=(...e)=>{if("all"===this.type||"warn"===this.type||!0===this.type){const t=o("warn");console.log(...t),console.warn.apply(console,e)}},this.error=(...e)=>{if("all"===this.type||"error"===this.type||!0===this.type){const t=o("error");console.log(...t),console.error.apply(console,e)}};const i=(...e)=>{this.info(...e)};Object.setPrototypeOf(i,this);const s=this;return new Proxy(i,{get:(e,t,n)=>"apply"===t?e:Reflect.get(e,t,n),set:(e,t,n)=>(Reflect.set(s,t,n),!0)})}We.prototype.clear=()=>{"browser"===Fe?console.clear():console.log(G.concat("c"))};const _e=new Ae({name:"nry",type:!1}),qe=O(_e.type);function ze(t){return e(t,{throwIfNoEntry:!1})}const Ve=new Ae({type:"error",name:"a node tools"});function Ge(...e){return u(f(...e))}function Je(e,t="file",...n){n=n.filter(e=>v(e));let r=h(...n);const o=ze(r);if(Ve("当前工作目录",r),!o)return Ve("🎯 工作目录不存在"),"";if(o.isFile())r=function(e){return l(e)}(r);else if(!o.isDirectory())return;let i=20;const s=()=>{const n=ze(Ge(r,e));if(n&&("file"==t&&n.isFile()||"directory"==t&&n.isDirectory()))return r;if(I(i))return;i--,Ve("♻️ 查找中...",r);const o=Ge(r,"..");return o!==r?(r=o,s()):void 0};return s()}function He(n){if(!/.json^/.test(n)&&!e(n,{throwIfNoEntry:!1}))return null;try{const e=t(n,{encoding:"utf-8"});return JSON.parse(e||"null")}catch(e){return Ve.error(e),null}}function Ke(e,t){try{return r(e,JSON.stringify(t,null,2),{encoding:"utf-8",flag:"w"}),!0}catch(e){return Ve.error(e),!1}}const Ue=()=>z()&&process&&process.stdout&&process.stdout.isTTY||!1,Ye=z()&&"win32"===process.platform||!z()&&window.navigator.userAgent.includes("Windows");function Ze(e){e=e.replaceAll(c.sep,"/"),/file:\/*/.test(e)&&(e=e.replace(/^.*file:\/*(.*)/,"$1"));const t=q(e);let n;try{throw new Error}catch(e){n=e}const r=(n.stack?.replace(/\\/gm,"/").split("\n")).reverse(),o=r.findIndex((e,n,r)=>!(t.test(e)||!t.test(r[n+1]))||!(!t.test(e)||0!==n));if(-1==o)return{name:"",line:0,row:0,originArr:r};let i=r[o];/\(.*\)/.test(i)&&(i=i.replace(/^.*\((.*)\).*/,"$1")),/file:\/*/.test(i)&&(i=i.replace(/^.*file:\/*(.*)/,"$1")),Ye||i.startsWith("/")||(i="/"+i);const s=i.match(/(.*?):(\d+):(\d+)/)??[i,i,0,0];return{name:s[1],line:Number(s[2]),row:Number(s[3]),originArr:r}}function Qe(){let e;try{new Function('import("")'),e=d(import.meta.url)}catch(t){Ve.error(t),e=__filename}Ye&&(e=e.replace(/\\/gm,"/")),e=Ze(e).name;return[e,l(e)]}const{stdin:Xe}=process,et={list:[],listened:!1,on(e,t,n){O(this.listened)&&(this.listened=!0,p(process.stdin),Ue()&&process.stdin.setRawMode(!0),process.stdin.resume(),Xe.on("keypress",rt),process.on("beforeExit",tt),process.stdin.on("end",nt));const r=this.list,o={key:e,callback:t,resolve:n};return M(r)&&Ve("当前执行的栈中没有数据",o),r.push(e),this[e]=o,o},remove(){const e=this.list,t=e.shift();return t&&this.del(t),Ve("执行完毕一项,还有:",e),!(e.length>0)&&(this.listened=!1,tt(),Ve("代理已移除"),!0)},del(e){Ve("开始移除",e);const t=this.list[0]===e&&!j(this[e]);if(Ve("当前 key 是否为当前执行项",t),t)return this.remove(),!0;{const t=this.list.includes(e),n=!j(this[e]);return t&&n?(this.list.splice(this.list.indexOf(e),1),this[e].resolve(!0),delete this[e],!0):t?(this.list.splice(this.list.indexOf(e),1),!0):!!n&&(this.list.splice(this.list.indexOf(e),1),this[e].resolve(!0),!0)}}};function tt(){Xe.removeListener("keypress",rt),process.removeListener("beforeExit",tt),process.stdin.removeListener("end",nt),Ue()&&Xe?.setRawMode(!1),Xe.pause()}function nt(){tt()}function rt(e,t){const n=et[et.list[0]],{callback:r,resolve:o}=n;Ve("当前执行的回调是",{...n,rl:"原始值为 readline 的 Interface 对象"}),R(r)?T(Reflect.apply(r,null,[e,t]))&&(Ve("回调遇见了想待的键,执行了退出操作,keyValue: < ",e,"> key: <",t,">"),et.remove(),o(!0)):(et.remove(),o(!1))}const ot=(e,t)=>async function(e,t){if(!z())throw new RangeError("当前环境不支持 readInput");const n=t??Symbol(A(3));return new Promise(t=>{et.on(n,e,t)})}(e,t);function it(e="",t=!0){let n="";const r=y(e);if(!C(t))throw Ve.error(""),new TypeError("lineFeed 的类型必须是 boolean ");if("bigint"===r){const r=Object.prototype.toString.call(e).concat("n");n=t?`${r}\n`:`${r}`}else if(["string","number","boolean","function","null"].includes(r))n=t?`${e}\n`:`${e}`;else{const r=JSON.stringify(e,(e,t)=>R(t)?`${t}`:null==t?"undefined":t,2);n=t?`${r}\n`:`${r}`}z()?process.stdout.write(n):console.log(...se(n.replace(/\n$/,"")))}function st(e,t=!0){it(`${t?J:G}${e}`,!1)}function at(){st("?25l")}function ct(){st("?25h")}function lt(e=!1){e&&ft(1/0),st("0J")}function ut(e=1,t=!1){st(`${dt(e,"vertical")}A`),t&&ft(1/0)}function ft(e=1){st(`${dt(e)}D`)}function ht(e=1){st(`${dt(e)}C`)}function dt(e,t="horizontal"){(!E(e=Number(e))||isNaN(e)||e<1||!1===Number.isInteger(e)&&e!==1/0)&&(e=1);const n=z()?"horizontal"===t?process.stdout.columns:process.stdout.rows:80;return(1/0===e||e>n)&&(e=n),e}function gt(){ct()}function pt(e){const t=e[e.length-1];v(t)&&!t.endsWith("\n")&&e.push("\n"),e.forEach(e=>it(e,!1))}function bt(e,t){const{show:n,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}=t??{show:!0,info:"请等待",prefix:0,interval:20,canCtrlCExit:!1,canCtrlDExit:!1,beforeDestroyed:()=>{}},l=C(e)?{show:e,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:v(e)?{show:n,info:e,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:j(e)?{show:n,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:E(e)?{show:!0,info:"请等待",prefix:isNaN(e)?o:Math.min(Math.max(0,e),2),interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c}:{show:n,info:r,prefix:o,interval:i,canCtrlCExit:s,canCtrlDExit:a,beforeDestroyed:c,...e};return l.interval=isFinite(l.interval)?Math.max(20,Math.min(2e3,l.interval)):i,l.info=l.info.replace(/\n/g,"\\n"),l}function mt(){ct()}Object.defineProperties(ot,{remove:{value:e=>et.del(e)}});const wt=[".","..","...","....","...",".."],yt=[["⋯","⋱","⋮","⋰","⋯","⋱","⋮","⋰"],["🕐","🕑","🕒","🕓","🕔","🕕","🕖","🕗","🕘","🕙","🕚","🕛"],["🕜","🕝","🕞","🕟","🕠","🕡","🕢","🕣","🕤","🕥","🕦","🕧"],["👈","👆","👉","👇","🤘","🤟","🫳","🫴","👊"],["🌞","🌕","🌖","🌗","🌜","🌘","🌑","🌒","🌓","🌛","🌔","🌔","🌔","🌝"]];class vt{#e;#t=void 0;#n=Symbol("waiting-tips");#r=[];#o=(...e)=>pt(e);state="destroyed";#i=0;#s=4e4;#a=!1;async destroyed(){"destroyed"!==this.state&&(this.state="destroyed",this.#i=0,j(this.#t)||clearInterval(this.#t),ot.remove(this.#n),ft(1/0),lt(),process.removeListener("exit",gt),process.removeListener("SIGINT",mt),ct(),this.#r.forEach(e=>this.#o(...e)),this.#r.length=0,this.log=this.#o,"promise"!==y(this.#e.beforeDestroyed)?this.#e.beforeDestroyed(this.#a):await this.#e.beforeDestroyed(this.#a),this.#a=!1)}log=this.#o;run(e){"run"===this.state&&this.destroyed(),this.#a=!1,this.state="run",this.#i=Date.now(),this.#e=j(e)?this.#e:bt(e,this.#e);const{prefix:t,info:n,interval:r,canCtrlCExit:o,canCtrlDExit:i}=this.#e;this.log=(...e)=>this.#r.push(e);const s=wt.length,a=yt[Math.min(yt.length-1,Math.max(t,0))],c=a.length,l=a.reduce((e,t)=>Math.max(e,Me(t)),0);let u=0;at(),process.on("exit",gt),process.on("SIGINT",mt),this.#t=setInterval(()=>{lt(!0),this.#r.forEach(e=>pt(e)),this.#r.length=0,it("\n".repeat(2)),ut(3),st(7,!1);const e=De(a[++u%c],l);Date.now()-this.#i<this.#s?it(Be(`${e} ${n.replace(/\n/,"\\n")}${wt[Math.floor(u/10)%s]}`),!1):it(Be(`${e} ${n} ${pe`当前已执行 ${Math.ceil((Date.now()-this.#i)/1e3)} 秒`}\n \n\r${be`可使用双击 esc 键退出(确保执行完成,若执行仍在期望时间内,请忽略)`}`),!1),st(8,!1)},r),ot((e,t)=>!!(t?.meta&&t?.sequence===G.repeat(2)||T(t?.ctrl)&&(o&&"c"===t?.name||i&&"d"===t?.name))&&(this.#a=!0,this.destroyed(),!0),this.#n)}set timeout(e){this.#i=Date.now(),this.#s=!isFinite(e)||e<0?4e4:e<600?1e3*e:e}get timeout(){return this.#s}constructor(e){this.#e=bt(e),T(this.#e.show)&&this.run()}}function xt(e,t,n){let r=e.toString().trim();return/\n$/.test(r)||(r=r.concat(Ye?"\r\n":"\n")),r=r.replace(/\n+/g,"\n"),lt(),t&&n.log(r),r}function $t(e,t){if(O(z()))throw new RangeError("当前环境不支持 node 环境");const{env:r}=t;v(e)&&(r.code=e,e={code:e,waiting:!1});const o=process.cwd();let i=b(o,e.cwd||"");-1===function(e){try{const t=ze(e);if(t&&t.isDirectory())return 0==n(e,{withFileTypes:!0}).length?1:0}catch(e){return Ve.error("is ",e),-1}return-1}(i)&&(Ve(`执行目录 ${fe(i)} 不存在,使用命令执行目录 ${be(o)}`),i=o);const s=e.code.replace(/\s{2,}/g," ").trim().split(" ");Object.assign(t.env,{shell:!0,hideWaiting:!0,waitingMessage:"请稍等",printLog:!1,...e,cmd:s,cwd:i})}function kt(e){const t={result:{success:!1,data:"",error:"",status:1,isSIGINT:!1,runCode:"",runCwd:""},env:{cmd:[],code:"",cwd:"",printLog:!1,shell:!0,callBack:()=>{},waiting:{show:!1,info:"",prefix:0,interval:10,canCtrlDExit:!1,canCtrlCExit:!1,async beforeDestroyed(){}}}},{env:n,result:r}=t;Ve("runOtherCode 方法 开始执行 "),$t(e,t),Ve("执行参数",t);const{cmd:o,waiting:i,cwd:s,shell:a,code:c}=n,[l,u]=(()=>{if(i instanceof vt)return[i,"run"===i.state];const e=bt(i);return[(t=e,new vt(t)),e.show];var t})();r.runCode=c,r.runCwd=s||process.cwd();try{return new Promise(e=>{const n=T(a)?g(c,[],{cwd:s,shell:a}):g(o[0],o.slice(1),{cwd:s,shell:a});u&&l.run({beforeDestroyed:e=>{if(e){if(Ve("执行退出前"),Ye){try{n.killed||n.kill(-1)}catch(e){Ve.error("使用 child.kill(child.pid, -1 ) 关闭子进程失败",e),g("taskkill",["/pid",n.pid?.toString()||"","/T","/F"],{stdio:"pipe"})}Ve("终结在 windows 下的子进程")}else n.kill("SIGTERM"),Ve("终结在非 windows 下的子进程");t.result.isSIGINT=!0}}}),n.on("spawn",()=>function(e){const{result:t}=e;Ve("子线程已启动,运行状态良好"),t.success=!0,t.status=1}(t)),n.stdout.on("data",e=>function(e,t,n){const{env:r,result:o}=t,i=xt(e,r.printLog,n);Ve(Ie`stdout on data`,i),o.data+=i}(e,t,l)),n.on("exit",(e,t)=>{Ve("子进程已退出了,退出码为 <",e,">"),S(t)||Ve.error("子进程被其他信号中断执行,执行的退出信号为:",t)}),n.stderr.on("data",e=>function(e,t,n){const{env:r,result:o}=t,i=xt(e,r.printLog,n);Ve(Ie`stderr on data`,i),o.error+=i}(e,t,l)),n.on("error",e=>function(e,t,n){const{env:r,result:o}=t;{const t=xt(e,r.printLog,n);Ve(Ie`error`,t),Ve.error("error",t),o.success=!1,o.status=""!==o.data?2:3,o.error+=t}}(e,t,l)),n.on("close",(n,r)=>function(e,t,n,r,o){const{env:i,result:s}=r,{callBack:a}=i;Ve("进行正常关闭",e),setTimeout(async()=>{a&&R(a)&&await Promise.resolve(Reflect.apply(a,null,[])),await o.destroyed(),0!==e&&"SIGINT"!==t&&"SIGTERM"!==t?(s.success=!1,s.status=3):"SIGINT"!==t&&"SIGTERM"!==t||(s.success=!1,s.status=4,s.isSIGINT=!0),n(s)})}(n??0,r??"",e,t,l))})}catch(e){const t=e.toString();return Ve.error("创建(但是确是非 node 无法创建子进程,而是更上游的 node 创建的错误)子进程出错",e),new Promise(e=>{(async()=>{await l.destroyed()})(),r.error=t,r.success=!1,r.status=0,e(r)})}}const Et=e=>kt(e);async function It(e,t=10){if(!v(e))throw new TypeError("str 需是一个字符串");if(!isFinite(t)||t<0||t>1e4)throw new RangeError("delay 需是一个 0 到 10000 之间(不包括两端)的数值");const n=Array.from(e);if(0!==n.length){for(const r of n)await V(t),Ve(`当前字符 ${Ce(r)} 长度为:`,r.length),Ve(`当前字符 ${ue.reversed(r)} 在 charCodeAt`,r.charCodeAt(0),r.charCodeAt(1),r.charCodeAt(2)),1===r.length&&isNaN(r.charCodeAt(1))?it(r,!1):2===e.length&&e.charCodeAt(0)>=55296&&e.charCodeAt(0)<=56319&&e.charCodeAt(1)>=56320&&e.charCodeAt(1)<=57343?(it(r,!1),it(" ",!1)):2===e.length&&65039===e.charCodeAt(1)?(it(r,!1),it(" ",!1)):(it(r,!1),it(" ",!1));it()}else it()}const Ct=process.argv.slice(2);Object.freeze(Ct);class Tt{originalArg=Ct.slice();name="";__filename="";get state(){return this._state}set state(e){this._state=[void 0,{code:1,text:"start"},{code:2,text:"bind over"},{code:3,text:"run over"},{code:4,text:"over",overCode:e}][E(e)?e:4]}_state={code:1,text:"start"};args=new Ot;abbr={};helpInfo="";hasShowVersion=!1;originalBind={};values=[]}class Ot extends Array{get $nomatch(){return[]}get $map(){return{}}get $arrMap(){return[]}get $only(){return[]}get $original(){return[]}get $isVoid(){return!1}}const St={},jt=new Ae({name:"a command"}),Rt=O(jt.type);function Nt(e){return[e.replace(/^(.*?)\s.*/gm,"$1")||"",/<.+>/.test(e)&&e.replace(/.*<(.+)>.*/,"$1")||"",e.replace(/.*?\((.*)\).*?/,"$1")||""]}function Mt(e,t){switch(t.state.code){case 3:return void jt.warn("执行绑定","但是已经执行过 `run`");case 4:return void jt.warn("执行绑定,但是 command 已完成全部应做动作");default:t.state=2}if(v(e)){const[n,r,o]=Nt(e);return Mt({name:n,abbr:r,info:o},t)}if(N(e))return e.forEach(e=>Mt(e,t));if(!j(e)&&!e.name&&!e.info)return function(e,t){const n={name:"",info:"",abbr:"",options:[]},r=Object.keys(e),o=Object.keys(n);return r.forEach(n=>{if(!o.includes(n)){const[r,o,i]=Nt(n);return Mt({name:r,info:i,abbr:o,options:e[n]},t)}})}(e,t);const n=e;n.abbr&&(t.abbr[n.abbr]=n.name),n.options?n.options=function(e,t,n){N(e)||(e=[e]);const r={};return e.forEach(e=>{let o={name:"",abbr:"",info:""};v(e)?[o.name,o.abbr,o.info]=Nt(e):o=Object.assign(o,e),o.abbr&&(n.abbr[`${t}^${o.abbr}`]=o.name),r[o.name]=o}),r}(n.options,n.name,t):n.options={},t.originalBind[n.name]={abbr:"",...n}}function Lt(){return new Proxy(new Tt,{get(e,t,n){if("args"===t){const t=JSON.parse(JSON.stringify(e[Symbol.for("_args")]||[]));return new Proxy(t,{get(n,r,o){return"$nomatch"===r?e.values.slice():"$map"===r?function(e){if(M(e))return{};const t=new Object;return e.forEach(e=>{const n=t[e.name]||{};n.value=[...n.value||[],...e.value||[]],e.options&&e.options.forEach(e=>{n[e.name]=[...n[e.name]||[],...e.value||[]]}),t[e.name]=n}),t}(t):"$arrMap"===r?M(i=t)?[]:i.map(e=>{const t={},n=t[e.name]||{};return e.value&&!M(e.value)&&(n.value=e.value),j(e)||j(e.options)||M(e.options)||(n.options=[],e.options.forEach(e=>{n.options?.push(Object.fromEntries([[e.name,e.value]]))})),t[e.name]=n,t}):"$only"===r?[...new Set(t.map(e=>e.name))]:"$original"===r?Ct.slice():"$isVoid"===r?0==Ct.slice().length:Reflect.get(n,r,o);var i},set:(e,t,n,r)=>(Reflect.set(e,t,n,r),!0)})}return Reflect.get(e,t,n)},set:(e,t,n,r)=>("args"===t?e[Symbol.for("_args")]=n:Reflect.set(e,t,n,r),!0)})}const Dt=" ".repeat(4);function Bt(e){return e.state="help",v(e.helpInfo)&&"help"!==e.helpInfo?function(e,t){const n=e.originalBind[t];if(it(`${Dt}${n.name}${Dt}${pe(n.info)}\n`),n.options&&!D(n.options)){it(`${de(`${Dt}使用:`)} ${e.name} ${t} [subOptions/subAbbr [value]]\n`),it(`${be(`${Dt}subOptions:`)} \n`),Pt(n.options||{})}else{it(`${he(`${Dt}使用:`)} ${e.name} ${t} [value]\n`)}}(e,e.helpInfo):N(e.helpInfo)&&2==e.helpInfo.length?function(e){const t=e.name,n=e.helpInfo.join(" "),r=e.originalBind[e.helpInfo[0]].options[e.helpInfo[1]].info;it(`${be(" 可使用:")} ${t} ${n} [value]\n${he(" 描述:")} ${r}`)}(e):function(e){it(`${we(" 可使用:")} ${e.name} options/abbr [subOptions/subAbbr [value]]\n\n选项:\n`);const t=Pt(e.originalBind);!function(e){["version -v 版本描述","help -h 帮助查看"].forEach(t=>{const[n,r,o]=t.split(" ");it(Ft({len:e,name:n,info:o,abbr:r})),it("")})}(t)}(e)}function Pt(e){const t=Object.keys(e).sort();let n=8;t.forEach(e=>n=Math.max(n,e.length));const r=Math.min(15,n+1);return it(Ft({len:r,name:"子命令",info:"描述",abbr:"缩写",color:!1})),it(""),t.forEach(t=>{const{name:n,abbr:o,info:i}=e[t];let s=!1;"options"in e[t]&&!D(e[t].options)&&(s=!0),it(Ft({len:r,name:n,info:i,abbr:o,textDecoration:s})),it("")}),r}function Ft(e){const t=Object.assign({name:"",info:"",abbr:"",len:15,color:!0,textDecoration:!1},e);let n=ue[t.color?"green":"black"](Dt);return n+=ue[t.textDecoration?"blue":"black"](t.name.slice(0,t.len)),n+=" ".repeat(t.len+1-At(t.name,t.len)),n+=ue[t.color?"yellow":"black"]`${t.abbr?.slice(0,6)||""}${" ".repeat(7-At(t.abbr||"",6))}`,n+=t.color?pe(t.info):t.info,n}function At(e,t){return Math.min(e.replace(/[^\x00-\x7f]/,"11").length,t)}const Wt="";function _t(e){const{name:t,object:n,item:r,result:o}=e;k(t)||(r.name&&n.options?.push(r),o.push(JSON.parse(JSON.stringify(n))))}function qt(e,t){"true"==e?e=!0:"false"==e?e=!1:e==Number(e)&&(e=Number(e)),k(t.name)?t.values.push(e):t[t.item.name?"item":"object"].value.push(e)}function zt(e,t){const n=[];let r="";const o=(e,t)=>j(t)||k(t)?n.push(e):n.push(e,t);function i(e,s){if(!k(r)){if(t.originalBind[r].options[e])return o(e,s);const n=t.abbr[`${r}^${e}`];if(!j(n))return o(n,s)}if(t.originalBind[e])return r=e,o(e,s);if(t.abbr[e])return e=t.abbr[e],r=e,o(e,s);if(e.includes("=")){const t=e.indexOf("=");if(0===t||t===e.length-1)return n.push(e);const[r,o]=[e.slice(0,t),e.slice(t+1)||"true"];return i(r,o)}return j(s)||k(s)?n.push(e):n.push(`${e}=${s}`)}return e.forEach(e=>i(e)),n}function Vt(e,t,n){n.init(),(e=zt(e.filter(e=>""!==e),t)).forEach(e=>{const{name:r}=n;return e=e.trim(),/^([a-z]|[A-Z]|-|\$|_)/.test(e)?!k(r)&&t.originalBind[r].options&&t.originalBind[r].options[e]?function(e,t){const{item:n,object:r}=t;n.name&&r.options.push(n),t.resetItem(e)}(e,n):t.originalBind[e]?function(e,t){k(t.name)||(_t(t),t.resetItem("")),t.resetObject(e)}(e,n):qt(e,n):qt(e,n)}),_t(n)}function Gt(e){switch(e.state.code){case 3:return void it("已经执行过 `run`");case 4:return void it("已完成全部");default:e.state=3}!function(e){if(2==process.argv.length)return;const t=e.originalArg,n=`${Wt}${t.join(Wt)}${Wt}`,r=t.findIndex(e=>/^(-h|help)$/.test(e));if(new RegExp(`${Wt}(-v|version)${Wt}`,"i").test(n))return void(e.hasShowVersion=!0);if(I(r))return void(e.helpInfo="help");let o=[];const i={result:[],values:[],name:"",object:{name:"",value:[],options:[]},item:{name:"",value:[]},resetObject(e){this.name=e,this.object={name:e,value:[],options:[]}},resetItem(e){this.item={name:e,value:[]}},init(){this.result=[],this.values=[],this.resetItem(""),this.resetObject("")}};r>0?(Vt(t.slice(0,r+1),e,i),e.values=i.values,e.args=i.result,o=e.args,M(o)?e.helpInfo="help":[j,M].some(e=>e(o[0].options))?e.helpInfo=o[0].name:e.helpInfo=[o[0].name,o[0].options[0].name]):(Vt(t,e,i),e.values=i.values,e.args=i.result)}(e),function(e){["name","originBind","abbr"].forEach(t=>{const n=t;e[n]&&(Object.freeze(e[n]),Object.defineProperty(e,t,{value:e[n],writable:!1,enumerable:!0,configurable:!1}))})}(e)}function Jt(e){e.state="version";const t=Je("package.json","file",Ze(e.__filename).name);if(j(t))return Ht();const n=Ge(t,"package.json");if(!ze(n))return Ht();const r=He(n);if(S(r))return Ht();const{platform:o}=process,i=ue.brightCyan(r.name),s=r.version,c="win32"==o?"Windows":"darwin"==o?"mac":o,l=ue.brightMagenta(a());it(`${i} 版本 ${ue.brightRed(s)} (${c} ${l})`)}function Ht(){it("抱歉,未找到版本定义说明")}const Kt=Re("#333"),Ut=Re("#666"),Yt=Re("#aaa"),Zt=Ne("#666"),Qt=Ut(".".repeat(3)),Xt=(e="❖")=>ye(e),en=(e="▶︎")=>ve(e),tn=(e="⚉")=>we(e),nn=(e="◦")=>Ut(e),rn=(e="●")=>ye.blink(e),on=(e="□")=>Ut(e),sn=(e="□")=>ye.blink(e),an=(e="■")=>Ut(e),cn=(e="■")=>ye.blink(e);function ln(e,t="⚉"){it(`${tn(t)} ${Re("#612").italic(e)}`)}function un(e,t="❖"){it(`${Xt(t)} ${e}`)}const fn={callList:[],on(e,t){const n=this.callList;M(n)&&(jt("当前执行列表为空,直接执行任务",e),Reflect.apply(t,void 0,[])),n.push([e,t])},remove(e){const t=this.callList,n=t.findIndex(([t])=>t===e);return t.splice(n,1),M(t)?(jt("当前执行列表为空,返回 true 结束执行"),!0):(Reflect.apply(t[0][1],null,[]),!1)}};function hn(e=!0){return process.stdout.rows-4*(1+Number(e))}function dn(e){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];if(P(r,e=>[v,E].some(t=>t(e))))t.push({value:r,label:r,checked:!1,tip:"",disable:!1});else{if(!P(r,e=>[v,v].some(t=>t(e.label))&&[v,E,B].some(t=>t(e.value))))throw new TypeError(`${r} 的类型非法(有可能是返回值类型更改后未在解析中兼容)`);{let e=r.checked;!j(e)&&C(e)||(e=!1);let n=r.tip;!j(n)&&v(n)||(n="");const o=r.value;if(j(o)||S(o))throw new TypeError("value 值类型非法");const i=r.label,s=T(r.disable);t.push({checked:e,tip:n,value:o,label:i,disable:s})}}}return t}const gn="请使用键盘选择,请使用 Enter 键进行选择",pn=!1,bn="radio",mn={drawData:[],info:gn,focus:0,renderInfo:{rows:0,renderRows:0,otherInfoRows:0,allowBelow:!1,size:{width:0,height:0}},resultText:"",errorText:"",private:pn,required:pn,kind:bn,mustInfo:pn,maxRows:hn(),data:[],initData(e){jt("初始化数据"),this.reset(),N(e)?this.data=dn(e):Object.keys(e).forEach(t=>{const n=e[t];switch(t){case"data":this.data=N(n)?dn(n):[];break;case"info":this.info=v(n)?n:gn;break;case"resultText":this.resultText=v(n)?n:this.info||"";break;case"errorText":this.errorText=v(n)?n:this.resultText||this.info||"";break;case"private":this.private=C(n)?n:pn;break;case"required":this.required=C(n)?n:pn;break;case"kind":this.kind="check"===n?"check":bn;break;case"maxRows":this.maxRows=isFinite(n)&&Number.isInteger(n)&&n>0?n+4:hn()}});const t=this.data;for(const e in t){if(!t[e].disable)return this.focus=Number(e),!1}return!0},reset(){this.drawData.length=this.data.length=this.focus=0,this.maxRows=hn(),this.renderInfo={rows:0,renderRows:0,otherInfoRows:0,allowBelow:!1,size:{width:0,height:0}},this.info=gn,this.kind=bn,this.resultText=this.errorText="",this.private=!0,this.required=this.mustInfo=pn}};function wn(e){const{data:t}=mn,n=process.stdout.columns-7,r=n-3,o=t[e].label.toString();return Me(o)<=n?o:De(o,r,!1).concat(Qt)}const yn=()=>{!function(){const{focus:e,drawData:t,data:n,kind:r}=mn;for(let o=0,i=n.length;o<i;o++){const i=n[o];if(j(t[o])){const n=Me(i.label.toString());t[o]={index:o,text:wn(o),length:n,checked:"radio"!==r&&i.checked,focus:o===e,changed:!0,show:!0,disable:i.disable}}else o===e?(t[o].changed=!0,t[o].focus=!0):o!==e&&T(t[o].focus)&&(t[o].changed=!0,t[o].focus=!1)}}(),function(){const{drawData:e,renderInfo:t,focus:n}=mn,{renderRows:r}=t,o=e.length;if(o===r)return void e.forEach(e=>e.show=!0);const i=o-1,s=Math.floor((r-1)/2);let a=1&r?n-s:n-s-1;a=a<0?0:a;let c=r+a-1;c>i&&(c=i,a=c-r+1);e.forEach(e=>{const{index:t}=e;t>c||t<a?e.show=!1:t===c&&t!==i||t===a&&0!==t?(e.show=!0,e.text=Qt):e.text===Qt?(e.show=!0,e.text=wn(t)):e.show=!0})}();const{info:e,mustInfo:t,renderInfo:n,focus:r,data:o}=mn,{rows:i,allowBelow:s,size:a}=n,{width:c}=a;let l=`${J}${c}D`;l+="\n".repeat(i),l+=`${J}${i}A`,l+=`${J}J`,l+=Be(`${en()} ${e} \n\n`),l+=function(){const{drawData:e,kind:t}=mn;let n="";for(let r=0,o=e.length;r<o;r++){const o=e[r];o.show&&(o.focus?(n+=Be(` ${"radio"===t?rn():o.checked?cn():sn()} ${o.text}`),n+="\n"):o.text===Qt?(n+=` ${Qt}`,n+="\n"):o.disable?(n+=Be(` ${"radio"===t?Yt`⊗`:o.checked?Yt`▣`:Yt`☒`} ${Yt(o.text)}`),n+="\n"):(n+=Be(` ${"radio"===t?nn():o.checked?an():on()} ${Kt(o.text||"")}`),n+="\n"))}return n}(),l+=`${J}J`,s&&(t?l+=function(){const e=process.stdout.columns-7;mn.mustInfo=!1;const t="抱歉,该项至少选择一项!!!请使用空格键或是左右键切换选择状态",n=Me(t)<e?t:De(t,e);return"\n".concat(fe(n))}():o[r].tip?(l+="\n",l+=Be(`${be(o[r].tip)}`)):l+="\n",l+="\n"),Rt&&(l+=`${J}${c}D${J}${i}A`),it(l,!1)},vn=W(yn,66),xn=W(yn,600);function $n(){const{data:e,renderInfo:t,maxRows:n}=mn,[r,o]=[process.stdout.columns,process.stdout.rows],i=e.length;t.size={width:r,height:o};const s=t.rows=Math.max(Math.min(i+4,hn(!1),n),5),a=t.allowBelow=hn()>e.length||s>6,c=t.otherInfoRows=a?4:2;t.renderRows=s-c}async function kn(){const{data:e,required:t,kind:n,drawData:r}=mn,o={exit:!1};return await ot((i,s)=>{const{focus:a}=mn;switch(s.name){case"return":return jt("用户已选择,返回真值告诉等待程序可终结当前输入"),"check"!==n||!t||!M(r.filter(e=>e.checked))||(mn.mustInfo=!0,vn(),!1);case"up":jt("用户使用了键盘键的 up 键"),In(!1),vn();break;case"down":jt("用户使用了键盘键的 down 键"),In(),vn();break;case"right":jt("用户使用了键盘键的右键");case"left":jt("用户使用了键盘键的左键");case"space":jt("用户使用了键盘键的空格键"),"check"===n&&(e[a].checked=r[a].checked=!r[a].checked,vn());break;case"escape":if(s?.sequence===G.repeat(2))return o.exit=!0,!0;break;default:if(jt("用户使用了键盘键的非方向键 <",i,">, <",s,">"),"check"===mn.kind&&("a"===s?.name&&(En(),vn()),"z"===s?.name&&(En(!1),vn()),"r"===s?.name&&(mn.data.forEach(e=>{e.disable||(e.checked=!e.checked)}),mn.drawData.forEach(e=>{e.disable||(e.checked=!e.checked)}),vn())),T(s?.ctrl)&&("c"===s?.name||"d"===s?.name))return o.exit=!0,!0}return!1}),o.exit}function En(e=!0){mn.data.forEach(t=>{t.disable||(t.checked=e)}),mn.drawData.forEach(t=>{t.disable||(t.checked=e)})}function In(e=!0){const{focus:t,drawData:n}=mn,r=n.length-1,o=e?t===r?n:[...n.slice(t+1),...n.slice(0,t+1)]:0===t?n.toReversed():[...n.slice(t),...n.slice(0,t)].toReversed();for(const e of o)if(!e.disable)return void(mn.focus=e.index)}async function Cn(e,t){const n=Symbol("selection");return new Promise((r,o)=>{fn.on(n,async()=>{try{const o=await async function(e,t){if(process.stdout.removeListener("resize",Tn),process.stdout.on("resize",Tn),mn.initData(e))return;at(),jt("初始绘制问题选项"),$n(),vn(),jt("绘制完成,等待用户操作");const n=await kn();it(K,!1),process.stdout.removeListener("resize",Tn);const{resultText:r,info:o,focus:i,kind:s,drawData:a,errorText:c}=mn;if(ct(),lt(!0),n)return void(mn.private||ln(c||r||o));const l=a.filter(e=>e.checked);if(!mn.private){const e="radio"===s?[a[i].text]:l.map(e=>e.text);un(`${Ut.italic.dim(r||o)}: ${Ut(e.join("、"))}`)}const u="radio"===s?mn.data[i].value:l.map(e=>mn.data[e.index].value),f="radio"===s?i:l.map(e=>e.index),h="string"==t||j(t)?u:f;return h}(e,t);fn.remove(n),r(o)}catch(e){jt.error(e),fn.remove(n),o()}})})}const Tn=W(()=>{const{drawData:e,renderInfo:t}=mn,n=t.size.height;e.length=0,it(K,!1),lt(),$n(),process.stdout.rows!==n?xn():vn()},33);function On(e,t){return Cn(e,t)}const Sn={data:"",kind:0,multi:!1,progressCount:0,indexOfCursor:0,init:function(e){this.data=e,this.multi=N(e)}},jn={get kind(){return Sn.kind},set kind(e){(!isFinite(e)||0!=e&&1!=e)&&(e=0),Sn.kind=e},get multi(){return Sn.multi},enterText:[],get progressCount(){return Sn.progressCount},set progressCount(e){Sn.progressCount=e,e<0&&Reflect.apply(Rn,this,[])},get indexOfCursor(){return Sn.indexOfCursor},set indexOfCursor(e){Sn.indexOfCursor=e},currentIssue:{text:"请更换为你自己的问题",tip:"",type:"text",private:!0,errorText:"",resultText:"",required:!0,defaultValue:"",mustInfo:!1,isWrapLine:!1,usableLength:0,mustInfoLen:0,row:0,cum:0,maxLen:0,minLen:0,len:0,verify:[]},results:[],assign(e){Object.keys(e).forEach(t=>{if(!Object.hasOwn(this,t)||j(e[t]))throw it(`${t} is not exist`),new Error(`${t} is not exist`);this[t]=e[t]})},beforeStart(){this.results.length=this.enterText.length=this.indexOfCursor=0,this.progressCount=Sn.multi?-Sn.data.length:-1}};function Rn(){const{multi:e,progressCount:t}=this,n=e&&N(Sn.data)?Sn.data[Sn.data.length+t]:Sn.data,r={text:"请更换为你自己的问题",tip:"",type:"text",private:!0,errorText:"",resultText:"",required:!0,defaultValue:"",mustInfo:!1,isWrapLine:!1,usableLength:0,mustInfoLen:0,row:0,cum:0,maxLen:0,minLen:0,len:0,verify:[]};Object.assign(r,v(n)||E(n)?{text:n}:n);const o=N(r.tip)?1:0;let i;1==o?i=[r.tip[0]]:(i=[],[r.tip,r.defaultValue].every(e=>$(e))&&(r.required=!0),!k(r.defaultValue)&&$(r.tip)&&(r.tip=r.defaultValue)),r.text=k(r.text.toString())?"请使用你自己的问题":r.text,this.assign({indexOfCursor:0,kind:o,enterText:i,currentIssue:r})}const Nn=W(()=>{const{kind:e,currentIssue:t,enterText:n}=jn,{mustInfo:r,text:o,required:i,tip:s,verify:a}=t;at();let c="",l=!1;if(I(t.row)||(c+=`${J}${t.row}A`,t.row=0),c+=`\r${J}0J${K}`,r)c=Mn(c),l=!0;else if(!M(n)){const e=n.join("");for(const n of a)if(x(n.reg)&&v(n.info)&&[j,C].some(e=>e(n.inverse))){n.reg.lastIndex=0;const r=n.reg.test(e);if(T(n.inverse)&&T(r)||T(!n.inverse)&&O(r)){t.mustInfo=n.warn?ve(n.info):n.info,c=Mn(c),l=!0;break}}}const u=0===e&&i?we.blink("*"):"";c+=`${en()} ${u}${o}${u}: `,t.row+=Number(t.isWrapLine),c+="\n".repeat(Number(t.isWrapLine)),I(e)?M(n)&&v(s)?$(s)?c+=Te.dim.blink("I"):c+=" ".concat(Zt.italic.dim(s[0])).concat(Te.dim(s.slice(1))):(c+=" ",c=function(e){const{type:t,usableLength:n}=jn.currentIssue;e="text"===t?function(e,t){const{enterText:n,indexOfCursor:r}=jn,o=Me(n.join(""))>t;r===n.length?(o?e=function(e,t){const{enterText:n}=jn;return e+=Qt.concat([...De(n.toReversed().join(""),t-3,!1)].reverse().join("")),e}(e,t):e+=n.join(""),e+=Zt.hide(" ")):o?e=function(e,t){const{indexOfCursor:n,enterText:r}=jn,o=r.join(""),i=r.length,s=Math.floor(t/2),a=De(o,s),c=a.length-1,l=a[c]===o[c]?c:c-1,u=De(o,-s),f=u.length-1,h=u[f]===o[i-1-f]?i-1-f:i-f,d=r.map((e,t)=>t===n?Zt(e):e).join("");if(n>=h)e+=Qt,e+=De(d,3-t,!1);else if(n<l)e+=De(d,t-3,!1),e+=Qt;else{const t=s-Me(r[n])-3;e+=Qt,e+=De(o.slice(0,n),-t,!1),e+=Zt(r[n]),e+=De(o.slice(n+1),t,!1),e+=Qt}return e}(e,t):e+=`${n.map((e,t)=>t===r?Zt(e):e).join("")}`;return e}(e,n):function(e){const{enterText:t,indexOfCursor:n}=jn;n===t.length?(e+=` ${t.map(()=>"*").join("")}`,e+=Zt.hide("1")):e+=` ${t.map((e,t)=>t===n?Zt("*"):"*").join("")}`;return e}(e);return e}(c)):c=function(e){const{currentIssue:t,enterText:n}=jn;return e+t.tip.map(e=>e===n[0]?Oe.bold.blink.cyan(e):pe(e)).join(" ")}(c),jt("计算完成的文本为",c),it(Be(c)),t.row++,function(e){const{currentIssue:t,indexOfCursor:n,enterText:r}=jn,{text:o,required:i,mustInfoLen:s}=t;if(e)return ht(s);const a=r.slice(0,n).join(""),c=o.toString().concat(a),l=Me(c),u=l+7+2*Number(i),f=u%process.stdout.columns;jt("用户输入",r.join("")),jt("光标所在的位置",n),jt("实际参与计算的用户输入的文本为",a),jt("计算总文本",c),jt("计算文本长度",l),jt("计算可用长度",u),jt("屏幕宽",process.stdout.columns),jt("光标偏移量",u%process.stdout.columns),ht(f)}(l),l||it(Se("I"),!1),st("8m")},66);function Mn(e){const{currentIssue:t}=jn;e+="\n\r",t.row++;let n="";if(C(t.mustInfo)){const e=t.required?" ":"";n+=" ".repeat(2).concat(e).concat(fe(t.text)).concat(e).concat(" ".repeat(3)),n+=fe.blink`👆`}else n+=pe(t.mustInfo);let r=Me(n);const o=process.stderr.columns-4;return o<r&&(r=o,n=De(n,o)),t.mustInfoLen=r,e+=n,e+=`\r${J}1A`,t.row--,t.mustInfo=!1,e}function Ln(){const{currentIssue:e}=jn;!function(){const{currentIssue:e}=jn,t=process.stdout.columns;let n=t-Me(e.text.toString())-2*Number(e.required)-4-7;const r=n<5;r&&(n=t-4);e.isWrapLine=r,e.usableLength=n}();const{isWrapLine:t}=e,n=2+Number(t);it("\n".repeat(n),!1),e.row+=n,ut(n),e.row-=n}async function Dn(){try{await ot((e=this,(t,n)=>{const{kind:r,currentIssue:o,enterText:i,results:s}=e,{tip:a,text:c}=o;let l=[],u=0,f=0,h=!0;switch(I(r)||(l=a,u=l.length-1,f=l.indexOf(i[0])),jt("\n 用户使用了",t,n),n.name){case"return":if(function(){const{enterText:e,currentIssue:t,results:n}=jn,r=t.text;let o=e.join("").trim();if($(o)&&t.required)return t.mustInfo=!0,!1;const{len:i,minLen:s,maxLen:a,verify:c}=t,l=o.length;if(I(jn.kind)){if(c.length>0)for(const e of c)if([j,O].some(t=>t(e.warn))&&x(e.reg)&&v(e.info)&&[j,C].some(t=>t(e.inverse))){e.reg.lastIndex=0;const t=e.reg.test(o);if(T(e.inverse)&&t||!e.inverse&&!t)return!1}if(!I(i)&&l!==i)return t.mustInfo=`您输入的长度 ${he(l)} 不符合要求值 ${be(i)}`,!1;if(!I(s)&&l<s)return t.mustInfo=`您输入的长度 ${he(l)} 小于最低要求${be(s)}`,!1;if(a>s&&l>a)return t.mustInfo=`您输入的长度 ${he(l)} 大于最低要求${be(a)}`,!1}return $(o)&&O(t.required)&&(o=t.defaultValue||t.tip||""),n.push({q:r,r:o}),!0}())return h=!1,!0;break;case"left":!function(e,t,n){const{kind:r,enterText:o}=jn;I(r)?jn.indexOfCursor=0===jn.indexOfCursor?o.length:jn.indexOfCursor-1:o[0]=e[0===t?n:t-1]}(l,f,u);break;case"right":!function(e,t,n){const{kind:r,enterText:o}=jn;I(r)?jn.indexOfCursor=jn.indexOfCursor==jn.enterText.length?0:jn.indexOfCursor+1:o[0]=e[t==n?0:t+1]}(l,f,u);break;case"delete":case"backspace":!function(){const{enterText:e,kind:t}=jn;I(t)&&!I(jn.indexOfCursor)&&(e.splice(jn.indexOfCursor-1,1),jn.indexOfCursor--)}();break;case"escape":if(n?.sequence===G.repeat(2))return s.push({q:c,r:void 0}),h=!1,!0;break;default:if(jt("[0m当前触发为含 ctrl 键的功能键",t,n),O(n?.ctrl))!function(e){const{enterText:t,kind:n}=jn;j(e)||0!==n||(jn.indexOfCursor==t.length?t.push(e):t.splice(jn.indexOfCursor,0,e),jn.indexOfCursor+=1)}(t);else if(h=!1,st("m"),"c"===n?.name||"d"===n?.name)return s.push({q:c,r:void 0}),!0}return h&&Nn(),!1}))}catch(e){jt.error("接收用户输入出错",e),it(e)}var e}function Bn(e,t){const n=Symbol("question");try{return new Promise((r,o)=>{fn.on(n,async()=>{try{const o=await async function(e,t){process.stdout.removeListener("resize",Pn),process.stdout.on("resize",Pn),jt("初始化问题"),Sn.init(e),jt("初始化当前问题"),jn.beforeStart(),jt("开始绘制问题");do{Ln(),Nn();try{await Reflect.apply(Dn,jn,[])}catch(e){jt.error(e)}const{currentIssue:e,results:t}=jn;I(e.row)||(ut(e.row,!0),e.row=0),st("m"),ct(),lt(!0);const n=e.resultText||e.text,r=t[t.length-1].r;e.private||(j(r)?ln(e.errorText||n):un(`${Ut(n)}: ${"text"===e.type?r:r.replace(/./gm,"*")}`)),++jn.progressCount}while(jn.progressCount<0);return process.stdout.removeListener("resize",Pn),st("m"),ct(),lt(!0),jn.multi?T(t)&&N(e)?jn.results.map(e=>e.r):jn.results:jn.results[0].r}(e,t);fn.remove(n),r(o)}catch(e){jt.error("\n\n\n\n\n执行出现错误",e),fn.remove(n),o(e)}})})}catch(e){return jt.error("系统故障",e),it("系统故障",!1),it(e),new Promise((t,n)=>{n(e)})}}const Pn=W(()=>{const{currentIssue:e}=jn;I(e.row)||(ut(e.row,!0),e.row=0),it(K,!1),lt(!0),Ln(),Nn()}),Fn=async function(e,t){return Bn(e,t)},An=new class{#c;#l;constructor(e=""){if(v(e)||(e=`${e}`),this.#c=Symbol(e),St[this.#c])throw new Error(`${e} 已经存在,请更换初始化命令名称,若仍想在原命令上操作,请抽离为单独的文件做数据共享`);this.#l=St[this.#c]=Lt(),[this.#l.__filename]=Qe(),this.#l.name=e||v(process.argv[1])&&process.argv.slice(1,2)[0].replace(/.*\/.*?$/,"$1")||"",Object.defineProperty(this,"#uniKey",{value:this.#c,writable:!1,enumerable:!1,configurable:!1})}get name(){return this.#l.name}get state(){return this.#l.state}isEnd(e=!1){const t=4===this.#l.state.code;return t&&T(e)&&this.end(),t}end(){return this.#l.state="end",process.exit()}error(){return this.#l.state="error",process.exit(1)}bind(e){return Mt(e,this.#l),this}run(){const e=this.#l;return Gt(e),k(e.helpInfo)||Bt(e),e.hasShowVersion&&Jt(e),this}get args(){return this.#l.args}get values(){return this.#l.values.slice()}help(e,t){const n=this.#l;v(e)&&n.originalBind[e]?v(t)&&n.originalBind[e].options&&n.originalBind[e].options[t]?n.helpInfo=[e,t]:n.helpInfo=e:n.helpInfo="help",Bt(this.#l)}version(){Jt(this.#l)}}("nry");async function Wn(e="好的,即将退出"){return k(e)||await It(e),ct(),An.end()}function _n(e){return e.endsWith("/")?e:e+"/"}async function qn(e){return new Promise(t=>{let n;try{return n=new URL(e),t(!0)}catch{return _e.error("当前传入的",e,"有误"),t(!1)}})}An.bind(["add <a> (用于添加一个自定义的 npm、yarn、pnpm 源)","edit <ed> (用于编辑源) ",qe?"":"clean (移除本地数据)","delete <del> (用于移除某个或多个自定义的项)","list <ls> (用于展示当前的所有的源)","manage <mg> (用于管理当前源在列表中的显隐)",`reset <rs> (重制当前的源,将${we`永久移除自定义源`}、${xe`恢复已更改的源`})`]).run().isEnd(!0);const zn={npm:"https://registry.npmjs.org/","tao-bao":"https://registry.npmmirror.com/","ten-xun":"https://mirrors.tencent.com/npm/",ustclug:"https://npmreg.proxy.ustclug.org/",yarn:"https://registry.yarnpkg.com/"},{npm:Vn,"tao-bao":Gn,"ten-xun":Jn,ustclug:Hn,yarn:Kn}=zn,Un=[{value:Vn,label:"官方",tip:Vn},{value:Gn,label:"淘宝",tip:Gn},{value:Jn,label:"腾讯",tip:Jn},{value:Hn,label:"中科大",tip:Hn},{value:Kn,label:"yarn",tip:Kn}];function Yn(e=!1){if(e)return[...Un];if(!Xn.available)return[...Un];const t=Xn.read();if(N(t)&&t.every(e=>v(e.value)&&!k(e.label)&&v(e.value)&&!k(e.value))){return t.map(e=>(e.value=_n(e.value),e.tip=_n(e.tip),e))}return[...Un]}const Zn=new class{#u;#f=!0;get available(){return this.#f}constructor(e){const t=function(){const e=s();if(Ve("当前获取用户主目录为",e),!e||"/"===e||e.includes("Default"))throw new Error("未能获取到主目录路径 <"+e+">");try{const t=Ge(e,"test_write"+Date.now());return Ke(t,{}),i(t),e}catch(e){return void Ve.error(e)}}();if(j(t))return this.#f=!1,void(this.#u="");this.#f=!0,this.#u=Ge(t,".mudbean.data",`${e}`)}read(e){if(!this.available)return null;const t=Ge(this.#u,e);return j(ze(t))?{}:He(t)||{}}write(e,t){if(!this.available)return!1;const n=Ge(this.#u,e),r=Ge(n,"../");Ve("创建的文件路径为"),o(r,{recursive:!0}),Ve("写入的文件路径为:",n),Ve("写入文件内容为",t);const i=Ke(n,t);return Ve("写入反馈",i),i}getPath(e){return Ge(this.#u,e)}}("nry"),Qn="config",Xn={available:Zn.available,read(){if(Zn.available){const e=Zn.read(Qn);if(N(e))return e}return Yn(!0)},addNew(e){if(Zn.available){const t=this.read();return t.push(e),_e("新写入的数据为",e),this.write(t)}return!1},write:e=>!!Zn.available&&Zn.write(Qn,e),getPath:()=>Zn.getPath(Qn),clean(){const e=this.getPath();_e("将要移除的文件",e),i(e)}},er={add:!1,edit:!1,delete:!1,manage:!1,list:!1,noMatch:!1,reset:!1,clean:!1},tr={pkgManager:function(e=!1){if(O(e)){const e=e=>Boolean(Je(e,"file"));if(e("pnpm-lock.yaml"))return"pnpm";if(e("yarn.lock"))return"yarn";if(e("package-lock.json"))return"npm"}const t=process.env.npm_config_user_agent||"";return t.includes("pnpm")?"pnpm":t.includes("yarn")?"yarn":t.includes("npm")?"npm":process.env.PNPM_HOME?"pnpm":process.env.YARN_IGNORE_PATH?"yarn":"npm"}(!0)};function nr(e){if(!Xn.available)return!1;const t=_n(e.value);return Xn.addNew({value:t,label:e.label.toString(),tip:t,disable:!1})}const rr=m(function(e){return this.data=[],Object.setPrototypeOf(this,e),this});function or(e,t){if(t.align&&(e.align=t.align),t.bgColor&&(e.bgColor=t.bgColor),t.color&&(e.color=t.color),t.italic&&(e.italic=t.italic),t.underline&&(e.underline=t.underline),t.border)if(P(t.border,e=>v(e))){const n=t.border;e.border={left:{color:void 0,style:n},right:{color:void 0,style:n},top:{color:void 0,style:n},bottom:{color:void 0,style:n}}}else if(P(t.border,e=>["color","style"].some(t=>!j(e[t])))){const n=t.border,r=n.style,o=n.color||void 0;e.border=JSON.parse(JSON.stringify({left:{color:o,style:r},right:{color:o,style:r},top:{color:o,style:r},bottom:{color:o,style:r}},(e,t)=>""===t?void 0:t))}else P(t.border,e=>["left","right","top","bottom"].some(t=>!j(e[t])))&&(e.border=t.border)}class ir{}function sr(e,t){N(e)&&(e={data:e});const n=new ir;or(n,e);const r=new rr(n);return Object.setPrototypeOf(n,t),e.data?.forEach(e=>{e&&r.data.push(function(e,t){if(j(e))return;P(e,e=>!L(e))&&(e={content:e});const n={content:e.content};return or(n,e),Object.setPrototypeOf(n,t),n}(e,n))}),r}class ar extends ir{border={left:{style:"bold",color:void 0},right:{style:"bold",color:void 0},top:{style:"bold",color:void 0},bottom:{style:"bold",color:void 0}}}function cr(e){const t=new ar;return Object.setPrototypeOf(t,e),t}const lr=!z(),ur={emojiLength:2.08,emojiRegex:/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}]/gu,chineseLength:1.8,chineseRegex:/[\u4E00-\u9FFF]/g};const fr=new class{align="left";color="";bgColor="";bold=!1;underline=!1;italic=!1;border={left:{color:void 0,style:"simple"},right:{color:void 0,style:"simple"},top:{color:void 0,style:"simple"},bottom:{color:void 0,style:"simple"}}},hr=m(function(e){return this.body=[],this.header=void 0,Object.setPrototypeOf(this,e),this});class dr{}function gr(e){let t=ue;return P(e)&&(e.bold&&(t=t.bold),k(e.bgColor)||j(e.bgColor)||(t=t.bgColor(e.bgColor)),k(e.color)||j(e.color)||(t=t.color(e.color)),e.italic&&(t=t.italic),e.underline&&(t=t.underline)),t}const pr={fine:{lt:"┌",ct:"┬",rt:"┐",lc:"├",c:"┼",rc:"┤",lb:"└",cb:"┴",rb:"┘",l:"─",v:"│"}};function br(e){let t=0;return[...e].forEach(e=>{ur.emojiRegex.lastIndex=0,ur.chineseRegex.lastIndex=0,e.match(ur.emojiRegex)?t+=ur.emojiLength:e.match(ur.chineseRegex)?t+=ur.chineseLength:t++}),Math.ceil(t)}function mr(e,t){const n=function(e){const t=[];return e.header&&e.header.data.forEach((e,n)=>{const r=e?.content?.toString()??"";t[n]=Math.max(t[n]??0,lr?br(r):Me(r))}),e.body&&e.body.forEach(e=>{e.data.forEach((e,n)=>{const r=e?.content?.toString()??"";t[n]=Math.max(t[n]??0,lr?br(r):Me(r))})}),t}(e);let r=!1,o="";e.header&&(r=!0,o+=function(e,t){let n="";const r=t.length-1,{fine:o}=pr,i=gr(e);return t.forEach((e,t)=>{0===t&&(n+=o.lt),n+=K,n+=o.l.repeat(e+2),t===r?(n+=K,n+=o.rt):(n+=K,n+=o.ct)}),n+="\n",t.forEach((t,s)=>{n+=K,n+=o.v;const a=e.data[s];if(j(a)||S(a))n+=K,n+=i(" ".repeat(t+2));else{const e=gr(a);let r=a.content?.toString()??"";r=r.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),n+=K,n+=e`\u2002${De(r,t)}\u2002`}s===r&&(n+=o.v)}),n+="\n",n}(e.header,n)),o+=function(e,t,n){let r="";const o=t.length-1,{fine:i}=pr;return t.forEach((e,t)=>{0===t&&(r+=K,r+=n?i.lc:i.lt),r+=K,r+=i.l.repeat(e+2),t===o?(r+=K,r+=n?i.rc:i.rt):(r+=K,r+=n?i.c:i.ct)}),r+="\n",e.forEach((n,s)=>{const a=gr(n);t.forEach((e,t)=>{r+=K,r+=i.v;const s=n.data[t];if(j(s)||S(s))r+=a`${" ".repeat(e+2)}`;else{const t=gr(s);let n=s.content?.toString()||"";n=n.replace(/[\n]/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"),r+=K,r+=t`\u2002${De(n,e)}\u2002`}t===o&&(r+=K,r+=i.v)}),r+="\n";const c=e.length-1===s;t.forEach((e,t)=>{0===t&&(r+=K,r+=c?i.lb:i.lc),r+=K,r+=i.l.repeat(e+2),t===o?(r+=K,r+=c?i.rb:i.rc):(r+=K,r+=c?i.cb:i.c)}),r+="\n"}),r}(e.body,n,r);const i=se(o);if(lr){const e=i[0].split("%c"),n=i.map((n,r)=>{if(r>0){const o=[...e[r]].reduce((e,t)=>Me(t)>1?(ur.emojiRegex.lastIndex=0,t.match(ur.emojiRegex)?e-(ur.emojiLength-2):e+(2-ur.chineseLength)):e,0);return n+"font-family: Consolas,Monaco,Courier,'Courier New','等宽字体',monospace; font-size:"+t+"px;word-spacing:normal;padding:0;margin:0;padding-right:"+o*t+"px"}return n});console.log(...n)}else console.log(...i)}const wr=m(function(e){const[t,n]=function(e){j(e)&&(e={}),N(e)&&(e={body:e});const t=new dr;or(t,e),Object.setPrototypeOf(t,fr);const n=new hr(t);return e.header&&(n.header=sr(e.header,cr(t))),e.body?.forEach(e=>n.body.push(sr(e,t))),[n,t]}(e);let r=12;const o=()=>mr(t,r);return Object.setPrototypeOf(o,this),Object.defineProperties(o,{addRow:{value:e=>(t.body.push(sr(e,n)),o),configurable:!1,writable:!1,enumerable:!1},setHeader:{value:e=>(t.header=sr(e,cr(n)),o),configurable:!1,writable:!1,enumerable:!1},setFontSize:{value:e=>(r=e,o)}}),o});async function yr(){const{pkgManager:e}=tr,t=`${e} config get registry`;_e("执行可写代码",t);const n=await Et(t);if(_e("获取当前的本地配置为",n),n.success)return n.data.replace(/\s/gm,"")}async function vr(){const{pkgManager:e}=tr,t=Yn(),n=await yr(),r=new wr({header:[`${e} registry 源`,"别名","当前可见"]});!(t.findIndex(e=>e.value===n)>-1)&&v(n)&&t.push({value:n,tip:n,label:"曾用值"}),t.forEach(e=>r.addRow([(n===e.value?pe`* `:" ").concat(e.value),(n===e.value?pe`* `:" ").concat(he(e.label)),e.disable?"❌":"✅"])),r(),it(me`注:当前可见状态仅影响 npx nry 选择项`)}const{npm:xr,yarn:$r}=zn;async function kr(e){const{pkgManager:t}=tr,n=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}];e.forEach(e=>{n.push({reg:new RegExp(`^${_(e.value)}/*$`,"mg"),info:`${he(e.value)}(${be(e.label)}) 已存在`,inverse:!0})});const r=await Fn({text:"请输入自定义的源地址",tip:"yarn"===t?$r:xr,minLen:5,maxLen:120,verify:n,required:!1});return _e("用户输入的地址",r),j(r)?await Wn():await qn(r)?_n(r):(it(`当前设置 registry 「${je(r)}」 不可用`),it("请使用正确的源设置"),await kr(e))}async function Er(){if(!Xn.available)return await Wn("读写受限,正在退出");const{pkgManager:e}=tr,t=Yn(),n=await kr(t),r=await async function(e){const t=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}],{pkgManager:n}=tr;e.forEach(e=>{t.push({reg:new RegExp(`^${_(e.label)}$`,"mg"),info:`${he(e.label)}(${be(e.value)}) 已存在`,inverse:!0})});const r=await Fn({text:`请输入自定义的 ${n} 的别名`,tip:"任意别名",minLen:1,maxLen:120,verify:t,defaultValue:"",required:!1});return _e("用户输入的别名为",r),j(r)?await Wn():r}(t);if(nr({value:n,label:r})){it(me`当前的 ${e} registry 源列表为`),await vr();const t=["退出","继续添加"],n=await Fn({text:"添加完成,是否持续添加",tip:t});return j(n)||n===t[0]?await Wn(""):await Er()}return await Wn(`写入${we`失败`},原因未知`)}async function Ir(e="",t=!0,n=!0){k(e)&&(e=`请选择想使用的新的 ${tr.pkgManager} registry 源`);let r=!1;const o=Yn(),i=await yr();if(!j(i)){for(const e of o)if(e.value===i){e.label=e.label.toString()+`(${pe`当前使用`})`,e.disable=!n,r=!0;break}if(O(r)){const e={value:i,label:"当前使用值",disable:!n};o.push(e),Xn.available&&nr({value:i,label:"曾用值"})}}_e("处理完的数据",o);const s=t?o.filter(e=>!e.disable||e.disable&&e.value===i):o.map(e=>(e.value===i?e.disable=!n:e.disable=!1,e)),a=await On({data:s,info:e},"number");return _e("用户选择的项",a),j(a)?await Wn():(_e("当前用户选择为",s[a]),s[a])}async function Cr(){const e=await Ir();await async function(e){const{pkgManager:t}=tr,n=_n(e.value);if(!await qn(n))return await Wn(`选择的项 「${pe(n)}」 不可连接,无法被设置`);const r=`${t} config set registry "${n}"`;_e("设置源执行代码",r);(await Et(r)).success||await Wn();it(`已将 ${t} registry 更改为 ${he(e.value)}(${ge(e.label)})`)}(e)}async function Tr(){if(!Xn.available)return await Wn("当前读写受限,即将退出程序");const e=await Ir("请选择要删除的项",!1,!1),{value:t,label:n}=e,r=Yn();for(const e in r){const o=Number(e),i=r[o];if(i.value===t&&i.label===n){r.splice(o,1);break}}if(Xn.write(r)){it("删除项后的列表为:"),await vr();const e=["退出","继续删除"],t=await Fn({text:"是否继续删除其他项",tip:e});return j(t)||t===e[0]?await Wn(""):await Tr()}}async function Or(){if(!Xn.available)return await Wn("当前读写权限不足,即将退出程序");const e=await Ir("请选择你想要修改的项",!1),{value:t,label:n}=e;_e("获取用户的选择",e),_e("原始的值",t),_e("原始的标签",n),await async function(e){const{pkgManager:t}=tr,n=await Fn({text:`请更改为新的 ${t} registry 值`,tip:e.value,defaultValue:e.value,required:!1});if(_e("新值为",n),j(n))return;e.value=e.tip=_n(n)}(e),await async function(e){const{pkgManager:t}=tr,n=await Fn({text:`请更改为新的 ${t} registry 别名`,tip:e.label,defaultValue:e.label.toString(),required:!1});if(_e("新值为",n),j(n))return;e.label=n}(e);const{value:r,label:o}=e;_e("更改后的值",r),_e("更改的标签",o);const i=Yn();for(const e of i)if(e.value===t&&e.label===n){e.value=r,e.label=o.toString();break}if(Xn.write(i)){it("更改后的列表为:"),await vr();const e=["退出","继续修改"],t=await Fn({text:"是否继续修改其他项",tip:e});return j(t)||t===e[0]?await Wn(""):await Or()}}async function Sr(){return function(){const e=An.args,t=e.$map;_e("源解析值",e),_e("源解析值没有匹配项",e.$isVoid),["add","delete","edit","list","manage","reset","clean"].forEach(e=>er[e]=O(j(t[e]))),er.noMatch=e.$isVoid,_e("解析完的值",er)}(),_e("解析参数完毕,开始执行",er),er.noMatch?(_e("当前没有匹配值"),await Cr()):er.reset?(_e("重置项"),await async function(){if(!Xn.available)return await Wn("当前读写权限受限,正在退出程序");const e=["退出","重置"],t=await Fn({text:"请确认是否执行覆盖原数据,该操作无法复原",tip:e});return j(t)||t===e[0]?await Wn("好的,这就退出重置"):Xn.write(Yn(!0))?(await It("写入"+he`成功`,60),await vr()):await Wn("重置未能完成,原因未知")}()):er.list?(_e("当前为展示项"),await vr()):er.manage?(_e("当前执行状态更改"),await async function(){if(!Xn.available)return await Wn("当前读写受限,即将退出程序。");const e=Yn(),t=await yr(),n=await On({data:e.map(e=>({...e,checked:!e.disable,disable:e.value===t})),kind:"check"},"number");if(_e("交互结果",n),j(n))return await Wn("好的,将退出状态显隐管理");e.forEach((e,t)=>{e.disable=!n.includes(t)}),_e("保存前的数据",e),Xn.write(e)&&await vr()}()):er.add?(_e("添加新的项"),await Er()):er.edit?(_e("编辑项"),await Or()):er.delete?(_e("删除项"),await Tr()):er.clean?(_e("当前执行清理"),Xn.clean()):await Cr()}(async()=>{try{await Sr()}catch(e){_e.error("系统级捕获 错误",e),console.log("当前出现未知错误",e)}})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nry",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "泥豆君",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"mudbean",
|
|
26
26
|
"vvi"
|
|
27
27
|
],
|
|
28
|
-
"homepage": "https://
|
|
28
|
+
"homepage": "https://npms.gleanings.cn/nry",
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/gleanings/nry/issues",
|
|
31
31
|
"email": "Mr.MudBean@outlook.com"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
35
|
-
"url": "git+https://github.com/
|
|
35
|
+
"url": "git+https://github.com/gleanings/nry.git"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public",
|