nry 0.1.0 → 0.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.
Files changed (3) hide show
  1. package/README.md +16 -281
  2. package/bin.mjs +1 -1
  3. package/package.json +10 -10
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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)
4
4
 
5
- 一个用于 npm registry 切换及管理的工具。
5
+ 一个用于 npm、yarn、pnpm registry 切换及管理的工具。
6
6
 
7
7
  ## 安装
8
8
 
@@ -16,289 +16,24 @@ npm install -g nry
16
16
 
17
17
  本应用使用 [a-command](https://www.npmjs.com/package/a-command) ,所以屏蔽了 `Ctrl + C` 、`Ctrl + D` ,但可采用*双击 `Esc` 退出*。
18
18
 
19
- | 调用子项 | 缩写项 | 释义 |
20
- | :--------------- | :------------ | :---------------------- |
21
- | `npx nry` | -- | 切换 npm registry |
22
- | `npx nry add` | `npx nry a` | 添加自定义 npm registry |
23
- | `npx nry delete` | `npx nry del` | 删除 npm registry |
24
- | `npx nry edit` | `npx nry ed` | 修改 npm registry |
25
- | `npx nry list` | `npx nry ls` | 展示 npm registry |
26
- | `npx nry manage` | `npx nry mg` | 管理 npm registry 显隐 |
27
- | `npx nry reset` | `npx nry re` | 重置 npm registry |
19
+ 执行能力可能根据当前执行的包管理器有关,
28
20
 
29
- 额,因为文档没啥写的,所以就有了下面的*执行展示*。
21
+ - 使用 `npm` 时使用 `npx`调用执行
22
+ - 使用 `yarn` 时使用 `yarn dlx` 调用执行
23
+ - 使用 `pnpm` 时使用 `pnpm dlx` 调用执行
30
24
 
31
- ### 简单使用
25
+ | 调用子项 | 缩写项 | 释义 |
26
+ | :-------------- | :----------- | :--------------------- |
27
+ | `-- nry` | -- | 切换 registry 源 |
28
+ | `-- nry add` | `-- nry a` | 添加自定义 registry 源 |
29
+ | `-- nry delete` | `-- nry del` | 删除 registry 源 |
30
+ | `-- nry edit` | `-- nry ed` | 修改 registry 源 |
31
+ | `-- nry list` | `-- nry ls` | 展示 registry 源 |
32
+ | `-- nry manage` | `-- nry mg` | 管理 registry 源显隐 |
33
+ | `-- nry reset` | `-- nry re` | 重置 registry 源 |
32
34
 
33
- ```bash
34
- # 简单使用
35
- npx nry
36
- ```
37
-
38
- 其效果为:
39
-
40
- ```bash
41
- ▶︎ 请选择想使用的新的 npm registry
42
-
43
- ● 官方
44
- ◦ tao bao
45
- ◦ 腾讯(当前使用)
46
- ◦ 中科大
47
- ◦ yarn
48
-
49
- https://registry.npmjs.org
50
- ```
51
-
52
- 可使用键盘上下键切换项,使用 `Enter` 键选择要选择新 npm registry。
53
-
54
- ### 添加自定义项
55
-
56
- 可使用 子命令 `add` 添加自定义 npm registry。
57
-
58
- ```bash
59
- # 长命令使用
60
- npx nry add
61
- # 使用缩写
62
- npx nry a
63
- ```
64
-
65
- 执行效果
66
-
67
- ```bash
68
- # 先问询输入自定义 npm registry 网址
69
- ▶︎ 请输入自定义的 npm 的源地址: https://registry.npmjs.org
70
- # 再询问输入自定义的 npm registry 别名
71
- ▶︎ 请输入自定义的 npm 的别名: 任意别名
72
- # 展示添加的结果
73
- 当前的 npm registry 列表为
74
- ┌────────────────────────────────────┬───────────┬──────────┐
75
- │ npm registry  │ 别名   │ 当前可见 │
76
- ├────────────────────────────────────┼───────────┼──────────┤
77
- │ * https://registry.npmjs.org  │ * 官方   │ ✅  │
78
- ├────────────────────────────────────┼───────────┼──────────┤
79
- │  https://taobao.com  │  tao bao │ ✅ │
80
- ├────────────────────────────────────┼───────────┼──────────┤
81
- │  https://mirrors.tencent.com/npm  │  腾讯   │ ✅  │
82
- ├────────────────────────────────────┼───────────┼──────────┤
83
- │  https://npmreg.proxy.ustclug.org │ 中科大   │ ✅  │
84
- ├────────────────────────────────────┼───────────┼──────────┤
85
- │  https://registry.yarnpkg.com  │  yarn  │ ✅  │
86
- ├────────────────────────────────────┼───────────┼──────────┤
87
- │  https://earthnut.dev  │  earthnut│ ✅  │
88
- └────────────────────────────────────┴───────────┴──────────┘
89
-
90
- 注:当前可见状态仅影响 npx nry 选择项
91
- # 添加新项后问询是否新添加或退出
92
- ▶︎ 添加完成,是否持续添加: 退出 继续添加
93
- ```
94
-
95
- 本来考虑是否在添加后直接配置新添加项为当前项,思之再三,专命令专用*该命令仅添加新的 npm registry,添加后并不设置该值为当前值*。
96
-
97
- ### 删除项
98
-
99
- 删除项,除了当前使用项,其他项均可以被删除,不限于自定义的项。
100
-
101
- ```bash
102
- # 常规使用删除
103
- npx nry delete
104
- # 缩写项删除
105
- npx nry del
106
- ```
107
-
108
- 效果:
109
-
110
- ```bash
111
- # 先展示交互选项,当前使用项不可被选中
112
- ▶︎ 请选择要删除的项
113
-
114
- ⊗ 官方(当前使用)
115
- ◦ tao bao
116
- ◦ 腾讯
117
- ◦ 中科大
118
- ● yarn
119
- ◦ earthnut
120
-
121
- https://registry.yarnpkg.com
122
-
123
- # 删除后展示
124
-
125
- 删除项后的列表为:
126
- ┌────────────────────────────────────┬───────────┬──────────┐
127
- │ npm registry  │ 别名  │ 当前可见  │
128
- ├────────────────────────────────────┼───────────┼──────────┤
129
- │ * https://registry.npmjs.org  │ * 官方  │ ✅  │
130
- ├────────────────────────────────────┼───────────┼──────────┤
131
- │  https://taobao.com  │  tao bao │ ✅  │
132
- ├────────────────────────────────────┼───────────┼──────────┤
133
- │  https://mirrors.tencent.com/npm  │  腾讯   │ ✅  │
134
- ├────────────────────────────────────┼───────────┼──────────┤
135
- │  https://npmreg.proxy.ustclug.org │  中科大  │ ✅  │
136
- ├────────────────────────────────────┼───────────┼──────────┤
137
- │  https://lmssee.com  │  lmssee  │ ✅  │
138
- └────────────────────────────────────┴───────────┴──────────┘
139
-
140
- 注:当前可见状态仅影响 npx nry 选择项
141
- # 问询是否进行再次删除或直接退出
142
- ▶︎ 是否继续删除其他项: 退出 继续删除
143
- # 若是选择了继续删除,则重复上述步骤
144
- ```
145
-
146
- ### 编辑项
147
-
148
- 编辑已有项,但*不切换项*,仅作 npm registry 的值更改
149
-
150
- ```bash
151
- # 常规的使用
152
- npx nry edit
153
- # 缩写的使用
154
- npx nry ed
155
- ```
156
-
157
- 效果在展示:
158
-
159
- ```bash
160
- # 先展示交互选择需要更改的项
161
- ▶︎ 请选择你想要修改的项
162
-
163
- ● 官方(当前使用)
164
- ◦ tao bao
165
- ◦ 腾讯
166
- ◦ 中科大
167
- ◦ yarn
168
- ◦ earthnut
169
-
170
- https://registry.npmjs.org
171
- # 然后在选择后更改 npm registry 值,直接回车,默认不更改
172
- ▶︎ 请更改为新的 npm registry 值: https://earthnut.dev
173
- # 接着更改选择项的 npm registry 的别名 ,默认不更改
174
- ▶︎ 请更改为新的 npm registry 别名: earthnut
175
- # 展示效果并问询是否依旧继续修改或退出
176
- 更改后的列表为:
177
- ┌────────────────────────────────────┬─────────────┬──────────┐
178
- │ npm registry  │ 别名  │ 当前可见  │
179
- ├────────────────────────────────────┼─────────────┼──────────┤
180
- │ * https://registry.npmjs.org  │ * 官方  │ ✅  │
181
- ├────────────────────────────────────┼─────────────┼──────────┤
182
- │  https://taobao.com  │  tao bao  │ ✅  │
183
- ├────────────────────────────────────┼─────────────┼──────────┤
184
- │  https://mirrors.tencent.com/npm  │  腾讯  │ ✅  │
185
- ├────────────────────────────────────┼─────────────┼──────────┤
186
- │  https://npmreg.proxy.ustclug.org │ 中科大  │ ✅  │
187
- ├────────────────────────────────────┼─────────────┼──────────┤
188
- │  https://earthnut.dev  │  earthtnut │ ✅  │
189
- └────────────────────────────────────┴─────────────┴──────────┘
190
-
191
- 注:当前可见状态仅影响 npx nry 选择项
192
- ▶︎ 是否继续修改其他项: 退出 继续修改
193
- ```
194
-
195
- ### 展示当前项状态
196
-
197
- ```bash
198
- # 常规使用
199
- npx nry list
200
- # 缩写调用
201
- npx nry ls
202
- ```
203
-
204
- 效果展示:
205
-
206
- ```bash
207
- ┌────────────────────────────────────┬─────────────┬──────────┐
208
- │ npm registry  │ 别名  │ 当前可见  │
209
- ├────────────────────────────────────┼─────────────┼──────────┤
210
- │ * https://registry.npmjs.org  │ * 官方  │ ✅  │
211
- ├────────────────────────────────────┼─────────────┼──────────┤
212
- │  https://taobao.com  │  tao bao  │ ✅  │
213
- ├────────────────────────────────────┼─────────────┼──────────┤
214
- │  https://mirrors.tencent.com/npm  │  腾讯  │ ❌  │
215
- ├────────────────────────────────────┼─────────────┼──────────┤
216
- │  https://npmreg.proxy.ustclug.org │ 中科大  │ ✅  │
217
- ├────────────────────────────────────┼─────────────┼──────────┤
218
- │  https://earthnut.dev  │  earthnut  │ ❌  │
219
- └────────────────────────────────────┴─────────────┴──────────┘
220
-
221
- 注:当前可见状态仅影响 npx nry 选择项
222
- ```
223
-
224
- ### 管理所有项的显隐
225
-
226
- 使用 [a-command](https://www.npmjs.com/package/a-command) 的多选,所以可以*使用`ctrl + A` 全选,使用 `ctrl + Z` 全不选,使用 `ctrl + R` 全反选*。而与删除命令类似,不作用于当前使用项。
227
-
228
- ```bash
229
- # 常规使用项
230
- npx nry manage
231
- # 缩写使用
232
- npx nry mg
233
- ```
234
-
235
- 效果展示:
236
-
237
- ```bash
238
- # 使用上下键切换焦点项,使用空格或左右键切换状态
239
- ▶︎ 请使用键盘选择,请使用 Enter 键进行选择
240
-
241
- ▣ 官方
242
- ■ tao bao
243
- □ 腾讯
244
- ■ 中科大
245
- □ earthnut
246
-
247
- https://registry.npmmirror.com
248
- # 按下 enter 键后保存状态
249
-
250
- ┌────────────────────────────────────┬─────────────┬──────────┐
251
- │ npm registry  │ 别名  │ 当前可见  │
252
- ├────────────────────────────────────┼─────────────┼──────────┤
253
- │ * https://registry.npmjs.org  │ * 官方  │ ✅  │
254
- ├────────────────────────────────────┼─────────────┼──────────┤
255
- │  https://taobao.com  │  tao bao  │ ✅  │
256
- ├────────────────────────────────────┼─────────────┼──────────┤
257
- │  https://mirrors.tencent.com/npm  │  腾讯  │ ✅  │
258
- ├────────────────────────────────────┼─────────────┼──────────┤
259
- │  https://npmreg.proxy.ustclug.org │ 中科大  │ ✅  │
260
- ├────────────────────────────────────┼─────────────┼──────────┤
261
- │  https://earthnut.dev  │  earthnut  │ ❌  │
262
- └────────────────────────────────────┴─────────────┴──────────┘
263
-
264
- 注:当前可见状态仅影响 npx nry 选择项
265
- ```
266
-
267
- ### 重置所有当前值
268
-
269
- 有时候,将值改的乱七八糟,就需要恢复原有,但*这么操作将丢失所有的自定义的项*。
270
-
271
- ```bash
272
- # 常规使用
273
- npx nry reset
274
- # 缩写调用
275
- npx nry rs
276
- ```
277
-
278
- 效果展示
279
-
280
- ```bash
281
- # 重置前再次询问
282
- ▶︎ 请确认是否执行覆盖原数据,该操作无法复原: 退出 重置
283
- # 选择重置
284
- 写入成功
285
- ┌────────────────────────────────────┬──────────┬──────────┐
286
- │ npm registry  │ 别名  │ 当前可见  │
287
- ├────────────────────────────────────┼──────────┼──────────┤
288
- │ * https://registry.npmjs.org  │ * 官方  │ ✅  │
289
- ├────────────────────────────────────┼──────────┼──────────┤
290
- │  https://registry.npmmirror.com  │  淘宝  │ ✅  │
291
- ├────────────────────────────────────┼──────────┼──────────┤
292
- │  https://mirrors.tencent.com/npm  │  腾讯  │ ✅  │
293
- ├────────────────────────────────────┼──────────┼──────────┤
294
- │  https://npmreg.proxy.ustclug.org │ 中科大  │ ✅  │
295
- ├────────────────────────────────────┼──────────┼──────────┤
296
- │  https://registry.yarnpkg.com  │  yarn  │ ✅  │
297
- └────────────────────────────────────┴──────────┴──────────┘
298
-
299
- 注:当前可见状态仅影响 npx nry 选择项
300
- ```
35
+ 相应的,对应的包管理器调用执行仅用于设置本包管理器的 `registry`。
301
36
 
302
37
  ## 文档地址
303
38
 
304
- 参看 [https://earthnut.dev/nry](https://earthnut.dev/nry)
39
+ 参看 [nry](https://earthnut.dev/npm/nry)
package/bin.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{Dog as a}from"@qqi/log";import{isFalse as t,isArray as e,isString as i,isBusinessEmptyString as n,isUndefined as r}from"a-type-of-js";import{QQI as l}from"qqi";import{escapeRegExp as o}from"a-js-tools";import{brightRedPen as s,brightCyanPen as c,greenPen as u,cyanPen as f,magentaPen as p,brightBlackPen as w,bluePen as m}from"color-pen";import{Command as d}from"a-command";import{typewrite as g,cursorShow as b,runOtherCode as v,_p as y}from"a-node-tools";import{Table as h}from"colored-table";const $=new a({name:"nry",type:!1});t($.type);const q=new l("nry");function x(a=!1){const t=[{value:"https://registry.npmjs.org",label:"官方",tip:"https://registry.npmjs.org"},{value:"https://registry.npmmirror.com",label:"淘宝",tip:"https://registry.npmmirror.com"},{value:"https://mirrors.tencent.com/npm",label:"腾讯",tip:"https://mirrors.tencent.com/npm"},{value:"https://npmreg.proxy.ustclug.org",label:"中科大",tip:"https://npmreg.proxy.ustclug.org"},{value:"https://registry.yarnpkg.com",label:"yarn",tip:"https://registry.yarnpkg.com"}];if(a)return t;if(!q.available)return t;const r=q.read("config");return e(r)&&r.every((a=>i(a.value)&&!n(a.label)&&i(a.value)&&!n(a.value)))?r:t}const k=new d("nry");async function E(a="好的,即将退出"){return n(a)||await g(a),b(),k.end()}function j(a){if(!q.available)return!1;const t={value:a.value,label:a.label.toString(),tip:a.value,disable:!1},e=q.read("config");return e.push(t),q.write("config",e)}async function V(){const a=await v("npm config get registry");if($("获取当前的本地配置为",a),a.success)return a.data.replace(/\s/gm,"")}async function L(){const a=x(),t=await V(),e=new h({header:["npm registry","别名","当前可见"]});!(a.findIndex((a=>a.value===t))>-1)&&i(t)&&a.push({value:t,tip:t,label:"曾用值"}),a.forEach((a=>e.addRow([(t===a.value?p`* `:" ").concat(a.value),(t===a.value?p`* `:" ").concat(u(a.label)),a.disable?"❌":"✅"]))),e(),y(w`注:当前可见状态仅影响 npx nry 选择项`)}async function S(){if(!q.available)return await E("读写受限,正在退出");const a=x(),t=await async function(a){const t=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}];a.forEach((a=>{t.push({reg:new RegExp(`^${o(a.value)}$`,"mg"),info:`${u(a.value)}(${f(a.label)}) 已存在`,inverse:!0})}));const e=await k.question({text:"请输入自定义的 npm 的源地址",tip:"https://registry.npmjs.org",minLen:5,maxLen:120,verify:t,required:!1});return $("用户输入的地址",e),r(e)?await E():e}(a),e=await async function(a){const t=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}];a.forEach((a=>{t.push({reg:new RegExp(`^${o(a.label)}$`,"mg"),info:`${u(a.label)}(${f(a.value)}) 已存在`,inverse:!0})}));const e=await k.question({text:"请输入自定义的 npm 的别名",tip:"任意别名",minLen:1,maxLen:120,verify:t,defaultValue:"",required:!1});return $("用户输入的别名为",e),r(e)?await E():e}(a);if(j({value:t,label:e})){y(w`当前的 npm registry 列表为`),await L();const a=["退出","继续添加"],t=await k.question({text:"添加完成,是否持续添加",tip:a});return r(t)||t===a[0]?await E(""):await S()}return await E(`写入${s`失败`},原因未知`)}async function M(a="请选择想使用的新的 npm registry",e=!0,i=!0){let n=!1;const l=x(),o=await V();if(!r(o)){for(const a of l)if(a.value===o){a.label=a.label.toString()+`(${p`当前使用`})`,a.disable=!i,n=!0;break}if(t(n)){const a={value:o,label:"当前使用值",disable:!i};l.push(a),q.available&&j({value:o,label:"曾用值"})}}$("处理完的数据",l);const s=e?l.filter((a=>!a.disable||a.disable&&a.value===o)):l.map((a=>(a.value===o?a.disable=!i:a.disable=!1,a))),c=await k.selection({data:s,info:a},"number");return $("用户选择的项",c),r(c)?await E():($("当前用户选择为",s[c]),s[c])}async function R(){const a=await M();await async function(a){(await v(`npm config set registry ${a.value}`)).success||await E(),y(`已将 npm registry 更改为 ${u(a.value)}(${m(a.label)})`)}(a)}k.bind(["add <a> (用于添加一个自定义的 npm 源)","edit <ed> (用于编辑源) ","delete <del> (用于移除某个或多个自定义的项)","list <ls> (用于展示当前的所有的源)","manage <mg> (用于管理当前源在列表中的显隐)",`reset <rs> (重制当前的源,将${s`永久移除自定义源`}、${c`恢复已更改的源`})`]).run().isEnd(!0);const I={add:!1,edit:!1,delete:!1,manage:!1,list:!1,noMatch:!1,reset:!1};async function N(){if(!q.available)return await E("当前读写受限,即将退出程序");const a=await M("请选择要删除的项",!1,!1),{value:t,label:e}=a,i=x();for(const a in i){const n=Number(a),r=i[n];if(r.value===t&&r.label===e){i.splice(n,1);break}}if(q.write("config",i)){y("删除项后的列表为:"),await L();const a=["退出","继续删除"],t=await k.question({text:"是否继续删除其他项",tip:a});return r(t)||t===a[0]?await E(""):await N()}}async function z(){if(!q.available)return await E("当前读写权限不足,即将退出程序");const a=await M("请选择你想要修改的项",!1),{value:t,label:e}=a;$("获取用户的选择",a),$("原始的值",t),$("原始的标签",e),await async function(a){const t=await k.question({text:"请更改为新的 npm registry 值",tip:a.value,defaultValue:a.value,required:!1});$("新值为",t),r(t)||(a.value=a.tip=t)}(a),await async function(a){const t=await k.question({text:"请更改为新的 npm registry 别名",tip:a.label,defaultValue:a.label.toString(),required:!1});$("新值为",t),r(t)||(a.label=t)}(a);const{value:i,label:n}=a;$("更改后的值",i),$("更改的标签",n);const l=x();for(const a of l)if(a.value===t&&a.label===e){a.value=i,a.label=n.toString();break}if(q.write("config",l)){y("更改后的列表为:"),await L();const a=["退出","继续修改"],t=await k.question({text:"是否继续修改其他项",tip:a});return r(t)||t===a[0]?await E(""):await z()}}async function A(){return function(){const a=k.args,e=a.$map;$("源解析值",a),$("源解析值没有匹配项",a.$isVoid),["add","delete","edit","list","manage","reset"].forEach((a=>I[a]=t(r(e[a])))),I.noMatch=a.$isVoid,$("解析完的值",I)}(),$("执行"),I.noMatch?($("当前没有匹配值"),await R()):I.reset?($("重置项"),await async function(){if(!q.available)return await E("当前读写权限受限,正在退出程序");const a=["退出","重置"],t=await k.question({text:"请确认是否执行覆盖原数据,该操作无法复原",tip:a});return r(t)||t===a[0]?await E("好的,这就退出重置"):q.write("config",x(!0))?(await g("写入"+u`成功`,60),await L()):await E("重置未能完成,原因未知")}()):I.list?($("当前为展示项"),await L()):I.manage?($("当前执行状态更改"),await async function(){if(!q.available)return await E("当前读写受限,即将退出程序。");const a=x(),t=await V(),e=await k.selection({data:a.map((a=>({...a,checked:!a.disable,disable:a.value===t}))),kind:"check"},"number");if($("交互结果",e),r(e))return await E("好的,将退出状态显隐管理");a.forEach(((a,t)=>{a.disable=!e.includes(t)})),$("保存前的数据",a),q.write("config",a)&&await L()}()):I.add?($("添加新的项"),await S()):I.edit?($("编辑项"),await z()):I.delete?($("删除项"),await N()):void 0}(async()=>{try{await A()}catch(a){$.error("系统级捕获 错误",a)}})();
2
+ import{Dog as a}from"@qqi/log";import{isFalse as t,isArray as e,isString as n,isBusinessEmptyString as i,isUndefined as r}from"a-type-of-js";import{QQI as s}from"qqi";import{escapeRegExp as o}from"a-js-tools";import{brightRedPen as l,brightCyanPen as c,greenPen as u,cyanPen as p,magentaPen as g,brightBlackPen as f,bluePen as w}from"color-pen";import{Command as m}from"a-command";import{typewrite as d,cursorShow as v,runOtherCode as b,_p as y}from"a-node-tools";import{Table as h}from"colored-table";const $=new a({name:"nry",type:!1});t($.type);const k=new s("nry");function q(a=!1){const t=[{value:"https://registry.npmjs.org",label:"官方",tip:"https://registry.npmjs.org"},{value:"https://registry.npmmirror.com",label:"淘宝",tip:"https://registry.npmmirror.com"},{value:"https://mirrors.tencent.com/npm",label:"腾讯",tip:"https://mirrors.tencent.com/npm"},{value:"https://npmreg.proxy.ustclug.org",label:"中科大",tip:"https://npmreg.proxy.ustclug.org"},{value:"https://registry.yarnpkg.com",label:"yarn",tip:"https://registry.yarnpkg.com"}];if(a)return t;if(!k.available)return t;const r=k.read("config");return e(r)&&r.every(a=>n(a.value)&&!i(a.label)&&n(a.value)&&!i(a.value))?r:t}const x=new m("nry");async function M(a="好的,即将退出"){return i(a)||await d(a),v(),x.end()}x.bind(["add <a> (用于添加一个自定义的 npm、yarn、pnpm 源)","edit <ed> (用于编辑源) ","delete <del> (用于移除某个或多个自定义的项)","list <ls> (用于展示当前的所有的源)","manage <mg> (用于管理当前源在列表中的显隐)",`reset <rs> (重制当前的源,将${l`永久移除自定义源`}、${c`恢复已更改的源`})`]).run().isEnd(!0);const E={add:!1,edit:!1,delete:!1,manage:!1,list:!1,noMatch:!1,reset:!1},_={pkgManager:function(){const a=process.env.npm_config_user_agent||"";return a.includes("pnpm")?"pnpm":a.includes("yarn")?"yarn":a.includes("npm")?"npm":process.env.PNPM_HOME?"pnpm":process.env.YARN_IGNORE_PATH?"yarn":"npm"}()};function j(a){if(!k.available)return!1;const t={value:a.value,label:a.label.toString(),tip:a.value,disable:!1},e=k.read("config");return e.push(t),k.write("config",e)}async function R(){const{pkgManager:a}=_,t=await b(`${a} config get registry`);if($("获取当前的本地配置为",t),t.success)return t.data.replace(/\s/gm,"")}async function V(){const{pkgManager:a}=_,t=q(),e=await R(),i=new h({header:[`${a} registry 源`,"别名","当前可见"]});!(t.findIndex(a=>a.value===e)>-1)&&n(e)&&t.push({value:e,tip:e,label:"曾用值"}),t.forEach(a=>i.addRow([(e===a.value?g`* `:" ").concat(a.value),(e===a.value?g`* `:" ").concat(u(a.label)),a.disable?"❌":"✅"])),i(),y(f`注:当前可见状态仅影响 npx nry 选择项`)}async function L(){if(!k.available)return await M("读写受限,正在退出");const{pkgManager:a}=_,t=q(),e=await async function(a){const{pkgManager:t}=_,e=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}];a.forEach(a=>{e.push({reg:new RegExp(`^${o(a.value)}$`,"mg"),info:`${u(a.value)}(${p(a.label)}) 已存在`,inverse:!0})});const n=await x.question({text:"请输入自定义的源地址",tip:"yarn"===t?"https://registry.yarnpkg.com":"https://registry.npmjs.org",minLen:5,maxLen:120,verify:e,required:!1});return $("用户输入的地址",n),r(n)?await M():n}(t),n=await async function(a){const t=[{reg:/\s+/g,info:"不允许出现空格",inverse:!0}],{pkgManager:e}=_;a.forEach(a=>{t.push({reg:new RegExp(`^${o(a.label)}$`,"mg"),info:`${u(a.label)}(${p(a.value)}) 已存在`,inverse:!0})});const n=await x.question({text:`请输入自定义的 ${e} 的别名`,tip:"任意别名",minLen:1,maxLen:120,verify:t,defaultValue:"",required:!1});return $("用户输入的别名为",n),r(n)?await M():n}(t);if(j({value:e,label:n})){y(f`当前的 ${a} registry 源列表为`),await V();const t=["退出","继续添加"],e=await x.question({text:"添加完成,是否持续添加",tip:t});return r(e)||e===t[0]?await M(""):await L()}return await M(`写入${l`失败`},原因未知`)}async function N(a="",e=!0,n=!0){i(a)&&(a=`请选择想使用的新的 ${_.pkgManager} registry 源`);let s=!1;const o=q(),l=await R();if(!r(l)){for(const a of o)if(a.value===l){a.label=a.label.toString()+`(${g`当前使用`})`,a.disable=!n,s=!0;break}if(t(s)){const a={value:l,label:"当前使用值",disable:!n};o.push(a),k.available&&j({value:l,label:"曾用值"})}}$("处理完的数据",o);const c=e?o.filter(a=>!a.disable||a.disable&&a.value===l):o.map(a=>(a.value===l?a.disable=!n:a.disable=!1,a)),u=await x.selection({data:c,info:a},"number");return $("用户选择的项",u),r(u)?await M():($("当前用户选择为",c[u]),c[u])}async function S(){const a=await N();await async function(a){const{pkgManager:t}=_;(await b(`${t} config set registry ${a.value}`)).success||await M(),y(`已将 ${t} registry 更改为 ${u(a.value)}(${w(a.label)})`)}(a)}async function P(){if(!k.available)return await M("当前读写受限,即将退出程序");const a=await N("请选择要删除的项",!1,!1),{value:t,label:e}=a,n=q();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(k.write("config",n)){y("删除项后的列表为:"),await V();const a=["退出","继续删除"],t=await x.question({text:"是否继续删除其他项",tip:a});return r(t)||t===a[0]?await M(""):await P()}}async function A(){if(!k.available)return await M("当前读写权限不足,即将退出程序");const a=await N("请选择你想要修改的项",!1),{value:t,label:e}=a;$("获取用户的选择",a),$("原始的值",t),$("原始的标签",e),await async function(a){const{pkgManager:t}=_,e=await x.question({text:`请更改为新的 ${t} registry 值`,tip:a.value,defaultValue:a.value,required:!1});$("新值为",e),r(e)||(a.value=a.tip=e)}(a),await async function(a){const{pkgManager:t}=_,e=await x.question({text:`请更改为新的 ${t} registry 别名`,tip:a.label,defaultValue:a.label.toString(),required:!1});$("新值为",e),r(e)||(a.label=e)}(a);const{value:n,label:i}=a;$("更改后的值",n),$("更改的标签",i);const s=q();for(const a of s)if(a.value===t&&a.label===e){a.value=n,a.label=i.toString();break}if(k.write("config",s)){y("更改后的列表为:"),await V();const a=["退出","继续修改"],t=await x.question({text:"是否继续修改其他项",tip:a});return r(t)||t===a[0]?await M(""):await A()}}async function H(){return function(){const a=x.args,e=a.$map;$("源解析值",a),$("源解析值没有匹配项",a.$isVoid),["add","delete","edit","list","manage","reset"].forEach(a=>E[a]=t(r(e[a]))),E.noMatch=a.$isVoid,$("解析完的值",E)}(),$("执行"),E.noMatch?($("当前没有匹配值"),await S()):E.reset?($("重置项"),await async function(){if(!k.available)return await M("当前读写权限受限,正在退出程序");const a=["退出","重置"],t=await x.question({text:"请确认是否执行覆盖原数据,该操作无法复原",tip:a});return r(t)||t===a[0]?await M("好的,这就退出重置"):k.write("config",q(!0))?(await d("写入"+u`成功`,60),await V()):await M("重置未能完成,原因未知")}()):E.list?($("当前为展示项"),await V()):E.manage?($("当前执行状态更改"),await async function(){if(!k.available)return await M("当前读写受限,即将退出程序。");const a=q(),t=await R(),e=await x.selection({data:a.map(a=>({...a,checked:!a.disable,disable:a.value===t})),kind:"check"},"number");if($("交互结果",e),r(e))return await M("好的,将退出状态显隐管理");a.forEach((a,t)=>{a.disable=!e.includes(t)}),$("保存前的数据",a),k.write("config",a)&&await V()}()):E.add?($("添加新的项"),await L()):E.edit?($("编辑项"),await A()):E.delete?($("删除项"),await P()):void 0}(async()=>{try{await H()}catch(a){$.error("系统级捕获 错误",a),console.log("当前出现未知错误",a)}})();
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "nry",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
- "description": "更替及管理 npm registry",
5
+ "description": "更替及管理 npm、yarn、pnpm registry",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@qqi/log": "^0.1.0",
8
+ "@qqi/log": "^0.1.1",
9
9
  "a-command": "^2.3.13",
10
- "a-js-tools": "^1.0.8",
11
- "a-node-tools": "^4.2.16",
12
- "a-type-of-js": "^1.0.5",
13
- "color-pen": "^2.0.12",
14
- "colored-table": "^0.0.2",
15
- "qqi": "^0.1.0"
10
+ "a-js-tools": "^1.0.10",
11
+ "a-node-tools": "^4.2.19",
12
+ "a-type-of-js": "^1.0.7",
13
+ "color-pen": "^2.0.13",
14
+ "colored-table": "^0.1.0",
15
+ "qqi": "^0.1.1"
16
16
  },
17
17
  "publishConfig": {
18
18
  "access": "public",
@@ -40,7 +40,7 @@
40
40
  "nry",
41
41
  "earthnut"
42
42
  ],
43
- "homepage": "https://earthnut.dev",
43
+ "homepage": "https://earthnut.dev/npm/nry",
44
44
  "bugs": {
45
45
  "url": "https://github.com/earthnutDev/nry/issues",
46
46
  "email": "earthnut.dev@outlook.com"