@aiot-toolkit/shared-utils 1.0.20-importfile-dev.2 → 1.0.20
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 +324 -1
- package/lib/buildMode/util.js +94 -1
- package/lib/index.js +573 -1
- package/lib/protobuf/protobuf.js +241 -1
- package/lib/protobuf/protobufControl.js +172 -1
- package/lib/protobuf/vdom_pb.js +2764 -1
- package/lib/record-client.js +171 -1
- package/package.json +2 -2
package/lib/protobuf/protobuf.js
CHANGED
|
@@ -1,2 +1,242 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const vdom_pb = require('./vdom_pb');
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AIOT {
|
|
8
|
+
constructor(aiotf) {
|
|
9
|
+
this.funcArr = [];
|
|
10
|
+
this.chld = [];
|
|
11
|
+
this.idCount = -1;
|
|
12
|
+
this.expCell = new vdom_pb.ExportCell();
|
|
13
|
+
this.aiotf = aiotf;
|
|
14
|
+
this.optArr = [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
init(expName) {
|
|
18
|
+
this.expCell.setTagname(expName);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
parseObj(opts) {
|
|
22
|
+
let styVaA = new vdom_pb.StyleValueArr();
|
|
23
|
+
|
|
24
|
+
for (let key in opts) {
|
|
25
|
+
let sKey = new vdom_pb.StyleKey();
|
|
26
|
+
let onesvl = new vdom_pb.OneStyleValue();
|
|
27
|
+
sKey.setValue(key);
|
|
28
|
+
onesvl.setKey(sKey);
|
|
29
|
+
let typ = Object.prototype.toString.call(opts[key]);
|
|
30
|
+
|
|
31
|
+
if (typ === '[object Number]') {
|
|
32
|
+
// TODO:double
|
|
33
|
+
onesvl.setDoublevl(opts[key]);
|
|
34
|
+
} else if (typ === '[object String]') {
|
|
35
|
+
// console.log(`String ${opts[key]}`)
|
|
36
|
+
onesvl.setStringvl(opts[key]);
|
|
37
|
+
} else if (typ === '[object Function]') {
|
|
38
|
+
if (this.aiotf == undefined) {
|
|
39
|
+
this.funcArr.push(opts[key]);
|
|
40
|
+
onesvl.setFuncid(this.funcArr.length - 1);
|
|
41
|
+
} else {
|
|
42
|
+
this.aiotf.funcArr.push(opts[key]);
|
|
43
|
+
onesvl.setFuncid(this.aiotf.funcArr.length - 1);
|
|
44
|
+
}
|
|
45
|
+
} else if (typ === '[object Object]') {
|
|
46
|
+
// console.log(`object ${opts[key]}`)
|
|
47
|
+
let styVaA_ = new vdom_pb.StyleValueArr();
|
|
48
|
+
styVaA_ = this.parseObj(opts[key]);
|
|
49
|
+
onesvl.setStylevlarr(styVaA_);
|
|
50
|
+
} else if (typ === '[object Array]') {
|
|
51
|
+
//TODO:default string arr
|
|
52
|
+
// console.log(`Array ${opts[key]}`)
|
|
53
|
+
let strarr = new vdom_pb.StringArr();
|
|
54
|
+
strarr.setStringvlarrList(opts[key]);
|
|
55
|
+
onesvl.setStringarr(strarr);
|
|
56
|
+
} else if (typ === '[object Boolean]') {
|
|
57
|
+
onesvl.setBoolvl(opts[key]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
styVaA.addVlarr(onesvl);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return styVaA;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
__cdc__(tagName, opts, childsArr) {
|
|
67
|
+
return this.__ce__(tagName, opts, childsArr, '__cdc__');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
__ce__(tagName, opts, childsArr, type = '__ce__') {
|
|
71
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
72
|
+
let ce = new vdom_pb.TemplateUnit();
|
|
73
|
+
ce.setType(type);
|
|
74
|
+
ce.setTag(tagName);
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(childsArr) && childsArr.length > 0) {
|
|
77
|
+
let arr = [];
|
|
78
|
+
|
|
79
|
+
for (let key in childsArr) {
|
|
80
|
+
arr.push(childsArr[key].id_);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
tempOne.setChldsidList(arr);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
tempOne.setId(++this.idCount);
|
|
87
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
88
|
+
ce.setOptsarrList(styVaA_.getVlarrList());
|
|
89
|
+
tempOne.setCv(ce);
|
|
90
|
+
this.expCell.addTemplatearr(tempOne);
|
|
91
|
+
return {
|
|
92
|
+
id_: this.idCount,
|
|
93
|
+
aiot_: this
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
__ci__(opts, renderFunc) {
|
|
98
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
99
|
+
let ci = new vdom_pb.TemplateUnit();
|
|
100
|
+
ci.setType('__ci__');
|
|
101
|
+
tempOne.setId(++this.idCount);
|
|
102
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
103
|
+
ci.setOptsarrList(styVaA_.getVlarrList()); // function(aiot) {
|
|
104
|
+
|
|
105
|
+
let aiotif = new AIOT(this);
|
|
106
|
+
aiotif.funcArr = this.funcArr;
|
|
107
|
+
aiotif.optArr = this.optArr;
|
|
108
|
+
let renderArr = renderFunc(aiotif);
|
|
109
|
+
let typ = Object.prototype.toString.call(renderArr);
|
|
110
|
+
|
|
111
|
+
if (typ === '[object Object]') {
|
|
112
|
+
ci.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
|
|
113
|
+
} else if (typ === '[object Array]') {
|
|
114
|
+
for (let key in renderArr) {
|
|
115
|
+
ci.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.funcArr = aiotif.aiotf.funcArr;
|
|
121
|
+
tempOne.setCv(ci);
|
|
122
|
+
this.expCell.addTemplatearr(tempOne);
|
|
123
|
+
return {
|
|
124
|
+
id_: this.idCount,
|
|
125
|
+
aiot_: this
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
__cf__(opts, renderFunc) {
|
|
130
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
131
|
+
let cf = new vdom_pb.TemplateUnit();
|
|
132
|
+
cf.setType('__cf__');
|
|
133
|
+
tempOne.setId(++this.idCount);
|
|
134
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
135
|
+
cf.setOptsarrList(styVaA_.getVlarrList());
|
|
136
|
+
let aiotfor = new AIOT();
|
|
137
|
+
aiotfor.optArr = this.optArr;
|
|
138
|
+
let key_, value_;
|
|
139
|
+
let renderArr = renderFunc(key_, value_, aiotfor);
|
|
140
|
+
let typ = Object.prototype.toString.call(renderArr);
|
|
141
|
+
|
|
142
|
+
if (typ === '[object Object]') {
|
|
143
|
+
cf.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
|
|
144
|
+
} else if (typ === '[object Array]') {
|
|
145
|
+
for (let key in renderArr) {
|
|
146
|
+
cf.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (aiotfor.funcArr.length > 0) {
|
|
152
|
+
const fun = function ($idx, $item) {
|
|
153
|
+
return aiotfor.aiotf.funcArr;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
fun.aiotfor = aiotfor;
|
|
157
|
+
fun.aiotfor.key = opts.__opts__['key'];
|
|
158
|
+
fun.aiotfor.value = opts.__opts__['value'];
|
|
159
|
+
this.funcArr.push(fun);
|
|
160
|
+
cf.setFuncrender(this.funcArr.length - 1);
|
|
161
|
+
} else {
|
|
162
|
+
cf.setFuncrender(-1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
tempOne.setCv(cf);
|
|
166
|
+
this.expCell.addTemplatearr(tempOne);
|
|
167
|
+
return {
|
|
168
|
+
id_: this.idCount,
|
|
169
|
+
aiot_: this
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
__cc__(tagName, opts) {
|
|
174
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
175
|
+
let cc = new vdom_pb.TemplateUnit();
|
|
176
|
+
cc.setType('__cc__');
|
|
177
|
+
cc.setTag(tagName);
|
|
178
|
+
tempOne.setId(++this.idCount); // 设置__opts__在数组中得索引
|
|
179
|
+
// if (Object.keys(opts.__opts__).length > 0) {
|
|
180
|
+
// this.optArr.push(opts.__opts__) //save to js
|
|
181
|
+
// cc.setOptsid(this.optArr.length - 1)
|
|
182
|
+
// } else {
|
|
183
|
+
// cc.setOptsid(-1)
|
|
184
|
+
// }
|
|
185
|
+
|
|
186
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
187
|
+
cc.setOptsarrList(styVaA_.getVlarrList());
|
|
188
|
+
tempOne.setCv(cc);
|
|
189
|
+
this.expCell.addTemplatearr(tempOne);
|
|
190
|
+
return {
|
|
191
|
+
id_: this.idCount,
|
|
192
|
+
aiot_: this
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
__cb__(opts, renderFunc) {
|
|
197
|
+
let tempOne = new vdom_pb.TemplateOne();
|
|
198
|
+
let cb = new vdom_pb.TemplateUnit();
|
|
199
|
+
cb.setType('__cb__');
|
|
200
|
+
tempOne.setId(++this.idCount);
|
|
201
|
+
let styVaA_ = this.parseObj(opts.__opts__);
|
|
202
|
+
cb.setOptsarrList(styVaA_.getVlarrList());
|
|
203
|
+
let aiotcb = new AIOT();
|
|
204
|
+
aiotcb.optArr = this.optArr;
|
|
205
|
+
let $data;
|
|
206
|
+
let renderArr = renderFunc($data, aiotcb);
|
|
207
|
+
let typ = Object.prototype.toString.call(renderArr);
|
|
208
|
+
|
|
209
|
+
if (typ === '[object Object]') {
|
|
210
|
+
cb.setTemplaterenderList(renderArr.aiot_.expCell.getTemplatearrList());
|
|
211
|
+
} else if (typ === '[object Array]') {
|
|
212
|
+
for (let key in renderArr) {
|
|
213
|
+
cb.setTemplaterenderList(renderArr[key].aiot_.expCell.getTemplatearrList());
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (aiotcb.funcArr.length > 0) {
|
|
219
|
+
const fun = function ($data) {
|
|
220
|
+
return aiotcb.aiotf.funcArr;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
fun.aiotcb = aiotcb;
|
|
224
|
+
this.funcArr.push(fun);
|
|
225
|
+
cb.setFuncrender(this.funcArr.length - 1);
|
|
226
|
+
} else {
|
|
227
|
+
cb.setFuncrender(-1);
|
|
228
|
+
} // this.funcArr = aiotcb.aiotf.funcArr
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
tempOne.setCv(cb);
|
|
232
|
+
this.expCell.addTemplatearr(tempOne);
|
|
233
|
+
return {
|
|
234
|
+
id_: this.idCount,
|
|
235
|
+
aiot_: this
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
module.exports = AIOT;
|
|
2
242
|
//# sourceMappingURL=protobuf.js.map
|
|
@@ -1,2 +1,173 @@
|
|
|
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
|
+
|
|
9
|
+
var _lib = require("../../lib");
|
|
10
|
+
|
|
11
|
+
const vdom_pb = require('./vdom_pb');
|
|
12
|
+
|
|
13
|
+
const Path = require('path');
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
|
|
17
|
+
const AIOT = require('./protobuf');
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {[[[number, string]], {[key:string]:string|number}][]} style
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function translateStyle(style, aiot) {
|
|
25
|
+
const exportCell = aiot.expCell;
|
|
26
|
+
style.forEach(item => {
|
|
27
|
+
const hasProperty = item.length === 3;
|
|
28
|
+
let property;
|
|
29
|
+
let selectorList = item[0];
|
|
30
|
+
let styleValue = item[1];
|
|
31
|
+
|
|
32
|
+
if (hasProperty) {
|
|
33
|
+
property = item[0];
|
|
34
|
+
selectorList = item[1];
|
|
35
|
+
styleValue = item[2];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const cssCell = exportCell.addCssarr(); // 如果有 property,写入
|
|
39
|
+
|
|
40
|
+
if (hasProperty && property) {
|
|
41
|
+
Object.keys(property).forEach(key => {
|
|
42
|
+
const value = property[key];
|
|
43
|
+
const propertyArr = cssCell.addPropertyarr(); // 设置属性名
|
|
44
|
+
|
|
45
|
+
const propertyKey = new vdom_pb.StyleKey();
|
|
46
|
+
propertyKey.setValue(key);
|
|
47
|
+
propertyArr.setKey(propertyKey); // 设置属性值
|
|
48
|
+
|
|
49
|
+
switch (typeof value) {
|
|
50
|
+
case 'string':
|
|
51
|
+
propertyArr.setStringvl(value);
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
case 'number':
|
|
55
|
+
if (Number.isInteger(value)) {
|
|
56
|
+
propertyArr.setInt32vl(value);
|
|
57
|
+
} else {
|
|
58
|
+
propertyArr.setDoublevl(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
} // 写入选择器
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
selectorList.forEach(selectorItem => {
|
|
68
|
+
const selector = cssCell.addSelectorarr();
|
|
69
|
+
selector.setId(selectorItem[0]);
|
|
70
|
+
selector.setName(selectorItem[1]);
|
|
71
|
+
}); // 写入属性值
|
|
72
|
+
|
|
73
|
+
Object.keys(styleValue).forEach(key => {
|
|
74
|
+
const value = styleValue[key];
|
|
75
|
+
const styleVl = cssCell.addStylearr(); // 设置css属性名称
|
|
76
|
+
|
|
77
|
+
const pk = new vdom_pb.StyleKey();
|
|
78
|
+
pk.setValue(key);
|
|
79
|
+
styleVl.setKey(pk);
|
|
80
|
+
const valueType = typeof value; // 设置css值
|
|
81
|
+
|
|
82
|
+
switch (valueType) {
|
|
83
|
+
case 'string':
|
|
84
|
+
styleVl.setStringvl(value);
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case 'number':
|
|
88
|
+
if (Number.isInteger(value)) {
|
|
89
|
+
styleVl.setInt32vl(value);
|
|
90
|
+
} else {
|
|
91
|
+
styleVl.setDoublevl(value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
case 'object':
|
|
97
|
+
styleVl.setStylevlarr(aiot.parseObj(value));
|
|
98
|
+
break;
|
|
99
|
+
|
|
100
|
+
default:
|
|
101
|
+
_lib.colorconsole.warn(`CssValue Of ${valueType} NotProcessed`);
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return exportCell;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function translateTemplate(template, aiot) {
|
|
110
|
+
const vm = {};
|
|
111
|
+
|
|
112
|
+
if (template) {
|
|
113
|
+
// eslint-disable-next-line no-eval
|
|
114
|
+
eval(`(${template})`)(vm);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createItem(entryName, style, template) {
|
|
119
|
+
// 创建aiot对象
|
|
120
|
+
let aiot = new AIOT();
|
|
121
|
+
aiot.init(entryName || 'entry'); // 写入template
|
|
122
|
+
|
|
123
|
+
translateTemplate(template, aiot); // 写入style
|
|
124
|
+
|
|
125
|
+
translateStyle(style, aiot);
|
|
126
|
+
return aiot;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @param {*} template
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
function extractFunctions(template) {
|
|
135
|
+
// 创建aiot对象
|
|
136
|
+
let aiot = new AIOT();
|
|
137
|
+
aiot.init('temp'); // 写入template
|
|
138
|
+
|
|
139
|
+
translateTemplate(template, aiot);
|
|
140
|
+
return aiot;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 创建bin文件
|
|
144
|
+
* @param {string} fileName
|
|
145
|
+
* @param {string[]} styleList
|
|
146
|
+
* @param {string[]} templateList
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
function createBin(fileName, tagList, styleList, templateList) {
|
|
151
|
+
const dataList = styleList.map((item, index) => {
|
|
152
|
+
return createItem(tagList[index], JSON.parse(item), templateList[index]);
|
|
153
|
+
}); // 写入数据
|
|
154
|
+
|
|
155
|
+
let indexExport = new vdom_pb.ExportArr();
|
|
156
|
+
indexExport.clearValuearrList();
|
|
157
|
+
dataList.forEach(item => {
|
|
158
|
+
indexExport.addValuearr(item.expCell);
|
|
159
|
+
}); // 如果文件夹不存在,则创建
|
|
160
|
+
|
|
161
|
+
const folder = Path.dirname(fileName);
|
|
162
|
+
|
|
163
|
+
if (!fs.existsSync(folder)) {
|
|
164
|
+
fs.mkdirSync(folder, {
|
|
165
|
+
recursive: true
|
|
166
|
+
});
|
|
167
|
+
} // 写入文件
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
let outbuff = indexExport.serializeBinary();
|
|
171
|
+
fs.writeFileSync(fileName, outbuff);
|
|
172
|
+
}
|
|
2
173
|
//# sourceMappingURL=protobufControl.js.map
|