fast-cocos 1.0.0 → 1.0.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.
@@ -100,7 +100,8 @@ class XlsxParser {
100
100
  intros,
101
101
  types,
102
102
  fields,
103
- data
103
+ data,
104
+ firstColumnMergedArray: SheetType.Array == sheetType && this.isFirstColumnMergedArray(data)
104
105
  };
105
106
  console.info("\x1b[36m%s\x1b[0m", "解析表: " + name);
106
107
  switch (sheetType) {
@@ -108,8 +109,12 @@ class XlsxParser {
108
109
  this.parseMap(sheetInfo);
109
110
  break;
110
111
  case SheetType.Array:
111
- this.parseArray(sheetInfo);
112
- break;
112
+ if (sheetInfo.firstColumnMergedArray) {
113
+ this.parseFirstColumnMergedArray(sheetInfo);
114
+ }
115
+ else {
116
+ this.parseArray(sheetInfo);
117
+ }
113
118
  case SheetType.KVMap:
114
119
  this.parseKVMap(sheetInfo);
115
120
  break;
@@ -176,6 +181,62 @@ class XlsxParser {
176
181
  // 写json文件
177
182
  this.writeSheetSync(sheetInfo.outPath, content);
178
183
  }
184
+ /**
185
+ * 解析首列合并行数组
186
+ * @param sheetInfo 工作表信息
187
+ */
188
+ parseFirstColumnMergedArray(sheetInfo) {
189
+ const { types, fields, data } = sheetInfo;
190
+ // 类型声明
191
+ this.parseTypeDeclare(sheetInfo);
192
+ // 解析内容
193
+ const content = [];
194
+ let group;
195
+ for (let i = 0; i < data.length; ++i) {
196
+ const col = data[i];
197
+ if (col[0]) {
198
+ const columns = data.map((v) => v[0]);
199
+ group = {
200
+ [fields[0]]: this.parseValue(types[0], col[0], columns),
201
+ arr: []
202
+ };
203
+ content.push(group);
204
+ }
205
+ const info = this.parseRowInfo(sheetInfo, col);
206
+ if (group && Object.keys(info).length) {
207
+ group.arr.push(info);
208
+ }
209
+ }
210
+ // 写json文件
211
+ this.writeSheetSync(sheetInfo.outPath, content);
212
+ }
213
+ /**
214
+ * 解析行数据
215
+ * @param sheetInfo 工作表信息
216
+ * @param row 行数据
217
+ */
218
+ parseRowInfo(sheetInfo, row) {
219
+ const { types, fields, data } = sheetInfo;
220
+ const info = {};
221
+ for (let i = 0; i < row.length; ++i) {
222
+ const field = fields[i];
223
+ if (field) {
224
+ const columns = data.map((v) => v[i]);
225
+ info[field] = this.parseValue(types[i], row[i], columns);
226
+ }
227
+ }
228
+ return info;
229
+ }
230
+ /**
231
+ * 是否首列合并行数组
232
+ * @param data 数据行
233
+ */
234
+ isFirstColumnMergedArray(data) {
235
+ if (data.length <= 0 || !data[0][0]) {
236
+ return false;
237
+ }
238
+ return data.some((row, index) => index > 0 && !row[0] && row.some((value) => value));
239
+ }
179
240
  /**
180
241
  * 解析键值表
181
242
  * @param sheetInfo 工作表信息
@@ -446,7 +507,18 @@ class XlsxParser {
446
507
  }
447
508
  this.pushUnique(lines, `}\n`, 0);
448
509
  this.pushUnique(lines, `/** ${xlsxName} */`, 0);
449
- this.pushUnique(lines, `type ${typeName} = ${basename}[];`, 0);
510
+ if (sheetInfo.firstColumnMergedArray) {
511
+ const type = this.removeExtraType(types[0]);
512
+ lines.push(`interface ${basename}Group {`);
513
+ lines.push(` /** ${intros[0]} */`);
514
+ lines.push(` readonly ${fields[0]}: ${type};`);
515
+ lines.push(` readonly arr: ${basename}[];`);
516
+ lines.push(`}\n`);
517
+ lines.push(`type ${typeName} = ${basename}Group[];`);
518
+ }
519
+ else {
520
+ this.pushUnique(lines, `type ${typeName} = ${basename}[];`, 0);
521
+ }
450
522
  this.declareMap.set(typeName, lines);
451
523
  break;
452
524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-cocos",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "scripts": {
5
5
  "clean": "rm -rf dist",
6
6
  "start": "node ./dist/index.js",