@aiot-toolkit/shared-utils 1.0.17-binary-beta.1 → 1.0.17-binary-beta.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.
- package/lib/buildMode/BuildModeManager.js +273 -1
- package/lib/buildMode/util.js +83 -1
- package/lib/index.js +488 -1
- package/lib/protobuf/protobuf.js +283 -1
- package/lib/protobuf/vdom_pb.js +2785 -1
- package/lib/record-client.js +150 -1
- package/package.json +2 -2
package/lib/protobuf/protobuf.js
CHANGED
|
@@ -1,2 +1,284 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extractFunctions = extractFunctions;
|
|
7
|
+
exports.createBin = createBin;
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const vdom_pb = require('./vdom_pb');
|
|
10
|
+
const Path = require('path');
|
|
11
|
+
/* eslint-disable */
|
|
12
|
+
|
|
13
|
+
class AIOT {
|
|
14
|
+
constructor(aiotf) {
|
|
15
|
+
this.funcArr = [];
|
|
16
|
+
this.chld = [];
|
|
17
|
+
this.idCount = -1;
|
|
18
|
+
this.expCell = new vdom_pb.ExportCell();
|
|
19
|
+
this.aiotf = aiotf;
|
|
20
|
+
}
|
|
21
|
+
init(expName) {
|
|
22
|
+
this.expCell.setTagname(expName);
|
|
23
|
+
}
|
|
24
|
+
parseObj(opts) {
|
|
25
|
+
let styVaA = new vdom_pb.StyleValueArr();
|
|
26
|
+
for (let key in opts) {
|
|
27
|
+
let sKey = new vdom_pb.StyleKey();
|
|
28
|
+
let onesvl = new vdom_pb.OneStyleValue();
|
|
29
|
+
console.log(`---parseobj-- key:${key}`);
|
|
30
|
+
sKey.setValue(key);
|
|
31
|
+
onesvl.setKey(sKey);
|
|
32
|
+
let typ = Object.prototype.toString.call(opts[key]);
|
|
33
|
+
if (typ === '[object Number]') {
|
|
34
|
+
// TODO:double
|
|
35
|
+
onesvl.setInt32vl(opts[key]);
|
|
36
|
+
} else if (typ === '[object String]') {
|
|
37
|
+
// console.log(`String ${opts[key]}`)
|
|
38
|
+
onesvl.setStringvl(opts[key]);
|
|
39
|
+
} else if (typ === '[object Function]') {
|
|
40
|
+
if (this.aiotf == undefined) {
|
|
41
|
+
this.funcArr.push(opts[key]);
|
|
42
|
+
onesvl.setFuncid(this.funcArr.length - 1);
|
|
43
|
+
} else {
|
|
44
|
+
this.aiotf.funcArr.push(opts[key]);
|
|
45
|
+
onesvl.setFuncid(this.aiotf.funcArr.length - 1);
|
|
46
|
+
}
|
|
47
|
+
} else if (typ === '[object Object]') {
|
|
48
|
+
// console.log(`object ${opts[key]}`)
|
|
49
|
+
let styVaA_ = new vdom_pb.StyleValueArr();
|
|
50
|
+
styVaA_ = this.parseObj(opts[key]);
|
|
51
|
+
onesvl.setStylevlarr(styVaA_);
|
|
52
|
+
} else if (typ === '[object Array]') {
|
|
53
|
+
//TODO:default string arr
|
|
54
|
+
// console.log(`Array ${opts[key]}`)
|
|
55
|
+
let strarr = new vdom_pb.StringArr();
|
|
56
|
+
strarr.setStringvlarrList(opts[key]);
|
|
57
|
+
onesvl.setStringarr(strarr);
|
|
58
|
+
}
|
|
59
|
+
styVaA.addVlarr(onesvl);
|
|
60
|
+
}
|
|
61
|
+
return styVaA;
|
|
62
|
+
}
|
|
63
|
+
__ce__(tagName, opts, childsArr) {
|
|
64
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
65
|
+
let ce = new vdom_pb.TemplateCE();
|
|
66
|
+
ce.setTag(tagName);
|
|
67
|
+
if (Array.isArray(childsArr) && childsArr.length > 0) {
|
|
68
|
+
let arr = [];
|
|
69
|
+
for (let key in childsArr) {
|
|
70
|
+
arr.push(childsArr[key].id_);
|
|
71
|
+
}
|
|
72
|
+
tempOne.setChldsidList(arr);
|
|
73
|
+
}
|
|
74
|
+
tempOne.setId(++this.idCount);
|
|
75
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
76
|
+
ce.setOptsarrList(styVaA_.getVlarrList());
|
|
77
|
+
tempOne.setCe(ce);
|
|
78
|
+
this.expCell.addTemplatearr(tempOne);
|
|
79
|
+
return {
|
|
80
|
+
id_: this.idCount,
|
|
81
|
+
aiot_: this
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
__ci__(opts, renderFunc) {
|
|
85
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
86
|
+
let ci = new vdom_pb.TemplateCI();
|
|
87
|
+
tempOne.setId(++this.idCount);
|
|
88
|
+
if (Object.prototype.toString.call(opts.__opts__['shown']) === '[object Function]') {
|
|
89
|
+
if (this.aiotf == undefined) {
|
|
90
|
+
this.funcArr.push(opts.__opts__['shown']);
|
|
91
|
+
ci.setShownid(this.funcArr.length - 1);
|
|
92
|
+
} else {
|
|
93
|
+
this.aiotf.funcArr.push(opts.__opts__['shown']);
|
|
94
|
+
ci.setShownid(this.aiotf.funcArr.length - 1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// function(aiot) {
|
|
99
|
+
|
|
100
|
+
let aiotif = new AIOT(this);
|
|
101
|
+
aiotif.funcArr = this.funcArr;
|
|
102
|
+
let renderArr = renderFunc(aiotif);
|
|
103
|
+
let typ = Object.prototype.toString.call(renderArr);
|
|
104
|
+
if (typ === '[object Object]') {
|
|
105
|
+
ci.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
|
|
106
|
+
} else if (typ === '[object Array]') {
|
|
107
|
+
for (let key in renderArr) {
|
|
108
|
+
ci.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
this.funcArr = aiotif.aiotf.funcArr;
|
|
113
|
+
tempOne.setCi(ci);
|
|
114
|
+
this.expCell.addTemplatearr(tempOne);
|
|
115
|
+
return {
|
|
116
|
+
id_: this.idCount,
|
|
117
|
+
aiot_: this
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
__cf__(opts, renderFunc) {
|
|
121
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
122
|
+
let cf = new vdom_pb.TemplateCF();
|
|
123
|
+
tempOne.setId(++this.idCount);
|
|
124
|
+
for (let key in opts.__opts__) {
|
|
125
|
+
if (key === 'exp' && Object.prototype.toString.call(opts.__opts__[key]) === '[object Function]') {
|
|
126
|
+
if (this.aiotf == undefined) {
|
|
127
|
+
this.funcArr.push(opts.__opts__[key]);
|
|
128
|
+
cf.setExpid(this.funcArr.length - 1);
|
|
129
|
+
} else {
|
|
130
|
+
this.aiotf.funcArr.push(opts.__opts__[key]);
|
|
131
|
+
cf.setExpid(this.aiotf.funcArr.length - 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (key === 'key' && Object.prototype.toString.call(opts.__opts__[key]) === '[object String]') {
|
|
135
|
+
let vl = new vdom_pb.OneStyleValue();
|
|
136
|
+
vl.setStringvl(opts.__opts__[key]);
|
|
137
|
+
cf.setKey(vl);
|
|
138
|
+
}
|
|
139
|
+
if (key === 'value' && Object.prototype.toString.call(opts.__opts__[key]) === '[object String]') {
|
|
140
|
+
let vl = new vdom_pb.OneStyleValue();
|
|
141
|
+
vl.setStringvl(opts.__opts__[key]);
|
|
142
|
+
cf.setValue(vl);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//function($idx, $item, aiot) {
|
|
147
|
+
// function($idx, $item)
|
|
148
|
+
|
|
149
|
+
let aiotfor = new AIOT(this);
|
|
150
|
+
aiotfor.funcArr = this.funcArr;
|
|
151
|
+
let key_, value_;
|
|
152
|
+
let renderArr = renderFunc(key_, value_, aiotfor);
|
|
153
|
+
let typ = Object.prototype.toString.call(renderArr);
|
|
154
|
+
if (typ === '[object Object]') {
|
|
155
|
+
cf.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
|
|
156
|
+
} else if (typ === '[object Array]') {
|
|
157
|
+
for (let key in renderArr) {
|
|
158
|
+
cf.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.funcArr = aiotfor.aiotf.funcArr;
|
|
163
|
+
tempOne.setCf(cf);
|
|
164
|
+
this.expCell.addTemplatearr(tempOne);
|
|
165
|
+
return {
|
|
166
|
+
id_: this.idCount,
|
|
167
|
+
aiot_: this
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
__cc__(tagName, opts) {
|
|
171
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
172
|
+
let cc = new vdom_pb.TemplateCC();
|
|
173
|
+
cc.setTag(tagName);
|
|
174
|
+
tempOne.setId(++this.idCount);
|
|
175
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
176
|
+
cc.setOptsarrList(styVaA_.getVlarrList());
|
|
177
|
+
|
|
178
|
+
// 1.解决方法先生成子组件,
|
|
179
|
+
// 2.删除这项,建树使用tagName查找(遍历一遍数组)
|
|
180
|
+
cc.setExportarrid(-1);
|
|
181
|
+
tempOne.setCc(cc);
|
|
182
|
+
this.expCell.addTemplatearr(tempOne);
|
|
183
|
+
return {
|
|
184
|
+
id_: this.idCount,
|
|
185
|
+
aiot_: this
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
* @param {[[[number, string]], {[key:string]:string|number}][]} style
|
|
193
|
+
*/
|
|
194
|
+
function translateStyle(style, aiot) {
|
|
195
|
+
const exportCell = aiot.expCell;
|
|
196
|
+
style.forEach(item => {
|
|
197
|
+
const id = item[0][0][0];
|
|
198
|
+
const name = item[0][0][1];
|
|
199
|
+
const styleValue = item[1];
|
|
200
|
+
const cssCell = exportCell.addCssarr();
|
|
201
|
+
cssCell.setId(id);
|
|
202
|
+
cssCell.setName(name);
|
|
203
|
+
Object.keys(styleValue).forEach(key => {
|
|
204
|
+
const value = styleValue[key];
|
|
205
|
+
const styleVl = cssCell.addStylearr();
|
|
206
|
+
|
|
207
|
+
// 设置css属性名称
|
|
208
|
+
const pk = new vdom_pb.StyleKey();
|
|
209
|
+
pk.setValue(key);
|
|
210
|
+
styleVl.setKey(pk);
|
|
211
|
+
|
|
212
|
+
// 设置css值
|
|
213
|
+
switch (typeof value) {
|
|
214
|
+
case 'string':
|
|
215
|
+
styleVl.setStringvl(value);
|
|
216
|
+
break;
|
|
217
|
+
case 'number':
|
|
218
|
+
if (Number.isInteger(value)) {
|
|
219
|
+
styleVl.setInt32vl(value);
|
|
220
|
+
} else {
|
|
221
|
+
styleVl.setDoublevl(value);
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
return exportCell;
|
|
228
|
+
}
|
|
229
|
+
function translateTemplate(template, aiot) {
|
|
230
|
+
const vm = {};
|
|
231
|
+
if (template) {
|
|
232
|
+
// eslint-disable-next-line no-eval
|
|
233
|
+
eval(`(${template})`)(vm);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function createItem(path, style, template) {
|
|
237
|
+
const name = Path.parse(path).base;
|
|
238
|
+
// 创建aiot对象
|
|
239
|
+
let aiot = new AIOT();
|
|
240
|
+
aiot.init(name);
|
|
241
|
+
// 写入template
|
|
242
|
+
translateTemplate(template, aiot);
|
|
243
|
+
// 写入style
|
|
244
|
+
translateStyle(style, aiot);
|
|
245
|
+
return aiot;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
*
|
|
250
|
+
* @param {*} template
|
|
251
|
+
*/
|
|
252
|
+
function extractFunctions(template) {
|
|
253
|
+
// 创建aiot对象
|
|
254
|
+
let aiot = new AIOT();
|
|
255
|
+
aiot.init('temp');
|
|
256
|
+
|
|
257
|
+
// 写入template
|
|
258
|
+
translateTemplate(template, aiot);
|
|
259
|
+
return aiot.funcArr;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 创建bin文件
|
|
264
|
+
* @param {string} fileName
|
|
265
|
+
* @param {string[]} styleList
|
|
266
|
+
* @param {string[]} templateList
|
|
267
|
+
*/
|
|
268
|
+
function createBin(fileName, styleList, templateList) {
|
|
269
|
+
const dataList = styleList.map((item, index) => {
|
|
270
|
+
return createItem(fileName, JSON.parse(styleList[index]), templateList[index]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// 写入数据
|
|
274
|
+
let indexExport = new vdom_pb.ExportArr();
|
|
275
|
+
indexExport.clearValuearrList();
|
|
276
|
+
dataList.forEach(item => {
|
|
277
|
+
indexExport.addValuearr(item.expCell);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// 写入文件
|
|
281
|
+
let outbuff = indexExport.serializeBinary();
|
|
282
|
+
fs.writeFileSync(fileName, outbuff);
|
|
283
|
+
}
|
|
2
284
|
//# sourceMappingURL=protobuf.js.map
|