@mybricks/to-code-taro 1.2.3 → 1.2.4
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/dist/cjs/generate/generateTaroProjectJson.js +11 -0
- package/dist/cjs/handleGlobal.js +14 -2
- package/dist/cjs/processors/processModule.js +3 -1
- package/dist/cjs/utils/logic/handleProcess.js +12 -10
- package/dist/esm/generate/generateTaroProjectJson.js +11 -0
- package/dist/esm/handleGlobal.js +21 -2
- package/dist/esm/processors/processModule.js +3 -1
- package/dist/esm/utils/logic/handleProcess.js +15 -11
- package/package.json +1 -1
|
@@ -194,6 +194,17 @@ ${item.content || ""}`;
|
|
|
194
194
|
(0, import_pageImages.handlePageImages)(assetsDir, pageImages);
|
|
195
195
|
(0, import_customTabBar.updateCustomTabBar)(srcDir, files);
|
|
196
196
|
(0, import_commonDir.handleCommonDir)(commonDir, files);
|
|
197
|
+
const globalItem = files.find((item) => item.type === "global");
|
|
198
|
+
if ((globalItem == null ? void 0 : globalItem.jsModules) && globalItem.jsModules.length > 0) {
|
|
199
|
+
commonDir.children.push({
|
|
200
|
+
path: "src/common/index.jsModules.ts",
|
|
201
|
+
content: (0, import_genJSModules.genScopedJSModules)(
|
|
202
|
+
globalItem.jsModules,
|
|
203
|
+
"@mybricks/taro-core",
|
|
204
|
+
"@/common/jsModulesRuntime"
|
|
205
|
+
)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
197
208
|
const apiItem = files.find((item) => item.type === "connector-api");
|
|
198
209
|
if (apiItem) {
|
|
199
210
|
commonDir.children = commonDir.children || [];
|
package/dist/cjs/handleGlobal.js
CHANGED
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(handleGlobal_exports);
|
|
|
25
25
|
var import_utils = require("./utils");
|
|
26
26
|
var import_handleProcess = require("./utils/logic/handleProcess");
|
|
27
27
|
var import_string = require("./utils/common/string");
|
|
28
|
+
var import_collectJSModules = require("./utils/context/collectJSModules");
|
|
28
29
|
var handleGlobal = (params, config) => {
|
|
29
30
|
const { tojson, globalFxs, globalVars } = params;
|
|
30
31
|
const globalImportManager = new import_utils.ImportManager(config);
|
|
@@ -121,8 +122,9 @@ ${indent2}})`;
|
|
|
121
122
|
}
|
|
122
123
|
return `value${index}: any`;
|
|
123
124
|
}).join(", ");
|
|
125
|
+
const fxParams = values ? `${values}, appContext: any` : `appContext: any`;
|
|
124
126
|
globalFxsInitCode += `${indent}/** ${event.title} */
|
|
125
|
-
${indent}${event.frameId}: any = createFx((${
|
|
127
|
+
${indent}${event.frameId}: any = createFx((${fxParams}) => {
|
|
126
128
|
${res}
|
|
127
129
|
${indent}})
|
|
128
130
|
`;
|
|
@@ -161,6 +163,15 @@ export const globalFxs = new GlobalFxs()`;
|
|
|
161
163
|
importType: "named"
|
|
162
164
|
});
|
|
163
165
|
}
|
|
166
|
+
const globalJsModules = [];
|
|
167
|
+
(tojson.global.fxFrames || []).forEach((fxFrame) => {
|
|
168
|
+
Object.entries(fxFrame.coms || {}).forEach(([comId, comInfo]) => {
|
|
169
|
+
const jsModule = (0, import_collectJSModules.extractJSModuleFromCom)(comId, comInfo);
|
|
170
|
+
if (jsModule && !globalJsModules.some((m) => m.id === comId)) {
|
|
171
|
+
globalJsModules.push(jsModule);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
164
175
|
return [
|
|
165
176
|
{
|
|
166
177
|
type: "rootConfig",
|
|
@@ -172,7 +183,8 @@ export const globalFxs = new GlobalFxs()`;
|
|
|
172
183
|
type: "global",
|
|
173
184
|
content: varCode + "\n\n" + fxCode,
|
|
174
185
|
importManager: globalImportManager,
|
|
175
|
-
name: "global"
|
|
186
|
+
name: "global",
|
|
187
|
+
jsModules: globalJsModules
|
|
176
188
|
}
|
|
177
189
|
];
|
|
178
190
|
};
|
|
@@ -70,10 +70,12 @@ var processModule = (params) => {
|
|
|
70
70
|
return { ...scene, ...originalScene, event };
|
|
71
71
|
},
|
|
72
72
|
add: (value) => {
|
|
73
|
+
const jsModules = Array.from(jsModulesMap.values());
|
|
73
74
|
addResult({
|
|
74
75
|
...value,
|
|
75
76
|
type: scene.type,
|
|
76
|
-
meta: scene
|
|
77
|
+
meta: scene,
|
|
78
|
+
jsModules
|
|
77
79
|
});
|
|
78
80
|
},
|
|
79
81
|
addJSModule: (module2) => {
|
|
@@ -186,7 +186,7 @@ ${indent}${nextCode}this.$vars.${varKey}.${props.id}(${nextValue}${xpathArg})`;
|
|
|
186
186
|
importType: "named"
|
|
187
187
|
});
|
|
188
188
|
code += `${indent}/** 调用全局Fx ${props.meta.title} */
|
|
189
|
-
${indent}${nextCode}globalFxs.${props.meta.ioProxy.id}(${nextValue})`;
|
|
189
|
+
${indent}${nextCode}globalFxs.${props.meta.ioProxy.id}(${nextValue}${nextValue ? ", " : ""}appContext)`;
|
|
190
190
|
} else {
|
|
191
191
|
const currentProvider = getCurrentProvider(
|
|
192
192
|
{ isSameScope, props },
|
|
@@ -225,7 +225,7 @@ ${indent}${nextCode}this.${props.meta.id}.${props.id}(${nextValue})`;
|
|
|
225
225
|
`;
|
|
226
226
|
} else {
|
|
227
227
|
const next = outputs.map((output) => {
|
|
228
|
-
return getNextValueWithParam(output, config, event);
|
|
228
|
+
return getNextValueWithParam(output, config, event, outputToInputPinMap);
|
|
229
229
|
}).join(", ");
|
|
230
230
|
return pre + `${indent2}${id}: ${next},
|
|
231
231
|
`;
|
|
@@ -343,8 +343,8 @@ var getNextValue = (props, config, event, outputToInputPinMap) => {
|
|
|
343
343
|
});
|
|
344
344
|
return nextValue.join(", ");
|
|
345
345
|
};
|
|
346
|
-
var getNextValueWithParam = (param, config, event) => {
|
|
347
|
-
var _a, _b, _c, _d, _e;
|
|
346
|
+
var getNextValueWithParam = (param, config, event, outputToInputPinMap) => {
|
|
347
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
348
348
|
if (param.type === "params") {
|
|
349
349
|
const params = config.getParams();
|
|
350
350
|
return params[param.id];
|
|
@@ -354,15 +354,17 @@ var getNextValueWithParam = (param, config, event) => {
|
|
|
354
354
|
}
|
|
355
355
|
const componentNameWithId = getComponentNameWithId(param, config, event);
|
|
356
356
|
if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
357
|
+
const key2 = `${(_f = param.meta) == null ? void 0 : _f.id}_${param.id}`;
|
|
358
|
+
const fullVarName2 = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key2);
|
|
359
|
+
if (fullVarName2) {
|
|
360
|
+
return fullVarName2;
|
|
360
361
|
}
|
|
361
362
|
return `${componentNameWithId}_result`;
|
|
362
363
|
}
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
const key = `${(_g = param.meta) == null ? void 0 : _g.id}_${param.id}`;
|
|
365
|
+
const fullVarName = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key);
|
|
366
|
+
if (fullVarName) {
|
|
367
|
+
return `${fullVarName}.${param.id}`;
|
|
366
368
|
}
|
|
367
369
|
return `${componentNameWithId}_result.${param.id}`;
|
|
368
370
|
};
|
|
@@ -190,6 +190,17 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
|
|
|
190
190
|
// 处理 common 目录下的文件
|
|
191
191
|
handleCommonDir(commonDir, files);
|
|
192
192
|
|
|
193
|
+
// 生成全局 jsModules(如果全局 Fx 中有 JS 计算组件)
|
|
194
|
+
var globalItem = files.find(function (item) {
|
|
195
|
+
return item.type === 'global';
|
|
196
|
+
});
|
|
197
|
+
if (globalItem !== null && globalItem !== void 0 && globalItem.jsModules && globalItem.jsModules.length > 0) {
|
|
198
|
+
commonDir.children.push({
|
|
199
|
+
path: 'src/common/index.jsModules.ts',
|
|
200
|
+
content: genScopedJSModules(globalItem.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
193
204
|
// 处理 common 目录下的 api.ts
|
|
194
205
|
var apiItem = files.find(function (item) {
|
|
195
206
|
return item.type === 'connector-api';
|
package/dist/esm/handleGlobal.js
CHANGED
|
@@ -9,6 +9,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
9
9
|
import { ImportManager, indentation } from "./utils";
|
|
10
10
|
import { handleProcess } from "./utils/logic/handleProcess";
|
|
11
11
|
import { getSafeVarName } from "./utils/common/string";
|
|
12
|
+
import { extractJSModuleFromCom } from "./utils/context/collectJSModules";
|
|
12
13
|
var handleGlobal = function handleGlobal(params, config) {
|
|
13
14
|
var tojson = params.tojson,
|
|
14
15
|
globalFxs = params.globalFxs,
|
|
@@ -98,7 +99,8 @@ var handleGlobal = function handleGlobal(params, config) {
|
|
|
98
99
|
}
|
|
99
100
|
return "value".concat(index, ": any");
|
|
100
101
|
}).join(", ");
|
|
101
|
-
|
|
102
|
+
var fxParams = values ? "".concat(values, ", appContext: any") : "appContext: any";
|
|
103
|
+
globalFxsInitCode += "".concat(indent, "/** ").concat(event.title, " */") + "\n".concat(indent).concat(event.frameId, ": any = createFx((").concat(fxParams, ") => {") + "\n".concat(res) + "\n".concat(indent, "})\n");
|
|
102
104
|
});
|
|
103
105
|
var varCode = "/** 全局变量 */" + "\nclass GlobalVars {" + "\n".concat(globalVarsInitCode) + "\n".concat(indent, "init() {") + "".concat(globalVarsRegisterChangeCode) + "\n".concat(indent, "}") + "\n}" + "\n\nexport const globalVars = new GlobalVars()";
|
|
104
106
|
var fxCode = "/** 全局Fx */" + "\nclass GlobalFxs {" + "\n".concat(globalFxsInitCode) + "}" + "\n\nexport const globalFxs = new GlobalFxs()";
|
|
@@ -123,6 +125,22 @@ var handleGlobal = function handleGlobal(params, config) {
|
|
|
123
125
|
importType: "named"
|
|
124
126
|
});
|
|
125
127
|
}
|
|
128
|
+
|
|
129
|
+
// 收集全局 JS 计算组件(从 fxFrames 的 coms 中提取)
|
|
130
|
+
var globalJsModules = [];
|
|
131
|
+
(tojson.global.fxFrames || []).forEach(function (fxFrame) {
|
|
132
|
+
Object.entries(fxFrame.coms || {}).forEach(function (_ref4) {
|
|
133
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
134
|
+
comId = _ref5[0],
|
|
135
|
+
comInfo = _ref5[1];
|
|
136
|
+
var jsModule = extractJSModuleFromCom(comId, comInfo);
|
|
137
|
+
if (jsModule && !globalJsModules.some(function (m) {
|
|
138
|
+
return m.id === comId;
|
|
139
|
+
})) {
|
|
140
|
+
globalJsModules.push(jsModule);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
126
144
|
return [{
|
|
127
145
|
type: "rootConfig",
|
|
128
146
|
content: JSON.stringify(tojson.rootConfig, null, 2),
|
|
@@ -132,7 +150,8 @@ var handleGlobal = function handleGlobal(params, config) {
|
|
|
132
150
|
type: "global",
|
|
133
151
|
content: varCode + "\n\n" + fxCode,
|
|
134
152
|
importManager: globalImportManager,
|
|
135
|
-
name: "global"
|
|
153
|
+
name: "global",
|
|
154
|
+
jsModules: globalJsModules
|
|
136
155
|
}];
|
|
137
156
|
};
|
|
138
157
|
export default handleGlobal;
|
|
@@ -58,9 +58,11 @@ export var processModule = function processModule(params) {
|
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
60
|
add: function add(value) {
|
|
61
|
+
var jsModules = Array.from(jsModulesMap.values());
|
|
61
62
|
addResult(_objectSpread(_objectSpread({}, value), {}, {
|
|
62
63
|
type: scene.type,
|
|
63
|
-
meta: scene
|
|
64
|
+
meta: scene,
|
|
65
|
+
jsModules: jsModules
|
|
64
66
|
}));
|
|
65
67
|
},
|
|
66
68
|
addJSModule: function addJSModule(module) {
|
|
@@ -196,7 +196,7 @@ export var handleProcess = function handleProcess(event, config) {
|
|
|
196
196
|
dependencyNames: ["globalFxs"],
|
|
197
197
|
importType: "named"
|
|
198
198
|
});
|
|
199
|
-
code += "".concat(indent, "/** \u8C03\u7528\u5168\u5C40Fx ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalFxs.").concat(props.meta.ioProxy.id, "(").concat(nextValue, ")");
|
|
199
|
+
code += "".concat(indent, "/** \u8C03\u7528\u5168\u5C40Fx ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalFxs.").concat(props.meta.ioProxy.id, "(").concat(nextValue).concat(nextValue ? ', ' : '', "appContext)");
|
|
200
200
|
} else {
|
|
201
201
|
var _currentProvider = getCurrentProvider({
|
|
202
202
|
isSameScope: isSameScope,
|
|
@@ -235,7 +235,7 @@ export var handleProcess = function handleProcess(event, config) {
|
|
|
235
235
|
return pre + "".concat(indent2).concat(id, ": undefined,\n");
|
|
236
236
|
} else {
|
|
237
237
|
var next = outputs.map(function (output) {
|
|
238
|
-
return getNextValueWithParam(output, config, event);
|
|
238
|
+
return getNextValueWithParam(output, config, event, outputToInputPinMap);
|
|
239
239
|
}).join(", ");
|
|
240
240
|
return pre + "".concat(indent2).concat(id, ": ").concat(next, ",\n");
|
|
241
241
|
}
|
|
@@ -382,8 +382,8 @@ var getNextValue = function getNextValue(props, config, event, outputToInputPinM
|
|
|
382
382
|
});
|
|
383
383
|
return nextValue.join(", ");
|
|
384
384
|
};
|
|
385
|
-
var getNextValueWithParam = function getNextValueWithParam(param, config, event) {
|
|
386
|
-
var _param$meta5, _param$meta6;
|
|
385
|
+
var getNextValueWithParam = function getNextValueWithParam(param, config, event, outputToInputPinMap) {
|
|
386
|
+
var _param$meta5, _param$meta6, _param$meta8;
|
|
387
387
|
if (param.type === "params") {
|
|
388
388
|
var params = config.getParams();
|
|
389
389
|
return params[param.id];
|
|
@@ -396,16 +396,20 @@ var getNextValueWithParam = function getNextValueWithParam(param, config, event)
|
|
|
396
396
|
var componentNameWithId = getComponentNameWithId(param, config, event);
|
|
397
397
|
// 变量组件直接返回 Subject
|
|
398
398
|
if ((_param$meta6 = param.meta) !== null && _param$meta6 !== void 0 && (_param$meta6 = _param$meta6.def) !== null && _param$meta6 !== void 0 && (_param$meta6 = _param$meta6.namespace) !== null && _param$meta6 !== void 0 && _param$meta6.includes(".var")) {
|
|
399
|
-
var
|
|
400
|
-
|
|
401
|
-
|
|
399
|
+
var _param$meta7;
|
|
400
|
+
var _key2 = "".concat((_param$meta7 = param.meta) === null || _param$meta7 === void 0 ? void 0 : _param$meta7.id, "_").concat(param.id);
|
|
401
|
+
var _fullVarName2 = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key2);
|
|
402
|
+
if (_fullVarName2) {
|
|
403
|
+
return _fullVarName2;
|
|
402
404
|
}
|
|
403
405
|
return "".concat(componentNameWithId, "_result");
|
|
404
406
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
|
|
408
|
+
// 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
|
|
409
|
+
var key = "".concat((_param$meta8 = param.meta) === null || _param$meta8 === void 0 ? void 0 : _param$meta8.id, "_").concat(param.id);
|
|
410
|
+
var fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
|
|
411
|
+
if (fullVarName) {
|
|
412
|
+
return "".concat(fullVarName, ".").concat(param.id);
|
|
409
413
|
}
|
|
410
414
|
return "".concat(componentNameWithId, "_result.").concat(param.id);
|
|
411
415
|
};
|