nry 0.0.1 → 0.0.3
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/README.md +297 -0
- package/bin.mjs +2 -0
- package/package.json +7 -25
- package/index.mjs +0 -515
package/README.md
CHANGED
|
@@ -2,6 +2,303 @@
|
|
|
2
2
|
|
|
3
3
|
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/nry) [?logo=github>)](https://github.com/earthnutDev/nry/issues)
|
|
4
4
|
|
|
5
|
+
一个仅用于 npm registry 切换的工具。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
可全局安装,亦可直接使用 `npx` 使用即可
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g nry
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
本应用使用 [a-command](https://www.npmjs.com/package/a-command) ,所以屏蔽了 `Ctrl + C` 、`Ctrl + D` ,但可采用*双击 `Esc` 退出*。
|
|
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 |
|
|
28
|
+
|
|
29
|
+
额,因为文档没啥写的,所以就有了下面的*执行展示*。
|
|
30
|
+
|
|
31
|
+
### 简单使用
|
|
32
|
+
|
|
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
|
+
```
|
|
301
|
+
|
|
5
302
|
## 文档地址
|
|
6
303
|
|
|
7
304
|
参看 [https://earthnut.dev/nry](https://earthnut.dev/nry)
|
package/bin.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{Dog as a}from"@qqi/dev-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)}})();
|
package/package.json
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "index.cjs",
|
|
3
|
-
"module": "index.mjs",
|
|
4
|
-
"types": "index.d.ts",
|
|
5
2
|
"name": "nry",
|
|
6
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
7
4
|
"type": "module",
|
|
8
5
|
"description": "",
|
|
9
6
|
"license": "MIT",
|
|
10
7
|
"dependencies": {
|
|
11
8
|
"@qqi/dev-log": "^1.0.4",
|
|
12
|
-
"a-command": "^2.3.
|
|
13
|
-
"a-js-tools": "^1.0.
|
|
14
|
-
"a-node-tools": "^4.2.
|
|
15
|
-
"a-type-of-js": "^1.0.
|
|
16
|
-
"color-pen": "^2.0.
|
|
9
|
+
"a-command": "^2.3.9",
|
|
10
|
+
"a-js-tools": "^1.0.1",
|
|
11
|
+
"a-node-tools": "^4.2.9",
|
|
12
|
+
"a-type-of-js": "^1.0.2",
|
|
13
|
+
"color-pen": "^2.0.11",
|
|
17
14
|
"colored-table": "^0.0.2",
|
|
18
15
|
"qqi": "^0.0.4"
|
|
19
16
|
},
|
|
@@ -22,23 +19,8 @@
|
|
|
22
19
|
"registry": "https://registry.npmjs.org/"
|
|
23
20
|
},
|
|
24
21
|
"files": [
|
|
25
|
-
"
|
|
26
|
-
"index.mjs",
|
|
27
|
-
"index.cjs",
|
|
28
|
-
"src"
|
|
22
|
+
"bin.mjs"
|
|
29
23
|
],
|
|
30
|
-
"exports": {
|
|
31
|
-
".": {
|
|
32
|
-
"import": {
|
|
33
|
-
"default": "./index.mjs",
|
|
34
|
-
"types": "./index.d.ts"
|
|
35
|
-
},
|
|
36
|
-
"require": {
|
|
37
|
-
"default": "./index.cjs",
|
|
38
|
-
"types": "./index.d.ts"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
24
|
"repository": {
|
|
43
25
|
"type": "git",
|
|
44
26
|
"url": "git+https://github.com/earthnutDev/nry.git"
|
package/index.mjs
DELETED
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Dog } from '@qqi/dev-log';
|
|
3
|
-
import { isFalse, isArray, isString, isBusinessEmptyString, isUndefined } from 'a-type-of-js';
|
|
4
|
-
import { QQI } from 'qqi';
|
|
5
|
-
import { escapeRegExp } from 'a-js-tools';
|
|
6
|
-
import { brightRedPen, brightCyanPen, greenPen, cyanPen, magentaPen, brightBlackPen, bluePen } from 'color-pen';
|
|
7
|
-
import { Command } from 'a-command';
|
|
8
|
-
import { typewrite, cursorShow, runOtherCode, _p } from 'a-node-tools';
|
|
9
|
-
import { Table } from 'colored-table';
|
|
10
|
-
|
|
11
|
-
const dog = new Dog({
|
|
12
|
-
name: 'nry',
|
|
13
|
-
type: false,
|
|
14
|
-
});
|
|
15
|
-
isFalse(dog.type);
|
|
16
|
-
|
|
17
|
-
const qqi = new QQI('nry');
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 创建原始的数据
|
|
21
|
-
*
|
|
22
|
-
* @param [reset=false] 是否为重置,该情况下直接返回原始值进行覆盖
|
|
23
|
-
*/
|
|
24
|
-
function getOriginData(reset = false) {
|
|
25
|
-
const originData = [
|
|
26
|
-
{
|
|
27
|
-
value: 'https://registry.npmjs.org',
|
|
28
|
-
label: '官方',
|
|
29
|
-
tip: 'https://registry.npmjs.org',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
value: 'https://registry.npmmirror.com',
|
|
33
|
-
label: '淘宝',
|
|
34
|
-
tip: 'https://registry.npmmirror.com',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
value: 'https://mirrors.tencent.com/npm',
|
|
38
|
-
label: '腾讯',
|
|
39
|
-
tip: 'https://mirrors.tencent.com/npm',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
value: 'https://npmreg.proxy.ustclug.org',
|
|
43
|
-
label: '中科大',
|
|
44
|
-
tip: 'https://npmreg.proxy.ustclug.org',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
value: 'https://registry.yarnpkg.com',
|
|
48
|
-
label: 'yarn',
|
|
49
|
-
tip: 'https://registry.yarnpkg.com',
|
|
50
|
-
},
|
|
51
|
-
];
|
|
52
|
-
// 重置默认返回原始值
|
|
53
|
-
if (reset)
|
|
54
|
-
return originData;
|
|
55
|
-
// 读写受限返回原始值
|
|
56
|
-
if (!qqi.available)
|
|
57
|
-
return originData;
|
|
58
|
-
const localConfig = qqi.read('config');
|
|
59
|
-
if (isArray(localConfig) &&
|
|
60
|
-
localConfig.every(e => isString(e.value) &&
|
|
61
|
-
!isBusinessEmptyString(e.label) &&
|
|
62
|
-
isString(e.value) &&
|
|
63
|
-
!isBusinessEmptyString(e.value))) {
|
|
64
|
-
return localConfig;
|
|
65
|
-
}
|
|
66
|
-
// 默认返回原始值
|
|
67
|
-
return originData;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const command = new Command('nry');
|
|
71
|
-
command
|
|
72
|
-
.bind([
|
|
73
|
-
'add <a> (用于添加一个自定义的 npm 源)',
|
|
74
|
-
'edit <ed> (用于编辑源) ',
|
|
75
|
-
'delete <del> (用于移除某个或多个自定义的项)',
|
|
76
|
-
'list <ls> (用于展示当前的所有的源)',
|
|
77
|
-
'manage <mg> (用于管理当前源在列表中的显隐)',
|
|
78
|
-
`reset <rs> (重制当前的源,将${brightRedPen `永久移除自定义源`}、${brightCyanPen `恢复已更改的源`})`,
|
|
79
|
-
])
|
|
80
|
-
.run()
|
|
81
|
-
.isEnd(true);
|
|
82
|
-
|
|
83
|
-
/** 退出程序 */
|
|
84
|
-
async function exitProgram(str = '好的,即将退出') {
|
|
85
|
-
if (!isBusinessEmptyString(str))
|
|
86
|
-
await typewrite(str);
|
|
87
|
-
cursorShow();
|
|
88
|
-
return command.end();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
async function getValue(originData) {
|
|
95
|
-
const valueVerify = [
|
|
96
|
-
{
|
|
97
|
-
reg: /\s+/g,
|
|
98
|
-
info: '不允许出现空格',
|
|
99
|
-
inverse: true,
|
|
100
|
-
},
|
|
101
|
-
];
|
|
102
|
-
originData.forEach(e => {
|
|
103
|
-
valueVerify.push({
|
|
104
|
-
reg: new RegExp(`^${escapeRegExp(e.value)}$`, 'mg'),
|
|
105
|
-
info: `${greenPen(e.value)}(${cyanPen(e.label)}) 已存在`,
|
|
106
|
-
inverse: true,
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
const value = await command.question({
|
|
110
|
-
text: '请输入自定义的 npm 的源地址:',
|
|
111
|
-
tip: 'https://registry.npmjs.org',
|
|
112
|
-
minLen: 5,
|
|
113
|
-
maxLen: 120,
|
|
114
|
-
verify: valueVerify,
|
|
115
|
-
required: false,
|
|
116
|
-
});
|
|
117
|
-
dog('用户输入的地址', value);
|
|
118
|
-
if (isUndefined(value))
|
|
119
|
-
return await exitProgram();
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
*
|
|
125
|
-
*/
|
|
126
|
-
function localAdd(item) {
|
|
127
|
-
// 读写受限
|
|
128
|
-
if (!qqi.available)
|
|
129
|
-
return false;
|
|
130
|
-
/** 新添加项 */
|
|
131
|
-
const writeItem = {
|
|
132
|
-
value: item.value,
|
|
133
|
-
label: item.label.toString(),
|
|
134
|
-
tip: item.value,
|
|
135
|
-
disable: false,
|
|
136
|
-
};
|
|
137
|
-
/// 本地原有数据
|
|
138
|
-
const localConfig = qqi.read('config');
|
|
139
|
-
/// 新添加的数据
|
|
140
|
-
localConfig.push(writeItem);
|
|
141
|
-
return qqi.write('config', localConfig);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** 获取 label */
|
|
145
|
-
async function getLabel(originData) {
|
|
146
|
-
const valueVerify = [
|
|
147
|
-
{
|
|
148
|
-
reg: /\s+/g,
|
|
149
|
-
info: '不允许出现空格',
|
|
150
|
-
inverse: true,
|
|
151
|
-
},
|
|
152
|
-
];
|
|
153
|
-
originData.forEach(e => {
|
|
154
|
-
valueVerify.push({
|
|
155
|
-
reg: new RegExp(`^${escapeRegExp(e.label)}$`, 'mg'),
|
|
156
|
-
info: `${greenPen(e.label)}(${cyanPen(e.value)}) 已存在`,
|
|
157
|
-
inverse: true,
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
const value = await command.question({
|
|
161
|
-
text: '请输入自定义的 npm 的别名:',
|
|
162
|
-
tip: '任意别名',
|
|
163
|
-
minLen: 1,
|
|
164
|
-
maxLen: 120,
|
|
165
|
-
verify: valueVerify,
|
|
166
|
-
defaultValue: '',
|
|
167
|
-
required: false,
|
|
168
|
-
});
|
|
169
|
-
dog('用户输入的别名为', value);
|
|
170
|
-
if (isUndefined(value))
|
|
171
|
-
return await exitProgram();
|
|
172
|
-
return value;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** 获取当前配置的 本地的 registry */
|
|
176
|
-
async function getCurrentRegistry() {
|
|
177
|
-
const result = await runOtherCode('npm config get registry');
|
|
178
|
-
dog('获取当前的本地配置为', result);
|
|
179
|
-
if (result.success)
|
|
180
|
-
return result.data.replace(/\s/gm, '');
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/** 展示项 */
|
|
185
|
-
async function list() {
|
|
186
|
-
/** 当前数据 */
|
|
187
|
-
const data = getOriginData();
|
|
188
|
-
const current = await getCurrentRegistry();
|
|
189
|
-
const table = new Table();
|
|
190
|
-
table.setHeader(['npm registry', '别名', '当前可见']);
|
|
191
|
-
data.forEach(e => table.addRow([
|
|
192
|
-
(current === e.value ? magentaPen `* ` : ' ').concat(e.value),
|
|
193
|
-
(current === e.value ? magentaPen `* ` : ' ').concat(greenPen(e.label)),
|
|
194
|
-
e.disable ? '❌' : '✅',
|
|
195
|
-
]));
|
|
196
|
-
table(); // 渲染
|
|
197
|
-
_p(brightBlackPen `注:当前可见状态仅影响 npx nry 选择项`);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** 添加新的项 */
|
|
201
|
-
async function addItem() {
|
|
202
|
-
if (!qqi.available)
|
|
203
|
-
return await exitProgram('读写受限,正在退出');
|
|
204
|
-
const originData = getOriginData();
|
|
205
|
-
const value = await getValue(originData);
|
|
206
|
-
const label = await getLabel(originData);
|
|
207
|
-
if (localAdd({
|
|
208
|
-
value,
|
|
209
|
-
label,
|
|
210
|
-
})) {
|
|
211
|
-
_p(brightBlackPen `当前的 npm registry 列表为`);
|
|
212
|
-
await list();
|
|
213
|
-
const tip = ['退出', '继续添加'];
|
|
214
|
-
const result = await command.question({
|
|
215
|
-
text: '添加完成,是否持续添加',
|
|
216
|
-
tip,
|
|
217
|
-
});
|
|
218
|
-
if (isUndefined(result) || result === tip[0])
|
|
219
|
-
return await exitProgram('');
|
|
220
|
-
return await addItem();
|
|
221
|
-
}
|
|
222
|
-
return await exitProgram(`写入${brightRedPen `失败`},原因未知`);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* 获得要编辑的项
|
|
227
|
-
*
|
|
228
|
-
* @param [info='请选择想使用的新的 npm registry'] 展示的信息
|
|
229
|
-
* @param [filter=true] 是否过滤不可用值
|
|
230
|
-
* @param [allowCurrent=true] 是否允许当前值被选择。默认允许
|
|
231
|
-
* */
|
|
232
|
-
async function getTarget(info = '请选择想使用的新的 npm registry', filter = true, allowCurrent = true) {
|
|
233
|
-
/** 是否有当前值 */
|
|
234
|
-
let hasCurrentValue = false;
|
|
235
|
-
/** 数据 */
|
|
236
|
-
const originData = getOriginData();
|
|
237
|
-
const currentValue = await getCurrentRegistry();
|
|
238
|
-
if (!isUndefined(currentValue)) {
|
|
239
|
-
for (const e of originData) {
|
|
240
|
-
if (e.value === currentValue) {
|
|
241
|
-
e.label = e.label.toString() + `(${magentaPen `当前使用`})`;
|
|
242
|
-
e.disable = !allowCurrent;
|
|
243
|
-
hasCurrentValue = true;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (isFalse(hasCurrentValue)) {
|
|
248
|
-
const newItem = {
|
|
249
|
-
value: currentValue,
|
|
250
|
-
label: '当前使用值',
|
|
251
|
-
disable: !allowCurrent,
|
|
252
|
-
};
|
|
253
|
-
originData.push(newItem);
|
|
254
|
-
// 当前本地可写
|
|
255
|
-
if (qqi.available) {
|
|
256
|
-
localAdd({ value: currentValue, label: '曾用值' });
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
dog('处理完的数据', originData);
|
|
261
|
-
const data = filter
|
|
262
|
-
? originData.filter(e => !e.disable || (e.disable && e.value === currentValue))
|
|
263
|
-
: originData.map(e => {
|
|
264
|
-
if (e.value === currentValue) {
|
|
265
|
-
e.disable = !allowCurrent;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
e.disable = false;
|
|
269
|
-
}
|
|
270
|
-
return e;
|
|
271
|
-
});
|
|
272
|
-
/** 选择交互 */
|
|
273
|
-
const result = await command.selection({
|
|
274
|
-
data,
|
|
275
|
-
info,
|
|
276
|
-
}, 'number');
|
|
277
|
-
dog('用户选择的项', result);
|
|
278
|
-
if (isUndefined(result))
|
|
279
|
-
return await exitProgram();
|
|
280
|
-
dog('当前用户选择为', data[result]);
|
|
281
|
-
return data[result];
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** 设置新的 */
|
|
285
|
-
async function setNewRegistry(item) {
|
|
286
|
-
const result = await runOtherCode(`npm config set registry ${item.value}`);
|
|
287
|
-
if (!result.success)
|
|
288
|
-
await exitProgram();
|
|
289
|
-
_p(`已将 npm registry 更改为 ${greenPen(item.value)}(${bluePen(item.label)})`);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/** 挑选一个域 */
|
|
293
|
-
async function choose() {
|
|
294
|
-
/** 获取靶 */
|
|
295
|
-
const target = await getTarget();
|
|
296
|
-
await setNewRegistry(target);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/** 用户启动命令参数 */
|
|
300
|
-
const commandParameters = {
|
|
301
|
-
add: false,
|
|
302
|
-
edit: false,
|
|
303
|
-
delete: false,
|
|
304
|
-
manage: false,
|
|
305
|
-
list: false,
|
|
306
|
-
noMatch: false,
|
|
307
|
-
reset: false,
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* 移除项
|
|
312
|
-
*/
|
|
313
|
-
async function delItem() {
|
|
314
|
-
if (!qqi.available)
|
|
315
|
-
return await exitProgram('当前读写受限,即将退出程序');
|
|
316
|
-
const target = await getTarget('请选择要删除的项', false, false);
|
|
317
|
-
const { value, label } = target;
|
|
318
|
-
/// 获取本地的值,防止意外覆盖
|
|
319
|
-
const originData = getOriginData();
|
|
320
|
-
for (const i in originData) {
|
|
321
|
-
const index = Number(i);
|
|
322
|
-
const ele = originData[index];
|
|
323
|
-
if (ele.value === value && ele.label === label) {
|
|
324
|
-
originData.splice(index, 1);
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
const result = qqi.write('config', originData);
|
|
329
|
-
if (result) {
|
|
330
|
-
_p('删除项后的列表为:');
|
|
331
|
-
await list();
|
|
332
|
-
const tip = ['退出', '继续删除'];
|
|
333
|
-
const result = await command.question({
|
|
334
|
-
text: '是否继续删除其他项',
|
|
335
|
-
tip,
|
|
336
|
-
});
|
|
337
|
-
if (isUndefined(result) || result === tip[0])
|
|
338
|
-
return await exitProgram('');
|
|
339
|
-
return await delItem();
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/** 更改值 */
|
|
344
|
-
async function editValue(target) {
|
|
345
|
-
const result = await command.question({
|
|
346
|
-
text: '请更改为新的 npm registry 值',
|
|
347
|
-
tip: target.value,
|
|
348
|
-
defaultValue: target.value,
|
|
349
|
-
required: false,
|
|
350
|
-
});
|
|
351
|
-
dog('新值为', result);
|
|
352
|
-
/** 没有更改 */
|
|
353
|
-
if (isUndefined(result))
|
|
354
|
-
return;
|
|
355
|
-
target.value = target.tip = result;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/** 更改当前的 label 值 */
|
|
359
|
-
async function editLabel(target) {
|
|
360
|
-
const result = await command.question({
|
|
361
|
-
text: '请更改为新的 npm registry 别名',
|
|
362
|
-
tip: target.label,
|
|
363
|
-
defaultValue: target.label.toString(),
|
|
364
|
-
required: false,
|
|
365
|
-
});
|
|
366
|
-
dog('新值为', result);
|
|
367
|
-
/** 没有更改 */
|
|
368
|
-
if (isUndefined(result))
|
|
369
|
-
return;
|
|
370
|
-
target.label = result;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/** 编辑项 */
|
|
374
|
-
async function editItem() {
|
|
375
|
-
if (!qqi.available)
|
|
376
|
-
return await exitProgram('当前读写权限不足,即将退出程序');
|
|
377
|
-
const target = await getTarget('请选择你想要修改的项', false);
|
|
378
|
-
const { value: originValue, label: originLabel } = target;
|
|
379
|
-
dog('获取用户的选择', target);
|
|
380
|
-
dog('原始的值', originValue);
|
|
381
|
-
dog('原始的标签', originLabel);
|
|
382
|
-
await editValue(target);
|
|
383
|
-
await editLabel(target);
|
|
384
|
-
const { value, label } = target;
|
|
385
|
-
dog('更改后的值', value);
|
|
386
|
-
dog('更改的标签', label);
|
|
387
|
-
/// 获取本地的值,防止意外覆盖
|
|
388
|
-
const originData = getOriginData();
|
|
389
|
-
for (const ele of originData) {
|
|
390
|
-
if (ele.value === originValue && ele.label === originLabel) {
|
|
391
|
-
ele.value = value;
|
|
392
|
-
ele.label = label.toString();
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
const result = qqi.write('config', originData);
|
|
397
|
-
if (result) {
|
|
398
|
-
_p('更改后的列表为:');
|
|
399
|
-
await list();
|
|
400
|
-
const tip = ['退出', '继续修改'];
|
|
401
|
-
const result = await command.question({
|
|
402
|
-
text: '是否继续修改其他项',
|
|
403
|
-
tip,
|
|
404
|
-
});
|
|
405
|
-
if (isUndefined(result) || result === tip[0])
|
|
406
|
-
return await exitProgram('');
|
|
407
|
-
return await editItem();
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/** 当前可见性的更改 */
|
|
412
|
-
async function manageVisible() {
|
|
413
|
-
if (!qqi.available)
|
|
414
|
-
return await exitProgram('当前读写受限,即将退出程序。');
|
|
415
|
-
const originData = getOriginData();
|
|
416
|
-
/** 当前设置项 */
|
|
417
|
-
const currentValue = await getCurrentRegistry();
|
|
418
|
-
const result = await command.selection({
|
|
419
|
-
data: originData.map(e => ({
|
|
420
|
-
...e,
|
|
421
|
-
checked: !e.disable,
|
|
422
|
-
disable: e.value === currentValue,
|
|
423
|
-
})),
|
|
424
|
-
kind: 'check',
|
|
425
|
-
}, 'number');
|
|
426
|
-
dog('交互结果', result);
|
|
427
|
-
if (isUndefined(result))
|
|
428
|
-
return await exitProgram('好的,将退出状态显隐管理');
|
|
429
|
-
originData.forEach((e, i) => {
|
|
430
|
-
e.disable = !result.includes(i);
|
|
431
|
-
});
|
|
432
|
-
dog('保存前的数据', originData);
|
|
433
|
-
qqi.write('config', originData);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/** 解析参数 */
|
|
437
|
-
function parseArg() {
|
|
438
|
-
/** 用户启动参数 */
|
|
439
|
-
const args = command.args;
|
|
440
|
-
/** 用户启用参数的 map 形式 */
|
|
441
|
-
const argsMap = args.$map;
|
|
442
|
-
dog('源解析值', args);
|
|
443
|
-
dog('源解析值没有匹配项', args.$isVoid);
|
|
444
|
-
[
|
|
445
|
-
'add',
|
|
446
|
-
'delete',
|
|
447
|
-
'edit',
|
|
448
|
-
'list',
|
|
449
|
-
'manage',
|
|
450
|
-
'reset',
|
|
451
|
-
].forEach(e => (commandParameters[e] = isFalse(isUndefined(argsMap[e]))));
|
|
452
|
-
// 当没有匹配到项
|
|
453
|
-
commandParameters.noMatch = args.$isVoid;
|
|
454
|
-
dog('解析完的值', commandParameters);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/** 重制项 */
|
|
458
|
-
async function reset() {
|
|
459
|
-
if (!qqi.available)
|
|
460
|
-
return await exitProgram('当前读写权限受限,正在退出程序');
|
|
461
|
-
const tip = ['退出', '重置'];
|
|
462
|
-
const result = await command.question({
|
|
463
|
-
text: '请确认是否执行覆盖原数据,该操作无法复原',
|
|
464
|
-
tip,
|
|
465
|
-
});
|
|
466
|
-
if (isUndefined(result) || result === tip[0])
|
|
467
|
-
return await exitProgram('好的,这就退出重置');
|
|
468
|
-
const writeResponse = qqi.write('config', getOriginData(true));
|
|
469
|
-
if (writeResponse)
|
|
470
|
-
return await exitProgram('写入成功,退出程序');
|
|
471
|
-
return await exitProgram('重置未能完成,原因未知');
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/** 主程序 */
|
|
475
|
-
async function main() {
|
|
476
|
-
parseArg();
|
|
477
|
-
dog('执行');
|
|
478
|
-
if (commandParameters.noMatch) {
|
|
479
|
-
dog('当前没有匹配值');
|
|
480
|
-
return await choose();
|
|
481
|
-
}
|
|
482
|
-
else if (commandParameters.reset) {
|
|
483
|
-
dog('重置项');
|
|
484
|
-
return await reset();
|
|
485
|
-
}
|
|
486
|
-
else if (commandParameters.list) {
|
|
487
|
-
dog('当前为展示项');
|
|
488
|
-
return await list();
|
|
489
|
-
}
|
|
490
|
-
else if (commandParameters.manage) {
|
|
491
|
-
dog('当前执行状态更改');
|
|
492
|
-
return await manageVisible();
|
|
493
|
-
}
|
|
494
|
-
else if (commandParameters.add) {
|
|
495
|
-
dog('添加新的项');
|
|
496
|
-
return await addItem();
|
|
497
|
-
}
|
|
498
|
-
else if (commandParameters.edit) {
|
|
499
|
-
dog('编辑项');
|
|
500
|
-
return await editItem();
|
|
501
|
-
}
|
|
502
|
-
else if (commandParameters.delete) {
|
|
503
|
-
dog('删除项');
|
|
504
|
-
return await delItem();
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
(async () => {
|
|
509
|
-
try {
|
|
510
|
-
await main();
|
|
511
|
-
}
|
|
512
|
-
catch (error) {
|
|
513
|
-
dog.error('系统级捕获 错误', error);
|
|
514
|
-
}
|
|
515
|
-
})();
|