@kezh/my-custom-js-converter 1.5.1 → 1.6.0
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/CLAUDE.md +1 -0
- package/TASKS.md +48 -396
- package/core/config/index.js +1 -0
- package/core/config/main_config.d.ts +5 -0
- package/core/context/map_context.d.ts +14 -0
- package/core/context/map_context.js +43 -10
- package/core/decode/index.js +144 -3
- package/core/scanf/index.d.ts +17 -0
- package/core/scanf/index.js +71 -0
- package/core/util/ast.d.ts +9 -0
- package/core/util/ast.js +37 -0
- package/package.json +42 -42
- package/test/fixtures/sample_project/config.json +18 -17
- package/test/fixtures/sample_project/util/drawer.js +15 -0
- package/test/fixtures/sample_project/util/form.js +11 -0
- package/test/manual_review.js +302 -288
- package/test/run_tests.js +515 -413
package/CLAUDE.md
CHANGED
|
@@ -48,3 +48,4 @@ When used as a dependency, the tool reads `config.json` from the parent project'
|
|
|
48
48
|
- `decode.file`: `"coded.js"`, `decode.output`: `"decoded.js"`, `decode.mount`: `"customEvent"`
|
|
49
49
|
- `settingDir`: `".setting"` (where `mod.map` is stored)
|
|
50
50
|
- `target`: directories to scan relative to `baseDir`
|
|
51
|
+
- `libs`: dependency library search directories (used by decode to supplement missing deps in `mod.map`). Supports `@/util` alias paths (`@` = project root) and `util` paths relative to `baseDir`. When decode finds unknown `__{mod}` suffixes in `coded.js` not present in `mod.map`, it searches these directories for `modName.js` / `modName/index.js` and auto-supplements `mod.map`. Duplicate names are resolved interactively after batch processing.
|
package/TASKS.md
CHANGED
|
@@ -1,399 +1,51 @@
|
|
|
1
1
|
# 任务
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
`npx decode`功能反编其他人的`coded.js`文件时,如果本地的`.setting/mod.map`文件没有及时更新依赖模块,会导致部分依赖无法识别,导致没有引入依赖模块:
|
|
3
|
+
1. 比如当前coded.js为:
|
|
4
4
|
```js
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.initHangupBtn();
|
|
15
|
-
},
|
|
16
|
-
onFormSubmit() {
|
|
17
|
-
if (form.getValue("REASON_TYPE_ORIGIN")) {
|
|
18
|
-
form.setValue(
|
|
19
|
-
"REASON_TYPE",
|
|
20
|
-
form.getSelectOptionLabel("REASON_TYPE_ORIGIN")
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
if ("挂起" == form.getValue("SUSPENDED_STATE")) {
|
|
24
|
-
message.warning("该流程已挂起,请解挂后提交工单!");
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
initForm() {
|
|
30
|
-
form.hidden("hiddenInfo");
|
|
31
|
-
if (form.getValue("SUSPENDED_STATE")) {
|
|
32
|
-
form.show("hangupInfo");
|
|
33
|
-
} else {
|
|
34
|
-
form.hidden("hangupInfo");
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
initHangupBtn() {
|
|
38
|
-
if ("告警处理" !== tch.getCurTchName()) {
|
|
39
|
-
return;
|
|
40
|
-
} // 注入弹出框样式
|
|
41
|
-
dom.addCss(
|
|
42
|
-
`
|
|
43
|
-
.hangup-dialog-overlay {
|
|
44
|
-
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
|
|
45
|
-
background: rgba(0, 0, 0, 0.5); z-index: 2000;
|
|
46
|
-
display: flex; align-items: center; justify-content: center;
|
|
47
|
-
}
|
|
48
|
-
.hangup-dialog {
|
|
49
|
-
background: #fff; border-radius: 4px; width: 420px; padding: 20px;
|
|
50
|
-
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
|
|
51
|
-
}
|
|
52
|
-
.hangup-dialog__title {
|
|
53
|
-
font-size: 16px; font-weight: bold; margin-bottom: 16px; color: #303133;
|
|
54
|
-
}
|
|
55
|
-
.hangup-dialog__label {
|
|
56
|
-
display: block; font-size: 14px; color: #606266; margin-bottom: 6px;
|
|
57
|
-
}
|
|
58
|
-
.hangup-dialog__input {
|
|
59
|
-
width: 100%; box-sizing: border-box; padding: 8px 12px;
|
|
60
|
-
border: 1px solid #dcdfe6; border-radius: 4px; font-size: 14px;
|
|
61
|
-
margin-bottom: 16px; outline: none;
|
|
62
|
-
}
|
|
63
|
-
.hangup-dialog__input:focus {
|
|
64
|
-
border-color: #409eff;
|
|
65
|
-
}
|
|
66
|
-
.hangup-dialog__textarea {
|
|
67
|
-
width: 100%; box-sizing: border-box; padding: 8px 12px;
|
|
68
|
-
border: 1px solid #dcdfe6; border-radius: 4px; font-size: 14px;
|
|
69
|
-
margin-bottom: 16px; outline: none; resize: vertical; min-height: 80px;
|
|
70
|
-
}
|
|
71
|
-
.hangup-dialog__textarea:focus {
|
|
72
|
-
border-color: #409eff;
|
|
73
|
-
}
|
|
74
|
-
.hangup-dialog__footer {
|
|
75
|
-
text-align: right; margin-top: 8px;
|
|
76
|
-
}
|
|
77
|
-
.hangup-dialog__btn {
|
|
78
|
-
padding: 8px 20px; border-radius: 4px; font-size: 14px;
|
|
79
|
-
cursor: pointer; border: 1px solid #dcdfe6; margin-left: 10px;
|
|
80
|
-
}
|
|
81
|
-
.hangup-dialog__btn--primary {
|
|
82
|
-
background: #409eff; color: #fff; border-color: #409eff;
|
|
83
|
-
}
|
|
84
|
-
.hangup-dialog__btn--primary:hover {
|
|
85
|
-
background: #66b1ff; border-color: #66b1ff;
|
|
86
|
-
}
|
|
87
|
-
.hangup-dialog__btn--default {
|
|
88
|
-
background: #fff; color: #606266;
|
|
89
|
-
}
|
|
90
|
-
.hangup-dialog__btn--default:hover {
|
|
91
|
-
color: #409eff; border-color: #c6e2ff; background: #ecf5ff;
|
|
92
|
-
}
|
|
93
|
-
`,
|
|
94
|
-
"hangup-dialog-style"
|
|
95
|
-
); // 等待DOM渲染完成后注入按钮
|
|
96
|
-
vue.nextTick(() => {
|
|
97
|
-
this.renderHangupBtn();
|
|
5
|
+
onClickPickLevel() {
|
|
6
|
+
this.pop__drawer({
|
|
7
|
+
title: "关联隐患信息",
|
|
8
|
+
size: "65%",
|
|
9
|
+
name: "storeOfHiddenDangers",
|
|
10
|
+
param: {}
|
|
11
|
+
}, resp => {
|
|
12
|
+
Object.keys(resp).forEach(key => {
|
|
13
|
+
this.setValue__form(`${key}`, resp[key]);
|
|
98
14
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
<textarea class="hangup-dialog__textarea" id="hangupReason" placeholder="请输入挂起原因"></textarea>
|
|
137
|
-
<label class="hangup-dialog__label"><span style="color:#f56c6c">*</span> 自动解挂时间</label>
|
|
138
|
-
<input class="hangup-dialog__input" type="datetime-local" id="hangupUnbanTime" />
|
|
139
|
-
<div class="hangup-dialog__footer">
|
|
140
|
-
<button class="hangup-dialog__btn hangup-dialog__btn--default" id="hangupCancelBtn">取 消</button>
|
|
141
|
-
<button class="hangup-dialog__btn hangup-dialog__btn--primary" id="hangupConfirmBtn">确 定</button>
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
`;
|
|
145
|
-
document.body.appendChild(overlay); // 设置自动解挂时间默认值为当前时间+1天
|
|
146
|
-
var defaultTime = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
|
147
|
-
var pad = function (n) {
|
|
148
|
-
return n < 10 ? "0" + n : "" + n;
|
|
149
|
-
};
|
|
150
|
-
var defaultTimeStr =
|
|
151
|
-
defaultTime.getFullYear() +
|
|
152
|
-
"-" +
|
|
153
|
-
pad(defaultTime.getMonth() + 1) +
|
|
154
|
-
"-" +
|
|
155
|
-
pad(defaultTime.getDate()) +
|
|
156
|
-
"T" +
|
|
157
|
-
pad(defaultTime.getHours()) +
|
|
158
|
-
":" +
|
|
159
|
-
pad(defaultTime.getMinutes());
|
|
160
|
-
document.getElementById("hangupUnbanTime").value = defaultTimeStr; // 点击遮罩层关闭
|
|
161
|
-
overlay.addEventListener("click", (e) => {
|
|
162
|
-
if (e.target === overlay) {
|
|
163
|
-
this.closeDialog("hangupDialogOverlay");
|
|
164
|
-
}
|
|
165
|
-
}); // 取消按钮
|
|
166
|
-
document.getElementById("hangupCancelBtn").addEventListener("click", () => {
|
|
167
|
-
this.closeDialog("hangupDialogOverlay");
|
|
168
|
-
}); // 确定按钮
|
|
169
|
-
document
|
|
170
|
-
.getElementById("hangupConfirmBtn")
|
|
171
|
-
.addEventListener("click", () => {
|
|
172
|
-
this.confirmHangup();
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
async confirmHangup() {
|
|
176
|
-
const reason = document.getElementById("hangupReason").value;
|
|
177
|
-
const unbanTimeRaw = document.getElementById("hangupUnbanTime").value;
|
|
178
|
-
if (!unbanTimeRaw) {
|
|
179
|
-
message.warning("请填写自动解挂时间");
|
|
180
|
-
return;
|
|
181
|
-
} // datetime-local的值格式为 yyyy-MM-ddTHH:mm,转为 yyyy-MM-dd HH:mm:ss
|
|
182
|
-
const unbanTime = unbanTimeRaw.replace("T", " ") + ":00";
|
|
183
|
-
const orderCode = form.getValue("ORDER_CODE", "");
|
|
184
|
-
const flowId = form.getValue("FLOW_ID", "");
|
|
185
|
-
if (!orderCode) {
|
|
186
|
-
message.error("集团工单号为空,无法挂起");
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
if (!flowId) {
|
|
190
|
-
message.error("工单ID为空,无法挂起");
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
try {
|
|
194
|
-
const result = await http.post(
|
|
195
|
-
"/aiops/api/v1/flow/group/province/alarm/dispatch/order/hangupOrder",
|
|
196
|
-
{
|
|
197
|
-
ORDER_CODE: orderCode,
|
|
198
|
-
FLOW_ID: flowId,
|
|
199
|
-
TYPE: "1",
|
|
200
|
-
REASON: reason,
|
|
201
|
-
UNBAN_TIME: unbanTime
|
|
202
|
-
}
|
|
203
|
-
);
|
|
204
|
-
if (result && result.resultCode === 0) {
|
|
205
|
-
message.success("挂起成功");
|
|
206
|
-
this.closeDialog("hangupDialogOverlay"); // 更新按钮状态为解挂
|
|
207
|
-
this.updateHangupBtnState("解挂");
|
|
208
|
-
} else {
|
|
209
|
-
message.error((result && result.resultMsg) || "挂起失败");
|
|
210
|
-
}
|
|
211
|
-
} catch (e) {
|
|
212
|
-
message.error("挂起请求异常");
|
|
213
|
-
console.error(e);
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
showResumeDialog() {
|
|
217
|
-
const overlay = document.createElement("div");
|
|
218
|
-
overlay.className = "hangup-dialog-overlay";
|
|
219
|
-
overlay.id = "resumeDialogOverlay";
|
|
220
|
-
overlay.innerHTML = `
|
|
221
|
-
<div class="hangup-dialog">
|
|
222
|
-
<div class="hangup-dialog__title">解挂工单</div>
|
|
223
|
-
<label class="hangup-dialog__label">解挂原因</label>
|
|
224
|
-
<textarea class="hangup-dialog__textarea" id="resumeReason" placeholder="请输入解挂原因"></textarea>
|
|
225
|
-
<div class="hangup-dialog__footer">
|
|
226
|
-
<button class="hangup-dialog__btn hangup-dialog__btn--default" id="resumeCancelBtn">取 消</button>
|
|
227
|
-
<button class="hangup-dialog__btn hangup-dialog__btn--primary" id="resumeConfirmBtn">确 定</button>
|
|
228
|
-
</div>
|
|
229
|
-
</div>
|
|
230
|
-
`;
|
|
231
|
-
document.body.appendChild(overlay); // 点击遮罩层关闭
|
|
232
|
-
overlay.addEventListener("click", (e) => {
|
|
233
|
-
if (e.target === overlay) {
|
|
234
|
-
this.closeDialog("resumeDialogOverlay");
|
|
235
|
-
}
|
|
236
|
-
}); // 取消按钮
|
|
237
|
-
document.getElementById("resumeCancelBtn").addEventListener("click", () => {
|
|
238
|
-
this.closeDialog("resumeDialogOverlay");
|
|
239
|
-
}); // 确定按钮
|
|
240
|
-
document
|
|
241
|
-
.getElementById("resumeConfirmBtn")
|
|
242
|
-
.addEventListener("click", () => {
|
|
243
|
-
this.confirmResume();
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
async confirmResume() {
|
|
247
|
-
const reason = document.getElementById("resumeReason").value;
|
|
248
|
-
const orderCode = form.getValue("ORDER_CODE", "");
|
|
249
|
-
const flowId = form.getValue("FLOW_ID", "");
|
|
250
|
-
if (!orderCode) {
|
|
251
|
-
message.error("集团工单号为空,无法解挂");
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (!flowId) {
|
|
255
|
-
message.error("工单ID为空,无法解挂");
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
try {
|
|
259
|
-
const result = await http.post(
|
|
260
|
-
"/aiops/api/v1/flow/group/province/alarm/dispatch/order/resumeOrder",
|
|
261
|
-
{ ORDER_CODE: orderCode, FLOW_ID: flowId, REASON: reason }
|
|
262
|
-
);
|
|
263
|
-
if (result && result.resultCode === 0) {
|
|
264
|
-
message.success("解挂成功");
|
|
265
|
-
this.closeDialog("resumeDialogOverlay"); // 更新按钮状态为挂起
|
|
266
|
-
this.updateHangupBtnState("挂起");
|
|
267
|
-
} else {
|
|
268
|
-
message.error((result && result.resultMsg) || "解挂失败");
|
|
269
|
-
}
|
|
270
|
-
} catch (e) {
|
|
271
|
-
message.error("解挂请求异常");
|
|
272
|
-
console.error(e);
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
updateHangupBtnState(prevState) {
|
|
276
|
-
const hangupBtn = document.getElementById("hangupBtn");
|
|
277
|
-
if (!hangupBtn) {
|
|
278
|
-
return;
|
|
279
|
-
} // 移除旧按钮的事件监听(通过替换节点实现)
|
|
280
|
-
const newBtn = hangupBtn.cloneNode(false);
|
|
281
|
-
if (prevState === "挂起") {
|
|
282
|
-
// 从挂起变为解挂 → 显示挂起按钮
|
|
283
|
-
newBtn.innerHTML =
|
|
284
|
-
'<div> <i class="fi el-icon-unlock icon"></i>挂起</div>';
|
|
285
|
-
newBtn.addEventListener("click", () => {
|
|
286
|
-
this.showHangupDialog();
|
|
287
|
-
}); // 同步更新表单字段
|
|
288
|
-
form.setValue("SUSPENDED_STATE", "解挂");
|
|
289
|
-
} else {
|
|
290
|
-
// 从解挂变为挂起 → 显示解挂按钮
|
|
291
|
-
newBtn.innerHTML = '<div> <i class="fi el-icon-lock icon"></i>解挂</div>';
|
|
292
|
-
newBtn.addEventListener("click", () => {
|
|
293
|
-
this.showResumeDialog();
|
|
294
|
-
}); // 同步更新表单字段
|
|
295
|
-
form.setValue("SUSPENDED_STATE", "挂起");
|
|
296
|
-
}
|
|
297
|
-
hangupBtn.parentNode.replaceChild(newBtn, hangupBtn);
|
|
298
|
-
},
|
|
299
|
-
closeDialog(overlayId) {
|
|
300
|
-
const overlay = document.getElementById(overlayId);
|
|
301
|
-
if (overlay) {
|
|
302
|
-
document.body.removeChild(overlay);
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
async receiveOrder() {
|
|
306
|
-
const orderCode = form.getValue("ORDER_CODE", "");
|
|
307
|
-
const flowId = form.getValue("FLOW_ID", "");
|
|
308
|
-
if (!orderCode) {
|
|
309
|
-
message.error("集团工单号为空,无法接单");
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
if (!flowId) {
|
|
313
|
-
message.error("工单ID为空,无法接单");
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
try {
|
|
317
|
-
const result = await http.post(
|
|
318
|
-
"/aiops/api/v1/flow/group/province/alarm/dispatch/order/receiveOrder",
|
|
319
|
-
this.form
|
|
320
|
-
);
|
|
321
|
-
if (result && result.resultCode === 0) {
|
|
322
|
-
message.success("接单成功");
|
|
323
|
-
return true;
|
|
324
|
-
} else {
|
|
325
|
-
message.error((result && result.resultMsg) || "接单失败");
|
|
326
|
-
}
|
|
327
|
-
} catch (e) {
|
|
328
|
-
message.error("接单请求异常");
|
|
329
|
-
console.error(e);
|
|
330
|
-
}
|
|
331
|
-
return false;
|
|
332
|
-
},
|
|
333
|
-
async handleAlarm() {
|
|
334
|
-
const orderCode = form.getValue("ORDER_CODE", "");
|
|
335
|
-
const flowId = form.getValue("FLOW_ID", "");
|
|
336
|
-
if (!orderCode) {
|
|
337
|
-
message.error("集团工单号为空,无法处理");
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
340
|
-
if (!flowId) {
|
|
341
|
-
message.error("工单ID为空,无法处理");
|
|
342
|
-
return false;
|
|
343
|
-
} // 1. 调用关联变更单接口(不判断结果)
|
|
344
|
-
try {
|
|
345
|
-
await http.post(
|
|
346
|
-
"/aiops/api/v1/flow/group/province/alarm/dispatch/order/relateChangeOrder",
|
|
347
|
-
this.form
|
|
348
|
-
);
|
|
349
|
-
} catch (e) {
|
|
350
|
-
console.error(e);
|
|
351
|
-
} // 2. 调用定位接口(不判断结果)
|
|
352
|
-
try {
|
|
353
|
-
await http.post(
|
|
354
|
-
"/aiops/api/v1/flow/group/province/alarm/dispatch/order/positioningOrder",
|
|
355
|
-
this.form
|
|
356
|
-
);
|
|
357
|
-
} catch (e) {
|
|
358
|
-
console.error(e);
|
|
359
|
-
} // 3. 调用回单接口
|
|
360
|
-
try {
|
|
361
|
-
const returnResult = await http.post(
|
|
362
|
-
"/aiops/api/v1/flow/group/province/alarm/dispatch/order/returnOrder",
|
|
363
|
-
this.form
|
|
364
|
-
);
|
|
365
|
-
if (returnResult && returnResult.resultCode === 0) {
|
|
366
|
-
message.success("告警处理成功");
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
message.error((returnResult && returnResult.resultMsg) || "回单失败");
|
|
370
|
-
return false;
|
|
371
|
-
} catch (e) {
|
|
372
|
-
message.error("回单请求异常");
|
|
373
|
-
console.error(e);
|
|
374
|
-
return false;
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
onChange_IF_RELATED_CHANGEORDER() {
|
|
378
|
-
form.removeRequired("CHANGE_ORDER");
|
|
379
|
-
if ("是" == form.getValue("IF_RELATED_CHANGEORDER")) {
|
|
380
|
-
const orderStr = form.getValue("CHANGE_ORDERS", "");
|
|
381
|
-
const orders = orderStr
|
|
382
|
-
.split(",")
|
|
383
|
-
.filter((order) => order.trim())
|
|
384
|
-
.map((order) => ({
|
|
385
|
-
label: order,
|
|
386
|
-
value: order,
|
|
387
|
-
children: null,
|
|
388
|
-
isShow: true,
|
|
389
|
-
pid: null,
|
|
390
|
-
state: null
|
|
391
|
-
}));
|
|
392
|
-
form.setSelectOptions("CHANGE_ORDER", orders);
|
|
393
|
-
form.setRequired("CHANGE_ORDER");
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
module.exports = customEvent;
|
|
398
|
-
|
|
399
|
-
```
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
2. 当时由于mod.map中没有定义`drawer`依赖,导致反编后的decoded.js为:
|
|
19
|
+
```js
|
|
20
|
+
onClickPickLevel() {
|
|
21
|
+
this.pop__drawer({
|
|
22
|
+
title: "关联隐患信息",
|
|
23
|
+
size: "65%",
|
|
24
|
+
name: "storeOfHiddenDangers",
|
|
25
|
+
param: {}
|
|
26
|
+
}, resp => {
|
|
27
|
+
Object.keys(resp).forEach(key => {
|
|
28
|
+
this.setValue__form(`${key}`, resp[key]);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
3. 但是我们期望的效果是:
|
|
34
|
+
```js
|
|
35
|
+
onClickPickLevel() {
|
|
36
|
+
drawer.pop({
|
|
37
|
+
title: "关联隐患信息",
|
|
38
|
+
size: "65%",
|
|
39
|
+
name: "storeOfHiddenDangers",
|
|
40
|
+
param: {}
|
|
41
|
+
}, resp => {
|
|
42
|
+
Object.keys(resp).forEach(key => {
|
|
43
|
+
this.setValue__form(`${key}`, resp[key]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
我想到的解决方案是:
|
|
49
|
+
1. `npx decode`时,先要将`.setting/mod.map`文件更新,此时需要先找到coded.js中可能的依赖`__{mod}`
|
|
50
|
+
2. 扫描匹配可能得文件名称,并更新mod.map文件
|
|
51
|
+
3. 依赖文件名可能存在重名问题,所以当出现重名时,需要交给用户指定依赖的js文件
|
package/core/config/index.js
CHANGED
|
@@ -5,6 +5,11 @@ export interface MainConfig {
|
|
|
5
5
|
target: string[];
|
|
6
6
|
settingDir: string;
|
|
7
7
|
customConfig: string;
|
|
8
|
+
/**
|
|
9
|
+
* 依赖库搜索目录数组,用于 decode 时补充缺失依赖。
|
|
10
|
+
* 支持 "@/util" 别名路径(@ 代表项目根目录)和 "util" 相对 baseDir 路径。
|
|
11
|
+
*/
|
|
12
|
+
libs: string[];
|
|
8
13
|
}
|
|
9
14
|
export interface EncodeConfig {
|
|
10
15
|
file: string;
|
|
@@ -13,6 +13,20 @@ export declare class MapContext {
|
|
|
13
13
|
getDependencyNameByMod(name: string): string[];
|
|
14
14
|
getSrcPathByMod(name: string): string | undefined;
|
|
15
15
|
getAbsoluteSrcPathByMod(name: string): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* 补充缺失的依赖到 mod.map
|
|
18
|
+
* 在 self.dependencies 下新增该依赖(让 importMods 生成 require),
|
|
19
|
+
* 并新增独立的 mod 条目(让 getAbsoluteSrcPathByMod 拿到源文件路径)。
|
|
20
|
+
* methods 留空数组,后续 npx encode 会自动补全。
|
|
21
|
+
* @param depName - 依赖名(如 "drawer")
|
|
22
|
+
* @param absoluteSrcPath - 依赖文件的绝对路径
|
|
23
|
+
*/
|
|
24
|
+
appendMissingDep(depName: string, absoluteSrcPath: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* 将当前 map 写入指定目录的 mod.map 文件
|
|
27
|
+
* @param outDir - 输出目录
|
|
28
|
+
*/
|
|
29
|
+
writeToLocalDir(outDir: string): void;
|
|
16
30
|
static readFromLocal(inDir: string): MapContext;
|
|
17
31
|
private init;
|
|
18
32
|
private writeToLocal;
|
|
@@ -59,6 +59,48 @@ class MapContext {
|
|
|
59
59
|
? path_1.default.resolve(parentRootDir, srcPath)
|
|
60
60
|
: srcPath;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* 补充缺失的依赖到 mod.map
|
|
64
|
+
* 在 self.dependencies 下新增该依赖(让 importMods 生成 require),
|
|
65
|
+
* 并新增独立的 mod 条目(让 getAbsoluteSrcPathByMod 拿到源文件路径)。
|
|
66
|
+
* methods 留空数组,后续 npx encode 会自动补全。
|
|
67
|
+
* @param depName - 依赖名(如 "drawer")
|
|
68
|
+
* @param absoluteSrcPath - 依赖文件的绝对路径
|
|
69
|
+
*/
|
|
70
|
+
appendMissingDep(depName, absoluteSrcPath) {
|
|
71
|
+
// self.dependencies[depName] = { methods: [] }
|
|
72
|
+
const selfMod = this.getMod("self");
|
|
73
|
+
if (selfMod) {
|
|
74
|
+
selfMod.dependencies[depName] = new map_config_1.Dependency([]);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const mod = new map_config_1.Mod("", new map_config_1.Dependencies());
|
|
78
|
+
mod.dependencies[depName] = new map_config_1.Dependency([]);
|
|
79
|
+
this.appendModMap(mod, true);
|
|
80
|
+
}
|
|
81
|
+
// map[depName] = { src: <相对 parentRootDir 的路径>, dependencies: {} }
|
|
82
|
+
const parentRootDir = (0, parent_path_1.getParentRootDir)();
|
|
83
|
+
const src = parentRootDir
|
|
84
|
+
? path_1.default.relative(parentRootDir, absoluteSrcPath)
|
|
85
|
+
: absoluteSrcPath;
|
|
86
|
+
this.appendModMap(new map_config_1.Mod(src, new map_config_1.Dependencies()), false, depName);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 将当前 map 写入指定目录的 mod.map 文件
|
|
90
|
+
* @param outDir - 输出目录
|
|
91
|
+
*/
|
|
92
|
+
writeToLocalDir(outDir) {
|
|
93
|
+
const outPath = path_1.default.join(outDir, MapContext.SAVE_FILE);
|
|
94
|
+
logger.info(`write map: ${outPath}`);
|
|
95
|
+
const json = JSON.stringify(this.map, null, 4);
|
|
96
|
+
try {
|
|
97
|
+
fs_1.default.accessSync(outDir);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
fs_1.default.mkdirSync(outDir);
|
|
101
|
+
}
|
|
102
|
+
fs_1.default.writeFileSync(outPath, json.replace(/\n/gm, os_1.EOL), "utf-8");
|
|
103
|
+
}
|
|
62
104
|
static readFromLocal(inDir) {
|
|
63
105
|
const inPath = path_1.default.join(inDir, MapContext.SAVE_FILE);
|
|
64
106
|
logger.info(`read map: ${inPath}`);
|
|
@@ -82,16 +124,7 @@ class MapContext {
|
|
|
82
124
|
this.writeToLocal();
|
|
83
125
|
}
|
|
84
126
|
writeToLocal() {
|
|
85
|
-
|
|
86
|
-
logger.info(`write map: ${outPath}`);
|
|
87
|
-
const json = JSON.stringify(this.map, null, 4);
|
|
88
|
-
try {
|
|
89
|
-
fs_1.default.accessSync(this.outDir);
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
fs_1.default.mkdirSync(this.outDir);
|
|
93
|
-
}
|
|
94
|
-
fs_1.default.writeFileSync(outPath, json.replace(/\n/gm, os_1.EOL), "utf-8");
|
|
127
|
+
this.writeToLocalDir(this.outDir);
|
|
95
128
|
}
|
|
96
129
|
buildMapContext(inPath, entry, root) {
|
|
97
130
|
const srcAst = (0, ast_1.parseSrcAst)(inPath);
|