tfose5-xlsx 3.4.4 → 3.5.4

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/README.md CHANGED
@@ -1 +1 @@
1
- # ![Version](https://img.shields.io/badge/version-3.4.4-green.svg)
1
+ # ![Version](https://img.shields.io/badge/version-3.5.4-green.svg)
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.parseXlsxToEnumJson = parseXlsxToEnumJson;
13
+ const node_xlsx_1 = require("node-xlsx");
13
14
  const path_1 = require("path");
14
15
  const tfose5_fs_1 = require("tfose5-fs");
15
- const xlsx_1 = require("xlsx");
16
16
  const converter_factory_1 = require("./converter-factory");
17
17
  const to_asset_converter_1 = require("./to-asset-converter");
18
18
  const to_bool_converter_1 = require("./to-bool-converter");
@@ -37,11 +37,12 @@ function parseXlsxToEnumJson(fsFactory, dstDirPath, srcDirPath, topEnums) {
37
37
  rewards: new to_rewards_converter_1.ToRewardsConverter(toEnumNoConverter, topEnums[topEnums.length - 1]),
38
38
  unit: new to_unix_converter_1.ToUnixConverter(),
39
39
  });
40
+ const topFiles = topEnums.map(r => r + '.xlsx');
40
41
  const filePaths = [];
41
42
  yield fsFactory.build(tfose5_fs_1.FsScanBase).scan({
42
43
  fileAction: (filePath) => __awaiter(this, void 0, void 0, function* () {
43
- const ok = topEnums.some(r => {
44
- return filePath.includes(r);
44
+ const ok = topFiles.some(r => {
45
+ return (0, path_1.basename)(filePath) == r;
45
46
  });
46
47
  if (ok)
47
48
  return;
@@ -49,47 +50,55 @@ function parseXlsxToEnumJson(fsFactory, dstDirPath, srcDirPath, topEnums) {
49
50
  }),
50
51
  path: srcDirPath,
51
52
  });
52
- topEnums.forEach(r => {
53
- filePaths.unshift((0, path_1.join)(srcDirPath, r + '.xlsx'));
53
+ topFiles.forEach(r => {
54
+ filePaths.unshift((0, path_1.join)(srcDirPath, r));
54
55
  });
55
56
  for (const r of filePaths) {
56
57
  if (r.includes('~'))
57
58
  continue;
58
- const sheets = (0, xlsx_1.readFile)(r).Sheets;
59
59
  const enumName = (0, path_1.basename)(r).replace('.xlsx', '');
60
60
  console.log(`xlsx: ${enumName}`);
61
- const allOtherSheetRows = {};
62
- for (const k in sheets) {
63
- if (k == enumName)
64
- continue;
65
- console.log(` sheet: ${k}`);
66
- allOtherSheetRows[k] = parseSheet(sheets[k]);
67
- }
68
- console.log(` sheet: ${enumName}`);
69
- const enumItems = parseSheet(sheets[enumName], allOtherSheetRows);
70
- if ((_a = enumItems[0]) === null || _a === void 0 ? void 0 : _a.text) {
71
- allEnumTextNo[enumName] = enumItems.reduce((memo, r) => {
61
+ const res = (0, node_xlsx_1.parse)(r).map(r => {
62
+ return {
63
+ sort: r.name == enumName ? 'zzz' : r.name,
64
+ sheet: r,
65
+ };
66
+ }).sort((a, b) => {
67
+ return a.sort.localeCompare(b.sort);
68
+ }).map(r => r.sheet).reduce((memo, r) => {
69
+ console.log(` sheet: ${r.name}`);
70
+ if (r.name == enumName)
71
+ memo.enumItems = parseSheet(r.data, memo.allOtherSheetRows);
72
+ else
73
+ memo.allOtherSheetRows[r.name] = parseSheet(r.data);
74
+ return memo;
75
+ }, {
76
+ enumItems: [],
77
+ allOtherSheetRows: {},
78
+ });
79
+ if ((_a = res.enumItems[0]) === null || _a === void 0 ? void 0 : _a.text) {
80
+ allEnumTextNo[enumName] = res.enumItems.reduce((memo, r) => {
72
81
  memo[r.text] = r.value;
73
82
  return memo;
74
83
  }, {});
75
84
  }
76
85
  yield fsFactory.build(tfose5_fs_1.FsWriteBase).write({
77
- data: enumItems,
86
+ data: res.enumItems,
78
87
  json: true,
79
88
  path: (0, path_1.join)(dstDirPath, enumName + '.json'),
80
89
  });
81
90
  }
82
91
  });
83
92
  }
84
- function parseSheet(sheet, allOtherSheetRows) {
85
- return xlsx_1.utils.sheet_to_json(sheet).map((r, i) => {
86
- return i ? Object.entries(r).reduce((memo, cr) => {
87
- var _a, _b;
88
- const [field, type, ext] = cr[0].split(':');
93
+ function parseSheet(sheetRows, allOtherSheetRows) {
94
+ return sheetRows.slice(2).map(r => {
95
+ return r.length ? sheetRows[0].reduce((memo, cr, ci) => {
96
+ var _a, _b, _c;
97
+ const [field, type, ext] = cr.split(':');
89
98
  let fieldValue;
90
99
  if (type == '#') {
91
100
  fieldValue = ((_a = allOtherSheetRows[ext]) !== null && _a !== void 0 ? _a : []).filter(sr => {
92
- return cr[1] == sr.group;
101
+ return r[ci] == sr.group;
93
102
  }).map(sr => {
94
103
  const copy = structuredClone(sr);
95
104
  delete copy.group;
@@ -98,12 +107,12 @@ function parseSheet(sheet, allOtherSheetRows) {
98
107
  });
99
108
  }
100
109
  else if (type == 'array') {
101
- fieldValue = cr[1].toString().split(/\r\n|\n|\r/g).map(sr => {
110
+ fieldValue = r[ci] ? r[ci].toString().split(/\r\n|\n|\r/g).map(sr => {
102
111
  return converterFactory.build(ext).convert(sr, ext);
103
- });
112
+ }) : undefined;
104
113
  }
105
114
  else {
106
- fieldValue = converterFactory.build(type).convert(cr[1], type);
115
+ fieldValue = r[ci] ? converterFactory.build(type).convert(r[ci], type) : undefined;
107
116
  }
108
117
  const fieldParts = field.split('.');
109
118
  let obj = memo;
@@ -114,7 +123,7 @@ function parseSheet(sheet, allOtherSheetRows) {
114
123
  obj = obj[name];
115
124
  }
116
125
  else {
117
- obj[name] = fieldValue;
126
+ (_c = obj[name]) !== null && _c !== void 0 ? _c : (obj[name] = fieldValue);
118
127
  }
119
128
  }
120
129
  return memo;
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "author": "ahl5esoft",
3
3
  "dependencies": {
4
4
  "dayjs": "^1.11.20",
5
- "tfose5-fs": "^1.6.1",
6
- "xlsx": "^0.18.5"
5
+ "node-xlsx": "^0.24.0",
6
+ "tfose5-fs": "^1.6.1"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@types/mocha": "^10.0.10",
@@ -24,5 +24,5 @@
24
24
  "test": "mocha -t 30s -r ./node_modules/ts-node/register/index.js --exit",
25
25
  "version": "ts-node script version"
26
26
  },
27
- "version": "3.4.4"
27
+ "version": "3.5.4"
28
28
  }