nry 1.0.1 → 1.1.1

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 ADDED
@@ -0,0 +1,69 @@
1
+ # 更新日志 📔
2
+
3
+ ## 1.1.1 (2026-6-27)
4
+
5
+ ## 1.1.0 (2026-1-17)
6
+
7
+ ## v1.0.1 (2025-11-11)
8
+
9
+ ### 🐛 bug 修复
10
+
11
+ 在输入的自定义的源为非法 URL 后,再次通过本程序设置将导致设置实效,建议使用
12
+
13
+ ```bash
14
+ # npm 源
15
+ npm config set registry
16
+ # pnpm 源
17
+ pnpm config set registry
18
+ # yarn 源
19
+ yarn config set registry
20
+ ```
21
+
22
+ ## v1.0.0 (2025-11-11)
23
+
24
+ ### 🎨 UI 改进
25
+
26
+ #### 1. 让 npm 的 registry 值更规范
27
+
28
+ - 默认的 `npm config get registry` 的值应当是 `https://registry.npmjs.org/` 而不是 `https://registry.npmjs.org` 。修改默认预设值并修改已有配置的用户的配置
29
+
30
+ 所以,可能将之前标记为 ”曾用值“ 的带尾斜杠的修改为同 `value` (如果有)的下。
31
+
32
+ - 新增的自定义的 registry 将自动带上尾斜杠(如果没有的话)
33
+ - 移除旧的设置值并更新为带尾斜杠(在下一次交互时才会触发修改,但是使用 `nry` 设置时将自动追加尾斜杠)
34
+
35
+ ## v0.1.3 (2025-8-16)
36
+
37
+ - 修复致命错误
38
+
39
+ ## v0.1.2 (2025-7-30)
40
+
41
+ - 文档补充
42
+
43
+ ## v0.1.1 (2025-7-24)
44
+
45
+ - 根据调用的包管理器不同配置不同的源,支持 `npm`、`yarn`、`pnpm`
46
+
47
+ ## v0.1.0 (2025-7-19)
48
+
49
+ - 么事
50
+
51
+ ## v0.0.4 (2025-6-22)
52
+
53
+ - 文档补充
54
+
55
+ ## v0.0.3 (2025-6-17)
56
+
57
+ - list 时展示当前的非默认值的设定值(这会让 rs 命令看起来没有重置当前使用值)
58
+
59
+ ## v0.0.2 (2025-6-15)
60
+
61
+ - 文档完善
62
+
63
+ ## v0.0.1 (2025-6-15)
64
+
65
+ - 功能添加
66
+
67
+ ## v0.0.0 (2025-6-14)
68
+
69
+ - 创建项目
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright (c) <2025> <🥜>
3
+ Copyright (c) <2025> <Mr.MudBean>
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
@@ -13,13 +13,4 @@ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
13
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
14
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
15
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
-
17
- # MIT 许可证
18
-
19
- 版权所有 (c) [2025] [花生亻]
20
-
21
- 特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、再许可和/或出售该软件副本的权利,并允许向其提供该软件的人这样做,但须遵守以下条件:
22
-
23
- 上述版权声明和本许可声明应包含在所有副本或软件的重要部分中。
24
-
25
- 软件按“原样”提供,不附带任何形式的明示或暗示的保证,包括但不限于适销性、特定用途适用性和不侵权的保证。在任何情况下,作者或版权持有人均不对因合同、侵权或其他方式引起的任何索赔、损害或其他责任负责,无论是在与软件或软件的使用或其他交易有关的任何诉讼中。
16
+
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Npm RegistrY
2
2
 
3
- [![version](<https://img.shields.io/npm/v/nry.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/nry) [![issues 提交](<https://img.shields.io/badge/issues-提交-rgb(255,0,63)?logo=github>)](https://github.com/earthnutDev/nry/issues)
3
+ [![version](<https://img.shields.io/npm/v/nry.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/nry) [![issues 提交](<https://img.shields.io/badge/issues-提交-rgb(255,0,63)?logo=github>)](https://github.com/MrMudBean/nry/issues)
4
4
 
5
5
  一个用于 npm、yarn、pnpm registry 切换及管理的工具。
6
6
 
@@ -14,7 +14,7 @@ npm install -g nry
14
14
 
15
15
  ## 使用
16
16
 
17
- 本应用使用 [a-command](https://www.npmjs.com/package/a-command) ,所以屏蔽了 `Ctrl + C` 、`Ctrl + D` ,但可采用*双击 `Esc` 退出*。
17
+ 本应用使用 [@vvi/command](https://www.npmjs.com/package/@vvi/command) ,所以屏蔽了 `Ctrl + C` 、`Ctrl + D` ,但可采用*双击 `Esc` 退出*。
18
18
 
19
19
  执行能力可能根据当前执行的包管理器有关,
20
20
 
@@ -34,6 +34,8 @@ npm install -g nry
34
34
 
35
35
  相应的,对应的包管理器调用执行仅用于设置本包管理器的 `registry`。
36
36
 
37
- ## 文档地址
37
+ ## 状态
38
38
 
39
- 参看 [nry](https://earthnut.dev/npm/nry)
39
+ 此软件包是 `MrMudBean` 生态系统的一部分。
40
+ 它使用严格的 TypeScript 编写,并通过 Rollup 构建进行验证。
41
+ 虽然单元测试较少,但 API 稳定,并在生产环境中大量使用。
package/bin.js ADDED
@@ -0,0 +1,2 @@
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"),"");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&&lt(1/0),ot("0J")}function ct(e=1,t=!1){ot(`${ft(e,"vertical")}A`),t&&lt(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("当前触发为含 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)}})();
package/package.json CHANGED
@@ -1,51 +1,47 @@
1
1
  {
2
2
  "name": "nry",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
+ "author": {
6
+ "name": "泥豆君",
7
+ "email": "Mr.MudBean@outlook.com",
8
+ "url": "https://mudbean.cn"
9
+ },
5
10
  "description": "更替及管理 npm、yarn、pnpm registry",
6
11
  "license": "MIT",
7
- "dependencies": {
8
- "@qqi/log": "^0.1.1",
9
- "a-command": "^2.3.16",
10
- "a-js-tools": "^1.0.12",
11
- "a-node-tools": "^4.2.20",
12
- "a-type-of-js": "^1.0.7",
13
- "color-pen": "^2.0.13",
14
- "colored-table": "^0.1.0",
15
- "qqi": "^0.1.2"
16
- },
17
- "publishConfig": {
18
- "access": "public",
19
- "registry": "https://registry.npmjs.org/"
20
- },
21
12
  "files": [
22
- "bin.mjs"
23
- ],
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/earthnutDev/nry.git"
27
- },
28
- "author": {
29
- "name": "🥜",
30
- "email": "earthnut.dev@outlook.com",
31
- "url": "https://earthnut.dev"
32
- },
33
- "browserslist": [
34
- "node>=18.0.0"
13
+ "bin.js",
14
+ "LICENSE",
15
+ "README.md",
16
+ "THIRD-PARTY-LICENSES.txt",
17
+ "CHANGELOG.md"
35
18
  ],
36
- "engines": {
37
- "node": ">=18.0.0"
38
- },
39
19
  "keywords": [
40
20
  "nry",
41
- "earthnut"
21
+ "npm",
22
+ "pnpm",
23
+ "yarn",
24
+ "registry",
25
+ "mudbean",
26
+ "vvi"
42
27
  ],
43
- "homepage": "https://earthnut.dev/npm/nry",
28
+ "homepage": "https://npm.lmssee.com/nry",
44
29
  "bugs": {
45
- "url": "https://github.com/earthnutDev/nry/issues",
46
- "email": "earthnut.dev@outlook.com"
30
+ "url": "https://github.com/MrMudBean/nry/issues",
31
+ "email": "Mr.MudBean@outlook.com"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/MrMudBean/nry.git"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org/"
47
40
  },
48
41
  "bin": {
49
- "nry": "./bin.mjs"
42
+ "nry": "bin.js"
43
+ },
44
+ "engines": {
45
+ "node": ">=18.0.0"
50
46
  }
51
47
  }
package/bin.mjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{Dog as a}from"@qqi/log";import{isFalse as t,isArray as e,isBusinessEmptyString as n,isString as i,isUndefined as r}from"a-type-of-js";import{QQI as l}from"qqi";import{unlinkSync as o}from"node:fs";import{typewrite as s,cursorShow as u,detectPackageManager as c,_p as f,runOtherCode as w}from"a-node-tools";import{Command as p}from"a-command";import{brightRedPen as d,brightCyanPen as g,greenPen as m,cyanPen as b,reversedPen as v,magentaPen as y,brightBlackPen as h,bluePen as $}from"color-pen";import k from"node:https";import{escapeRegExp as x}from"a-js-tools";import{Table as q}from"colored-table";const M=new a({name:"nry",type:!1}),E=t(M.type),S=new l("nry"),L="config",V={available:S.available,read(){if(S.available){const a=S.read(L);if(e(a))return a}return z(!0)},addNew(a){if(S.available){const t=this.read();return t.push(a),M("新写入的数据为",a),this.write(t)}return!1},write:a=>!!S.available&&S.write(L,a),getPath:()=>S.getPath(L),clean(){const a=this.getPath();M("将要移除的文件",a),o(a)}},P={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/"},R=new p("nry");async function j(a="好的,即将退出"){return n(a)||await s(a),u(),R.end()}function N(a){return a.endsWith("/")?a:a+"/"}async function C(a){return new Promise(t=>{let e;try{return e=new URL(a),t(!0)}catch{return M.error("当前传入的",a,"有误"),t(!1)}const n={hostname:e.hostname,path:N(e.pathname),port:443,method:"GET",timeout:5e3,headers:{"sec-fetch-dest":"empty","X-Spiferacl":"1"}};M("请求的测试参数为",n);const i=k.get(n,a=>{a.on("data",a=>M(a.toString())),a.on("end",()=>t(200===a.statusCode)),a.on("error",a=>(M.error(a),t(!1))),a.on("timeout",()=>(i.destroy(),t(!1)))});i.end()})}R.bind(["add <a> (用于添加一个自定义的 npm、yarn、pnpm 源)","edit <ed> (用于编辑源) ",E?"":"clean (移除本地数据)","delete <del> (用于移除某个或多个自定义的项)","list <ls> (用于展示当前的所有的源)","manage <mg> (用于管理当前源在列表中的显隐)",`reset <rs> (重制当前的源,将${d`永久移除自定义源`}、${g`恢复已更改的源`})`]).run().isEnd(!0);const{npm:G,"tao-bao":I,"ten-xun":T,ustclug:U,yarn:W}=P,X=[{value:G,label:"官方",tip:G},{value:I,label:"淘宝",tip:I},{value:T,label:"腾讯",tip:T},{value:U,label:"中科大",tip:U},{value:W,label:"yarn",tip:W}];function z(a=!1){if(a)return[...X];if(!V.available)return[...X];const t=V.read();if(e(t)&&t.every(a=>i(a.value)&&!n(a.label)&&i(a.value)&&!n(a.value))){return t.map(a=>(a.value=N(a.value),a.tip=N(a.tip),a))}return[...X]}const A={add:!1,edit:!1,delete:!1,manage:!1,list:!1,noMatch:!1,reset:!1,clean:!1},B={pkgManager:c(!0)},{npm:D,yarn:F}=P;async function H(a){const{pkgManager:t}=B,e=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}];a.forEach(a=>{e.push({reg:new RegExp(`^${x(a.value)}/*$`,"mg"),info:`${m(a.value)}(${b(a.label)}) 已存在`,inverse:!0})});const n=await R.question({text:"请输入自定义的源地址",tip:"yarn"===t?F:D,minLen:5,maxLen:120,verify:e,required:!1});return M("用户输入的地址",n),r(n)?await j():await C(n)?N(n):(f(`当前设置 registry 「${v(n)}」 不可用`),f("请使用正确的源设置"),await H(a))}function J(a){if(!V.available)return!1;const t=N(a.value);return V.addNew({value:t,label:a.label.toString(),tip:t,disable:!1})}async function K(){const{pkgManager:a}=B,t=`${a} config get registry`;M("执行可写代码",t);const e=await w(t);if(M("获取当前的本地配置为",e),e.success)return e.data.replace(/\s/gm,"")}async function O(){const{pkgManager:a}=B,t=z(),e=await K(),n=new q({header:[`${a} registry 源`,"别名","当前可见"]});!(t.findIndex(a=>a.value===e)>-1)&&i(e)&&t.push({value:e,tip:e,label:"曾用值"}),t.forEach(a=>n.addRow([(e===a.value?y`* `:" ").concat(a.value),(e===a.value?y`* `:" ").concat(m(a.label)),a.disable?"❌":"✅"])),n(),f(h`注:当前可见状态仅影响 npx nry 选择项`)}async function Q(){if(!V.available)return await j("读写受限,正在退出");const{pkgManager:a}=B,t=z(),e=await H(t),n=await async function(a){const t=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}],{pkgManager:e}=B;a.forEach(a=>{t.push({reg:new RegExp(`^${x(a.label)}$`,"mg"),info:`${m(a.label)}(${b(a.value)}) 已存在`,inverse:!0})});const n=await R.question({text:`请输入自定义的 ${e} 的别名`,tip:"任意别名",minLen:1,maxLen:120,verify:t,defaultValue:"",required:!1});return M("用户输入的别名为",n),r(n)?await j():n}(t);if(J({value:e,label:n})){f(h`当前的 ${a} registry 源列表为`),await O();const t=["退出","继续添加"],e=await R.question({text:"添加完成,是否持续添加",tip:t});return r(e)||e===t[0]?await j(""):await Q()}return await j(`写入${d`失败`},原因未知`)}async function Y(a="",e=!0,i=!0){n(a)&&(a=`请选择想使用的新的 ${B.pkgManager} registry 源`);let l=!1;const o=z(),s=await K();if(!r(s)){for(const a of o)if(a.value===s){a.label=a.label.toString()+`(${y`当前使用`})`,a.disable=!i,l=!0;break}if(t(l)){const a={value:s,label:"当前使用值",disable:!i};o.push(a),V.available&&J({value:s,label:"曾用值"})}}M("处理完的数据",o);const u=e?o.filter(a=>!a.disable||a.disable&&a.value===s):o.map(a=>(a.value===s?a.disable=!i:a.disable=!1,a)),c=await R.selection({data:u,info:a},"number");return M("用户选择的项",c),r(c)?await j():(M("当前用户选择为",u[c]),u[c])}async function Z(){const a=await Y();await async function(a){const{pkgManager:t}=B,e=N(a.value);if(!await C(e))return await j(`选择的项 「${y(e)}」 不可连接,无法被设置`);const n=`${t} config set registry "${e}"`;M("设置源执行代码",n),(await w(n)).success||await j(),f(`已将 ${t} registry 更改为 ${m(a.value)}(${$(a.label)})`)}(a)}async function _(){if(!V.available)return await j("当前读写受限,即将退出程序");const a=await Y("请选择要删除的项",!1,!1),{value:t,label:e}=a,n=z();for(const a in n){const i=Number(a),r=n[i];if(r.value===t&&r.label===e){n.splice(i,1);break}}if(V.write(n)){f("删除项后的列表为:"),await O();const a=["退出","继续删除"],t=await R.question({text:"是否继续删除其他项",tip:a});return r(t)||t===a[0]?await j(""):await _()}}async function aa(){if(!V.available)return await j("当前读写权限不足,即将退出程序");const a=await Y("请选择你想要修改的项",!1),{value:t,label:e}=a;M("获取用户的选择",a),M("原始的值",t),M("原始的标签",e),await async function(a){const{pkgManager:t}=B,e=await R.question({text:`请更改为新的 ${t} registry 值`,tip:a.value,defaultValue:a.value,required:!1});M("新值为",e),r(e)||(a.value=a.tip=N(e))}(a),await async function(a){const{pkgManager:t}=B,e=await R.question({text:`请更改为新的 ${t} registry 别名`,tip:a.label,defaultValue:a.label.toString(),required:!1});M("新值为",e),r(e)||(a.label=e)}(a);const{value:n,label:i}=a;M("更改后的值",n),M("更改的标签",i);const l=z();for(const a of l)if(a.value===t&&a.label===e){a.value=n,a.label=i.toString();break}if(V.write(l)){f("更改后的列表为:"),await O();const a=["退出","继续修改"],t=await R.question({text:"是否继续修改其他项",tip:a});return r(t)||t===a[0]?await j(""):await aa()}}async function ta(){return function(){const a=R.args,e=a.$map;M("源解析值",a),M("源解析值没有匹配项",a.$isVoid),["add","delete","edit","list","manage","reset","clean"].forEach(a=>A[a]=t(r(e[a]))),A.noMatch=a.$isVoid,M("解析完的值",A)}(),M("解析参数完毕,开始执行",A),A.noMatch?(M("当前没有匹配值"),await Z()):A.reset?(M("重置项"),await async function(){if(!V.available)return await j("当前读写权限受限,正在退出程序");const a=["退出","重置"],t=await R.question({text:"请确认是否执行覆盖原数据,该操作无法复原",tip:a});return r(t)||t===a[0]?await j("好的,这就退出重置"):V.write(z(!0))?(await s("写入"+m`成功`,60),await O()):await j("重置未能完成,原因未知")}()):A.list?(M("当前为展示项"),await O()):A.manage?(M("当前执行状态更改"),await async function(){if(!V.available)return await j("当前读写受限,即将退出程序。");const a=z(),t=await K(),e=await R.selection({data:a.map(a=>({...a,checked:!a.disable,disable:a.value===t})),kind:"check"},"number");if(M("交互结果",e),r(e))return await j("好的,将退出状态显隐管理");a.forEach((a,t)=>{a.disable=!e.includes(t)}),M("保存前的数据",a),V.write(a)&&await O()}()):A.add?(M("添加新的项"),await Q()):A.edit?(M("编辑项"),await aa()):A.delete?(M("删除项"),await _()):A.clean?(M("当前执行清理"),V.clean()):await Z()}(async()=>{try{await ta()}catch(a){M.error("系统级捕获 错误",a),console.log("当前出现未知错误",a)}})();