@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.
@@ -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
- if (names.has(config.base.module_name)) {
192
- callback(
193
- new Error(
194
- `base.module_name ${config.base.module_name} was duplicated in ${configPath}`,
195
- ),
196
- );
197
- return true;
198
- } else {
199
- names.add(config.base.module_name);
200
- }
201
- if (name === 'main') {
202
- main.config = config;
203
- main.data = data;
204
- return;
205
- }
206
- const id = Math.random().toString(16).slice(2);
207
- config.id = id;
208
- data.id = id;
209
- subConfigs.push(config);
210
- subDatas.push(data);
211
- })
212
- )
213
- return;
214
-
215
- // 解析导出变量名
216
- let vname = '',
217
- exportName = `__EASYV_COMPONENT__`;
218
- const ast = parser(content, {
219
- sourceType: 'module',
220
- plugins: ['jsx', 'typescript', 'classProperties'],
221
- });
222
- traverse(ast, {
223
- ExportDefaultDeclaration(path) {
224
- const child = path.node.declaration;
225
-
226
- if (child.type === 'ClassDeclaration') {
227
- // e.g: export default class a {}
228
- if (child.id) {
229
- vname = child.id.name;
230
- // e.g: export default class {}
231
- } else {
232
- vname = exportName;
233
- child.id = t.identifier(exportName);
234
- }
235
- // e.g: export default memo()
236
- // e.g: export default () => {}
237
- } else if (
238
- !!~[
239
- 'CallExpression',
240
- 'ArrowFunctionExpression',
241
- 'FunctionExpression',
242
- ].indexOf(child.type)
243
- ) {
244
- const exportIdentifier = t.identifier(exportName);
245
- path.insertBefore(
246
- t.variableDeclaration('const', [
247
- t.variableDeclarator(exportIdentifier, child),
248
- ]),
249
- );
250
- path.node.declaration = exportIdentifier;
251
- vname = exportName;
252
- // e.g: export default function(){}
253
- } else if (!!~['FunctionDeclaration'].indexOf(child.type)) {
254
- const exportIdentifier = t.identifier(exportName);
255
- child.id = exportIdentifier;
256
- vname = exportName;
257
- // e.g: export default a;
258
- } else if (child.type === 'Identifier') {
259
- vname = child.name;
260
- }
261
- path.stop();
262
- },
263
- ExportNamedDeclaration(path) {
264
- const child = path.node.declaration;
265
- // e.g: export const a = {};
266
- if (child.type === 'VariableDeclaration') {
267
- const exportIdentifier = child.declarations[0].id;
268
- vname = exportIdentifier.name;
269
- path.replaceWith(child);
270
- path.insertAfter(t.exportDefaultDeclaration(exportIdentifier));
271
- // e.g: export function a(){};
272
- } else if (child.type === 'FunctionDeclaration') {
273
- const exportIdentifier = child.id;
274
- path.replaceWith(child);
275
- path.insertAfter(t.exportDefaultDeclaration(exportIdentifier));
276
- }
277
- path.stop();
278
- },
279
- });
280
- file = generate(ast, { quotes: 'single', retainLines: false }).code;
281
- if (!vname) {
282
- return callback(
283
- `cannot found default export object in ${path.join(
284
- modulePath,
285
- 'index',
286
- )}`,
287
- );
288
- }
289
- // 检查width/height
290
- const mainConfig = main.config;
291
- // if (!('width' in mainConfig) || !('height' in mainConfig)) {
292
- // return callback(`main.json lack field 'width' or 'height'.`)
293
- // }
294
-
295
- // 添加width/height属性兼容老版本
296
- let updateChart = false;
297
- const hasUnderline = mainConfig.configuration[0]
298
- ? '_value' in mainConfig.configuration[0]
299
- : false;
300
- const keys = {
301
- name: hasUnderline ? '_name' : 'name',
302
- displayName: hasUnderline ? '_displayName' : 'displayName',
303
- value: hasUnderline ? '_value' : 'value',
304
- type: hasUnderline ? '_type' : 'type',
305
- children: hasUnderline ? '_children' : 'children',
306
- };
307
- mainConfig.configuration = mainConfig.configuration.map((item) => {
308
- if (item[keys.name] === 'chart') {
309
- let values = item._value || item.value;
310
- values = values.map((item) => {
311
- if (item[keys.name] === 'dimension') {
312
- updateChart = true;
313
- return item;
314
- // return getOldDimension(mainConfig.width, mainConfig.height, hasUnderline)
315
- }
316
- return item;
317
- });
318
- if (!updateChart) {
319
- values.unshift(
320
- getOldDimension(
321
- mainConfig.width,
322
- mainConfig.height,
323
- hasUnderline,
324
- ),
325
- );
326
- updateChart = true;
327
- }
328
- item[keys.value] = values;
329
- return item;
330
- }
331
- return item;
332
- });
333
- if (!updateChart) {
334
- const chart = {
335
- [keys.name]: 'chart',
336
- [keys.displayName]: '组件',
337
- [keys.value]: [
338
- getOldDimension(
339
- mainConfig.width,
340
- mainConfig.height,
341
- hasUnderline,
342
- ),
343
- ],
344
- };
345
- mainConfig.configuration.unshift(chart);
346
- }
347
-
348
- // 子组件排序,有配置项则以chilren排序,否则以文件顺序排序
349
- if (mainConfig.children) {
350
- subConfigs = mainConfig.children.reduce((all, item) => {
351
- let childConfig = subConfigs.find(
352
- (d) => d.base.module_name === item,
353
- );
354
- return childConfig ? all.concat(childConfig) : all;
355
- }, []);
356
- }
357
-
358
- if (query.isBuild) {
359
- // 兼容平台子组件配置
360
- if (subConfigs.length) {
361
- const defineMap = subConfigs.reduce((a, b) => {
362
- a[b.base.module_name] = b;
363
- return a;
364
- }, {});
365
- const defineChildren =
366
- mainConfig.children ||
367
- subConfigs.map((item) => item.base.module_name);
368
- const presetChidlren = mainConfig.presetChildren || [];
369
-
370
- const children = {
371
- [keys.name]: 'children',
372
- [keys.displayName]: '子组件',
373
- [keys.value]: [
374
- {
375
- [keys.name]: 'component',
376
- [keys.displayName]: '管理',
377
- [keys.value]: [
378
- {
379
- [keys.name]: 'list',
380
- [keys.displayName]: '',
381
- [keys.value]: presetChidlren
382
- .filter((id) => defineMap[id])
383
- .map((id) => {
384
- const { base } = defineMap[id];
385
- return { label: base.name, name: base.module_name };
386
- }),
387
- [keys.type]: 'children',
388
- [keys.children]: defineChildren
389
- .filter((id) => defineMap[id])
390
- .map((id) => {
391
- const { base } = defineMap[id];
392
- return { name: base.name, value: base.module_name };
393
- }),
394
- },
395
- ],
396
- },
397
- ],
398
- };
399
- mainConfig.configuration.push(children);
400
- }
401
- // 替换modulename
402
- if (query.uniqueId) {
403
- mainConfig.base.module_name += '.' + query.uniqueId;
404
- }
405
- // 删除平台无法识别的参数
406
- delete mainConfig.children;
407
- delete mainConfig.presetChildren;
408
- }
409
-
410
- file += '\n';
411
- file += `${vname}.getDefaultConfig=function(){return ${JSON.stringify(
412
- mainConfig,
413
- )}};`;
414
- file += `${vname}.getDefaultData=function(){return ${JSON.stringify(
415
- main.data,
416
- )}};`;
417
- file += `${vname}.getDefaultChildrenConfig=function(){return ${JSON.stringify(
418
- subConfigs,
419
- )}};`;
420
- file += `${vname}.getDefaultChildrenData=function(){return ${JSON.stringify(
421
- subDatas,
422
- )}};`;
423
-
424
- callback(null, file);
425
- } catch (e) {
426
- callback(e);
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
+ };