@easyv/react-component-builder 0.19.3 → 0.19.5-beta.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/config/paths.js +24 -24
- package/config/webpack.config.build.js +70 -70
- package/config/webpack.config.common.js +126 -126
- package/config/webpack.config.js +126 -126
- package/launcher/build.js +122 -120
- package/launcher/generate.js +99 -99
- package/launcher/start.js +238 -238
- package/loaders/react-entry-loader.js +470 -430
- package/package.json +76 -76
- package/public/component.ejs +51 -51
- package/public/home.ejs +21 -21
- package/templates/basic/assets/logo.png +0 -0
- package/templates/basic/config/main.data.json +14 -14
- package/templates/basic/config/main.json +6 -6
- package/templates/basic/index.jsx +26 -26
- package/templates/basic/styles/index.module.css +3 -3
- package/templates/basic/utils/bind-children.js +10 -10
- package/templates/basic/utils/reduce-config.js +20 -20
- package/templates/three-component/config/main.data.json +14 -14
- package/templates/three-component/config/main.json +76 -76
- package/templates/three-component/index.jsx +122 -122
- package/templates/three-component/utils/Component.js +274 -274
- package/templates/three-component/utils/OrbitControls.js +1051 -1051
- package/templates/three-component/utils/reduce-config.js +20 -20
- package/utils/auto-assign-port.js +11 -11
- package/utils/index.js +91 -91
- package/utils/openBrowser.js +153 -153
- package/utils/openChrome.applescript +94 -94
|
@@ -1,430 +1,470 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 给导出的组件添加static方法获取配置文件
|
|
3
|
-
*/
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const glob = require('glob');
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
// const vm = require('vm');
|
|
8
|
-
|
|
9
|
-
const parser = require('@babel/parser').parse;
|
|
10
|
-
const traverse = require('@babel/traverse').default;
|
|
11
|
-
const generate = require('@babel/generator').default;
|
|
12
|
-
const t = require('@babel/types');
|
|
13
|
-
|
|
14
|
-
function getOldDimension(width, height, hasUndeline) {
|
|
15
|
-
if (hasUndeline) {
|
|
16
|
-
return {
|
|
17
|
-
_name: 'dimension', // 定义位置宽高
|
|
18
|
-
_displayName: '位置尺寸',
|
|
19
|
-
_value: [
|
|
20
|
-
{
|
|
21
|
-
_name: 'chartPosition',
|
|
22
|
-
_displayName: '图表位置',
|
|
23
|
-
_value: [
|
|
24
|
-
{
|
|
25
|
-
_name: 'left',
|
|
26
|
-
_displayName: 'X轴坐标',
|
|
27
|
-
_value: 100, // 开发环境默认显示位置
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
_name: 'top',
|
|
31
|
-
_displayName: 'Y轴坐标',
|
|
32
|
-
_value: 100, // 开发环境默认显示位置
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
_name: 'chartDimension',
|
|
38
|
-
_displayName: '图表尺寸',
|
|
39
|
-
_value: [
|
|
40
|
-
{
|
|
41
|
-
_name: 'width',
|
|
42
|
-
_displayName: '宽度',
|
|
43
|
-
_value: width, // 组件默认宽
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
_name: 'height',
|
|
47
|
-
_displayName: '高度',
|
|
48
|
-
_value: height, // 组件默认高
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
name: 'dimension', // 定义位置宽高
|
|
57
|
-
displayName: '位置尺寸',
|
|
58
|
-
value: [
|
|
59
|
-
{
|
|
60
|
-
name: 'chartPosition',
|
|
61
|
-
displayName: '图表位置',
|
|
62
|
-
value: [
|
|
63
|
-
{
|
|
64
|
-
name: 'left',
|
|
65
|
-
displayName: 'X轴坐标',
|
|
66
|
-
value: 100, // 开发环境默认显示位置
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: 'top',
|
|
70
|
-
displayName: 'Y轴坐标',
|
|
71
|
-
value: 100, // 开发环境默认显示位置
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: 'chartDimension',
|
|
77
|
-
displayName: '图表尺寸',
|
|
78
|
-
value: [
|
|
79
|
-
{
|
|
80
|
-
name: 'width',
|
|
81
|
-
displayName: '宽度',
|
|
82
|
-
value: width, // 组件默认宽
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: 'height',
|
|
86
|
-
displayName: '高度',
|
|
87
|
-
value: height, // 组件默认高
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = function (content, map, meta) {
|
|
96
|
-
var callback = this.async();
|
|
97
|
-
const query = this.query || {};
|
|
98
|
-
|
|
99
|
-
const modulePath = this.context;
|
|
100
|
-
let file = content;
|
|
101
|
-
|
|
102
|
-
// 兼容旧的写法
|
|
103
|
-
if (~file.indexOf('getDefaultConfig')) {
|
|
104
|
-
return callback(null, file);
|
|
105
|
-
}
|
|
106
|
-
const configPath = `${modulePath}/config`;
|
|
107
|
-
// 添加watcher依赖
|
|
108
|
-
this.addContextDependency(path.resolve(configPath));
|
|
109
|
-
|
|
110
|
-
glob(
|
|
111
|
-
`{*.data.{json,js},subConfigs/*.data.{json,js}}`,
|
|
112
|
-
{
|
|
113
|
-
cwd: configPath,
|
|
114
|
-
},
|
|
115
|
-
function (err, matches) {
|
|
116
|
-
if (err || matches.length === 0) {
|
|
117
|
-
callback(
|
|
118
|
-
`main.json or main.data.json cannot be found in ${configPath}`,
|
|
119
|
-
);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
// 读取配置文件
|
|
125
|
-
const main = {};
|
|
126
|
-
let subConfigs = [];
|
|
127
|
-
const subDatas = [];
|
|
128
|
-
const names = new Set();
|
|
129
|
-
if (
|
|
130
|
-
matches
|
|
131
|
-
.map((filename) => filename.split('.')[0])
|
|
132
|
-
.some((name, i) => {
|
|
133
|
-
let config;
|
|
134
|
-
try {
|
|
135
|
-
let jsonFile = fs.existsSync(
|
|
136
|
-
path.join(configPath, name + '.json'),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
if (jsonFile) {
|
|
140
|
-
config = JSON.parse(
|
|
141
|
-
fs.readFileSync(path.resolve(configPath, name + '.json')),
|
|
142
|
-
{ encoding: 'utf8' },
|
|
143
|
-
);
|
|
144
|
-
} else {
|
|
145
|
-
Object.keys(require.cache).forEach(function (key) {
|
|
146
|
-
if (key.includes('node_modules')) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
delete require.cache[key];
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
config = require(path.resolve(
|
|
153
|
-
configPath,
|
|
154
|
-
name + '.js',
|
|
155
|
-
)).default;
|
|
156
|
-
}
|
|
157
|
-
} catch (error) {
|
|
158
|
-
error.message += ` in ${configPath}${name}.json or ${configPath}${name}.js`;
|
|
159
|
-
callback(error);
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
let data;
|
|
164
|
-
try {
|
|
165
|
-
let dataJsonFile = fs.existsSync(
|
|
166
|
-
path.join(configPath, name + '.data.json'),
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
if (dataJsonFile) {
|
|
170
|
-
data = JSON.parse(
|
|
171
|
-
fs.readFileSync(
|
|
172
|
-
path.resolve(configPath, name + '.data.json'),
|
|
173
|
-
{ encoding: 'utf8' },
|
|
174
|
-
),
|
|
175
|
-
);
|
|
176
|
-
} else {
|
|
177
|
-
delete require.cache[
|
|
178
|
-
require.resolve(path.resolve(configPath, name + '.data.js'))
|
|
179
|
-
];
|
|
180
|
-
data = require(path.resolve(
|
|
181
|
-
configPath,
|
|
182
|
-
name + '.data.js',
|
|
183
|
-
)).default;
|
|
184
|
-
}
|
|
185
|
-
} catch (error) {
|
|
186
|
-
error.message += ` in ${configPath}${name}.data.json or ${configPath}${name}.data.js`;
|
|
187
|
-
callback(error);
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 给导出的组件添加static方法获取配置文件
|
|
3
|
+
*/
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const glob = require('glob');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
// const vm = require('vm');
|
|
8
|
+
|
|
9
|
+
const parser = require('@babel/parser').parse;
|
|
10
|
+
const traverse = require('@babel/traverse').default;
|
|
11
|
+
const generate = require('@babel/generator').default;
|
|
12
|
+
const t = require('@babel/types');
|
|
13
|
+
|
|
14
|
+
function getOldDimension(width, height, hasUndeline) {
|
|
15
|
+
if (hasUndeline) {
|
|
16
|
+
return {
|
|
17
|
+
_name: 'dimension', // 定义位置宽高
|
|
18
|
+
_displayName: '位置尺寸',
|
|
19
|
+
_value: [
|
|
20
|
+
{
|
|
21
|
+
_name: 'chartPosition',
|
|
22
|
+
_displayName: '图表位置',
|
|
23
|
+
_value: [
|
|
24
|
+
{
|
|
25
|
+
_name: 'left',
|
|
26
|
+
_displayName: 'X轴坐标',
|
|
27
|
+
_value: 100, // 开发环境默认显示位置
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
_name: 'top',
|
|
31
|
+
_displayName: 'Y轴坐标',
|
|
32
|
+
_value: 100, // 开发环境默认显示位置
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
_name: 'chartDimension',
|
|
38
|
+
_displayName: '图表尺寸',
|
|
39
|
+
_value: [
|
|
40
|
+
{
|
|
41
|
+
_name: 'width',
|
|
42
|
+
_displayName: '宽度',
|
|
43
|
+
_value: width, // 组件默认宽
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
_name: 'height',
|
|
47
|
+
_displayName: '高度',
|
|
48
|
+
_value: height, // 组件默认高
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
name: 'dimension', // 定义位置宽高
|
|
57
|
+
displayName: '位置尺寸',
|
|
58
|
+
value: [
|
|
59
|
+
{
|
|
60
|
+
name: 'chartPosition',
|
|
61
|
+
displayName: '图表位置',
|
|
62
|
+
value: [
|
|
63
|
+
{
|
|
64
|
+
name: 'left',
|
|
65
|
+
displayName: 'X轴坐标',
|
|
66
|
+
value: 100, // 开发环境默认显示位置
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'top',
|
|
70
|
+
displayName: 'Y轴坐标',
|
|
71
|
+
value: 100, // 开发环境默认显示位置
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'chartDimension',
|
|
77
|
+
displayName: '图表尺寸',
|
|
78
|
+
value: [
|
|
79
|
+
{
|
|
80
|
+
name: 'width',
|
|
81
|
+
displayName: '宽度',
|
|
82
|
+
value: width, // 组件默认宽
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'height',
|
|
86
|
+
displayName: '高度',
|
|
87
|
+
value: height, // 组件默认高
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = function (content, map, meta) {
|
|
96
|
+
var callback = this.async();
|
|
97
|
+
const query = this.query || {};
|
|
98
|
+
|
|
99
|
+
const modulePath = this.context;
|
|
100
|
+
let file = content;
|
|
101
|
+
|
|
102
|
+
// 兼容旧的写法
|
|
103
|
+
if (~file.indexOf('getDefaultConfig')) {
|
|
104
|
+
return callback(null, file);
|
|
105
|
+
}
|
|
106
|
+
const configPath = `${modulePath}/config`;
|
|
107
|
+
// 添加watcher依赖
|
|
108
|
+
this.addContextDependency(path.resolve(configPath));
|
|
109
|
+
|
|
110
|
+
glob(
|
|
111
|
+
`{*.data.{json,js},subConfigs/*.data.{json,js}}`,
|
|
112
|
+
{
|
|
113
|
+
cwd: configPath,
|
|
114
|
+
},
|
|
115
|
+
function (err, matches) {
|
|
116
|
+
if (err || matches.length === 0) {
|
|
117
|
+
callback(
|
|
118
|
+
`main.json or main.data.json cannot be found in ${configPath}`,
|
|
119
|
+
);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
// 读取配置文件
|
|
125
|
+
const main = {};
|
|
126
|
+
let subConfigs = [];
|
|
127
|
+
const subDatas = [];
|
|
128
|
+
const names = new Set();
|
|
129
|
+
if (
|
|
130
|
+
matches
|
|
131
|
+
.map((filename) => filename.split('.')[0])
|
|
132
|
+
.some((name, i) => {
|
|
133
|
+
let config;
|
|
134
|
+
try {
|
|
135
|
+
let jsonFile = fs.existsSync(
|
|
136
|
+
path.join(configPath, name + '.json'),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (jsonFile) {
|
|
140
|
+
config = JSON.parse(
|
|
141
|
+
fs.readFileSync(path.resolve(configPath, name + '.json')),
|
|
142
|
+
{ encoding: 'utf8' },
|
|
143
|
+
);
|
|
144
|
+
} else {
|
|
145
|
+
Object.keys(require.cache).forEach(function (key) {
|
|
146
|
+
if (key.includes('node_modules')) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
delete require.cache[key];
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
config = require(path.resolve(
|
|
153
|
+
configPath,
|
|
154
|
+
name + '.js',
|
|
155
|
+
)).default;
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
error.message += ` in ${configPath}${name}.json or ${configPath}${name}.js`;
|
|
159
|
+
callback(error);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let data;
|
|
164
|
+
try {
|
|
165
|
+
let dataJsonFile = fs.existsSync(
|
|
166
|
+
path.join(configPath, name + '.data.json'),
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
if (dataJsonFile) {
|
|
170
|
+
data = JSON.parse(
|
|
171
|
+
fs.readFileSync(
|
|
172
|
+
path.resolve(configPath, name + '.data.json'),
|
|
173
|
+
{ encoding: 'utf8' },
|
|
174
|
+
),
|
|
175
|
+
);
|
|
176
|
+
} else {
|
|
177
|
+
delete require.cache[
|
|
178
|
+
require.resolve(path.resolve(configPath, name + '.data.js'))
|
|
179
|
+
];
|
|
180
|
+
data = require(path.resolve(
|
|
181
|
+
configPath,
|
|
182
|
+
name + '.data.js',
|
|
183
|
+
)).default;
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
error.message += ` in ${configPath}${name}.data.json or ${configPath}${name}.data.js`;
|
|
187
|
+
callback(error);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
/----------- common assets start -------------/
|
|
191
|
+
let commonAssets;
|
|
192
|
+
try {
|
|
193
|
+
let dataJsonFile = fs.existsSync(
|
|
194
|
+
path.join(configPath, name + '.common.assets.json'),
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (dataJsonFile) {
|
|
198
|
+
commonAssets = JSON.parse(
|
|
199
|
+
fs.readFileSync(
|
|
200
|
+
path.resolve(configPath, name + '.common.assets.json'),
|
|
201
|
+
{ encoding: 'utf8' },
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
|
+
} else {
|
|
205
|
+
delete require.cache[
|
|
206
|
+
require.resolve(path.resolve(configPath, name + '.common.assets.js'))
|
|
207
|
+
];
|
|
208
|
+
commonAssets = require(path.resolve(
|
|
209
|
+
configPath,
|
|
210
|
+
name + '.common.assets.js',
|
|
211
|
+
)).default;
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
// 公共资源配置非必填,若不存在可跳过
|
|
215
|
+
// error.message += ` in ${configPath}${name}.common.assets.json or ${configPath}${name}.common.assets.js`;
|
|
216
|
+
// callback(error);
|
|
217
|
+
}
|
|
218
|
+
/----------- common assets end -------------/
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
if (names.has(config.base.module_name)) {
|
|
222
|
+
callback(
|
|
223
|
+
new Error(
|
|
224
|
+
`base.module_name ${config.base.module_name} was duplicated in ${configPath}`,
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
return true;
|
|
228
|
+
} else {
|
|
229
|
+
names.add(config.base.module_name);
|
|
230
|
+
}
|
|
231
|
+
if (name === 'main') {
|
|
232
|
+
main.config = config;
|
|
233
|
+
main.data = data;
|
|
234
|
+
main.commonAssets = commonAssets;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const id = Math.random().toString(16).slice(2);
|
|
238
|
+
config.id = id;
|
|
239
|
+
data.id = id;
|
|
240
|
+
subConfigs.push(config);
|
|
241
|
+
subDatas.push(data);
|
|
242
|
+
})
|
|
243
|
+
)
|
|
244
|
+
return;
|
|
245
|
+
|
|
246
|
+
// 解析导出变量名
|
|
247
|
+
let vname = '',
|
|
248
|
+
exportName = `__EASYV_COMPONENT__`;
|
|
249
|
+
const ast = parser(content, {
|
|
250
|
+
sourceType: 'module',
|
|
251
|
+
plugins: ['jsx', 'typescript', 'classProperties'],
|
|
252
|
+
});
|
|
253
|
+
traverse(ast, {
|
|
254
|
+
ExportDefaultDeclaration(path) {
|
|
255
|
+
const child = path.node.declaration;
|
|
256
|
+
|
|
257
|
+
if (child.type === 'ClassDeclaration') {
|
|
258
|
+
// e.g: export default class a {}
|
|
259
|
+
if (child.id) {
|
|
260
|
+
vname = child.id.name;
|
|
261
|
+
// e.g: export default class {}
|
|
262
|
+
} else {
|
|
263
|
+
vname = exportName;
|
|
264
|
+
child.id = t.identifier(exportName);
|
|
265
|
+
}
|
|
266
|
+
// e.g: export default memo()
|
|
267
|
+
// e.g: export default () => {}
|
|
268
|
+
} else if (
|
|
269
|
+
!!~[
|
|
270
|
+
'CallExpression',
|
|
271
|
+
'ArrowFunctionExpression',
|
|
272
|
+
'FunctionExpression',
|
|
273
|
+
].indexOf(child.type)
|
|
274
|
+
) {
|
|
275
|
+
const exportIdentifier = t.identifier(exportName);
|
|
276
|
+
path.insertBefore(
|
|
277
|
+
t.variableDeclaration('const', [
|
|
278
|
+
t.variableDeclarator(exportIdentifier, child),
|
|
279
|
+
]),
|
|
280
|
+
);
|
|
281
|
+
path.node.declaration = exportIdentifier;
|
|
282
|
+
vname = exportName;
|
|
283
|
+
// e.g: export default function(){}
|
|
284
|
+
} else if (!!~['FunctionDeclaration'].indexOf(child.type)) {
|
|
285
|
+
const exportIdentifier = t.identifier(exportName);
|
|
286
|
+
child.id = exportIdentifier;
|
|
287
|
+
vname = exportName;
|
|
288
|
+
// e.g: export default a;
|
|
289
|
+
} else if (child.type === 'Identifier') {
|
|
290
|
+
vname = child.name;
|
|
291
|
+
}
|
|
292
|
+
path.stop();
|
|
293
|
+
},
|
|
294
|
+
ExportNamedDeclaration(path) {
|
|
295
|
+
const child = path.node.declaration;
|
|
296
|
+
// e.g: export const a = {};
|
|
297
|
+
if (child.type === 'VariableDeclaration') {
|
|
298
|
+
const exportIdentifier = child.declarations[0].id;
|
|
299
|
+
vname = exportIdentifier.name;
|
|
300
|
+
path.replaceWith(child);
|
|
301
|
+
path.insertAfter(t.exportDefaultDeclaration(exportIdentifier));
|
|
302
|
+
// e.g: export function a(){};
|
|
303
|
+
} else if (child.type === 'FunctionDeclaration') {
|
|
304
|
+
const exportIdentifier = child.id;
|
|
305
|
+
path.replaceWith(child);
|
|
306
|
+
path.insertAfter(t.exportDefaultDeclaration(exportIdentifier));
|
|
307
|
+
}
|
|
308
|
+
path.stop();
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
file = generate(ast, { quotes: 'single', retainLines: false }).code;
|
|
312
|
+
if (!vname) {
|
|
313
|
+
return callback(
|
|
314
|
+
`cannot found default export object in ${path.join(
|
|
315
|
+
modulePath,
|
|
316
|
+
'index',
|
|
317
|
+
)}`,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
// 检查width/height
|
|
321
|
+
const mainConfig = main.config;
|
|
322
|
+
// if (!('width' in mainConfig) || !('height' in mainConfig)) {
|
|
323
|
+
// return callback(`main.json lack field 'width' or 'height'.`)
|
|
324
|
+
// }
|
|
325
|
+
|
|
326
|
+
// 添加width/height属性兼容老版本
|
|
327
|
+
let updateChart = false;
|
|
328
|
+
const hasUnderline = mainConfig.configuration[0]
|
|
329
|
+
? '_value' in mainConfig.configuration[0]
|
|
330
|
+
: false;
|
|
331
|
+
const keys = {
|
|
332
|
+
name: hasUnderline ? '_name' : 'name',
|
|
333
|
+
displayName: hasUnderline ? '_displayName' : 'displayName',
|
|
334
|
+
value: hasUnderline ? '_value' : 'value',
|
|
335
|
+
type: hasUnderline ? '_type' : 'type',
|
|
336
|
+
children: hasUnderline ? '_children' : 'children',
|
|
337
|
+
};
|
|
338
|
+
mainConfig.configuration = mainConfig.configuration.map((item) => {
|
|
339
|
+
if (item[keys.name] === 'chart') {
|
|
340
|
+
let values = item._value || item.value;
|
|
341
|
+
values = values.map((item) => {
|
|
342
|
+
if (item[keys.name] === 'dimension') {
|
|
343
|
+
updateChart = true;
|
|
344
|
+
return item;
|
|
345
|
+
// return getOldDimension(mainConfig.width, mainConfig.height, hasUnderline)
|
|
346
|
+
}
|
|
347
|
+
return item;
|
|
348
|
+
});
|
|
349
|
+
if (!updateChart) {
|
|
350
|
+
values.unshift(
|
|
351
|
+
getOldDimension(
|
|
352
|
+
mainConfig.width,
|
|
353
|
+
mainConfig.height,
|
|
354
|
+
hasUnderline,
|
|
355
|
+
),
|
|
356
|
+
);
|
|
357
|
+
updateChart = true;
|
|
358
|
+
}
|
|
359
|
+
item[keys.value] = values;
|
|
360
|
+
return item;
|
|
361
|
+
}
|
|
362
|
+
return item;
|
|
363
|
+
});
|
|
364
|
+
if (!updateChart) {
|
|
365
|
+
const chart = {
|
|
366
|
+
[keys.name]: 'chart',
|
|
367
|
+
[keys.displayName]: '组件',
|
|
368
|
+
[keys.value]: [
|
|
369
|
+
getOldDimension(
|
|
370
|
+
mainConfig.width,
|
|
371
|
+
mainConfig.height,
|
|
372
|
+
hasUnderline,
|
|
373
|
+
),
|
|
374
|
+
],
|
|
375
|
+
};
|
|
376
|
+
mainConfig.configuration.unshift(chart);
|
|
377
|
+
}
|
|
378
|
+
console.log(
|
|
379
|
+
JSON.stringify(
|
|
380
|
+
main.commonAssets
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
// 公共资源配置
|
|
384
|
+
if (main.commonAssets && Array.isArray(main.commonAssets)) {
|
|
385
|
+
mainConfig['commonAssets'] = main.commonAssets
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 子组件排序,有配置项则以chilren排序,否则以文件顺序排序
|
|
389
|
+
if (mainConfig.children) {
|
|
390
|
+
subConfigs = mainConfig.children.reduce((all, item) => {
|
|
391
|
+
let childConfig = subConfigs.find(
|
|
392
|
+
(d) => d.base.module_name === item,
|
|
393
|
+
);
|
|
394
|
+
return childConfig ? all.concat(childConfig) : all;
|
|
395
|
+
}, []);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (query.isBuild) {
|
|
399
|
+
// 兼容平台子组件配置
|
|
400
|
+
if (subConfigs.length) {
|
|
401
|
+
const defineMap = subConfigs.reduce((a, b) => {
|
|
402
|
+
a[b.base.module_name] = b;
|
|
403
|
+
return a;
|
|
404
|
+
}, {});
|
|
405
|
+
const defineChildren =
|
|
406
|
+
mainConfig.children ||
|
|
407
|
+
subConfigs.map((item) => item.base.module_name);
|
|
408
|
+
const presetChidlren = mainConfig.presetChildren || [];
|
|
409
|
+
|
|
410
|
+
const children = {
|
|
411
|
+
[keys.name]: 'children',
|
|
412
|
+
[keys.displayName]: '子组件',
|
|
413
|
+
[keys.value]: [
|
|
414
|
+
{
|
|
415
|
+
[keys.name]: 'component',
|
|
416
|
+
[keys.displayName]: '管理',
|
|
417
|
+
[keys.value]: [
|
|
418
|
+
{
|
|
419
|
+
[keys.name]: 'list',
|
|
420
|
+
[keys.displayName]: '',
|
|
421
|
+
[keys.value]: presetChidlren
|
|
422
|
+
.filter((id) => defineMap[id])
|
|
423
|
+
.map((id) => {
|
|
424
|
+
const { base } = defineMap[id];
|
|
425
|
+
return { label: base.name, name: base.module_name };
|
|
426
|
+
}),
|
|
427
|
+
[keys.type]: 'children',
|
|
428
|
+
[keys.children]: defineChildren
|
|
429
|
+
.filter((id) => defineMap[id])
|
|
430
|
+
.map((id) => {
|
|
431
|
+
const { base } = defineMap[id];
|
|
432
|
+
return { name: base.name, value: base.module_name };
|
|
433
|
+
}),
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
};
|
|
439
|
+
mainConfig.configuration.push(children);
|
|
440
|
+
}
|
|
441
|
+
// 替换modulename
|
|
442
|
+
if (query.uniqueId) {
|
|
443
|
+
mainConfig.base.module_name += '.' + query.uniqueId;
|
|
444
|
+
}
|
|
445
|
+
// 删除平台无法识别的参数
|
|
446
|
+
delete mainConfig.children;
|
|
447
|
+
delete mainConfig.presetChildren;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
file += '\n';
|
|
451
|
+
file += `${vname}.getDefaultConfig=function(){return ${JSON.stringify(
|
|
452
|
+
mainConfig,
|
|
453
|
+
)}};`;
|
|
454
|
+
file += `${vname}.getDefaultData=function(){return ${JSON.stringify(
|
|
455
|
+
main.data,
|
|
456
|
+
)}};`;
|
|
457
|
+
file += `${vname}.getDefaultChildrenConfig=function(){return ${JSON.stringify(
|
|
458
|
+
subConfigs,
|
|
459
|
+
)}};`;
|
|
460
|
+
file += `${vname}.getDefaultChildrenData=function(){return ${JSON.stringify(
|
|
461
|
+
subDatas,
|
|
462
|
+
)}};`;
|
|
463
|
+
|
|
464
|
+
callback(null, file);
|
|
465
|
+
} catch (e) {
|
|
466
|
+
callback(e);
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
);
|
|
470
|
+
};
|