fast-cocos 1.0.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.
@@ -0,0 +1,580 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const node_xlsx_1 = __importDefault(require("node-xlsx"));
8
+ const path_1 = __importDefault(require("path"));
9
+ /**
10
+ * 工作表类型
11
+ */
12
+ var SheetType;
13
+ (function (SheetType) {
14
+ SheetType["Map"] = "Map";
15
+ SheetType["Array"] = "Array";
16
+ SheetType["KVMap"] = "KVMap";
17
+ SheetType["VMap"] = "VMap";
18
+ })(SheetType || (SheetType = {}));
19
+ /**
20
+ * Xlsx解析器
21
+ */
22
+ class XlsxParser {
23
+ constructor(options) {
24
+ /** 数组分隔符类 */
25
+ this.separators = ["|", ";", ",", "-", "_"];
26
+ /** 接口声明表 接口名称 => 字段声明 */
27
+ this.declareMap = new Map();
28
+ this.options = options;
29
+ // 数组分隔符类型
30
+ if (this.options.separators) {
31
+ this.separators = this.options.separators || this.separators;
32
+ }
33
+ // 移除临时目录
34
+ if (fs_1.default.existsSync(this.options.tmpDir)) {
35
+ fs_1.default.rmSync(this.options.tmpDir, { recursive: true });
36
+ }
37
+ }
38
+ /**
39
+ * 解析xlsx文件
40
+ */
41
+ parse() {
42
+ const xlsxFiles = this.findFilesWithExtensions(this.options.xlsxDir, [".xlsx", ".xls"]);
43
+ xlsxFiles.forEach((filePath) => {
44
+ console.info("\x1b[35m%s\x1b[0m", "解析文件: " + filePath);
45
+ const xlsxName = path_1.default.basename(filePath, path_1.default.extname(filePath));
46
+ const workSheetsFromFile = node_xlsx_1.default.parse(filePath);
47
+ workSheetsFromFile.forEach((workSheet) => {
48
+ this.parseWorkSheet(xlsxName, workSheet);
49
+ });
50
+ });
51
+ this.writeTs();
52
+ this.mergeJson();
53
+ }
54
+ /**
55
+ * 解析出表信息
56
+ * @param xlsxName xlsx文件名
57
+ * @param workSheet 工作表
58
+ */
59
+ parseWorkSheet(xlsxName, workSheet) {
60
+ let { name, data } = workSheet;
61
+ name = this.processString(name);
62
+ const arr = name.split(".");
63
+ // 解析表名、类型、版本
64
+ const [basename, sheetType, version] = arr;
65
+ // 去除空数组
66
+ data = data.filter((item) => item.length > 0);
67
+ /** 介绍(第一行) */
68
+ let intros = data[0];
69
+ /** 类型(第二行) */
70
+ let types = data[1];
71
+ /** 字段(第三行) */
72
+ let fields = data[2];
73
+ // VMap类型特殊处理
74
+ if (SheetType.VMap == sheetType) {
75
+ intros = [];
76
+ types = [];
77
+ fields = [];
78
+ data.shift();
79
+ }
80
+ else {
81
+ data.shift();
82
+ data.shift();
83
+ data.shift();
84
+ }
85
+ data.forEach((row) => row.forEach((v, i) => (row[i] = String(v || "").trim())));
86
+ let fileName = `${basename}${sheetType}`;
87
+ let typeName = fileName;
88
+ // 带版本号
89
+ if (version === null || version === void 0 ? void 0 : version.startsWith("v")) {
90
+ fileName = `${typeName}.${arr[2]}`;
91
+ }
92
+ const outPath = path_1.default.join(this.options.tmpDir, xlsxName, `${fileName}.json`);
93
+ // 工作表信息
94
+ const sheetInfo = {
95
+ sheetType: sheetType,
96
+ xlsxName,
97
+ basename,
98
+ outPath,
99
+ typeName,
100
+ intros,
101
+ types,
102
+ fields,
103
+ data
104
+ };
105
+ console.info("\x1b[36m%s\x1b[0m", "解析表: " + name);
106
+ switch (sheetType) {
107
+ case SheetType.Map:
108
+ this.parseMap(sheetInfo);
109
+ break;
110
+ case SheetType.Array:
111
+ this.parseArray(sheetInfo);
112
+ break;
113
+ case SheetType.KVMap:
114
+ this.parseKVMap(sheetInfo);
115
+ break;
116
+ case SheetType.VMap:
117
+ this.parseVMap(sheetInfo);
118
+ break;
119
+ default:
120
+ console.error(`表【${sheetType}】格式错误,导出失败`);
121
+ break;
122
+ }
123
+ }
124
+ /**
125
+ * 解析对象
126
+ * @param sheetInfo 工作表信息
127
+ */
128
+ parseMap(sheetInfo) {
129
+ const { types, fields, data } = sheetInfo;
130
+ // 类型声明
131
+ this.parseTypeDeclare(sheetInfo);
132
+ // 解析内容
133
+ const content = {};
134
+ for (const row of data) {
135
+ const rowInfo = {};
136
+ for (let i = 0; i < row.length; ++i) {
137
+ const field = fields[i];
138
+ if (field) {
139
+ const columns = data.map((v) => v[i]);
140
+ rowInfo[field] = this.parseValue(types[i], row[i], columns);
141
+ }
142
+ }
143
+ // 只有有效行才会记录
144
+ if (Object.keys(rowInfo).length) {
145
+ const key = rowInfo.id || rowInfo[fields[0]];
146
+ content[key] = rowInfo;
147
+ }
148
+ }
149
+ // 写json文件
150
+ this.writeSheetSync(sheetInfo.outPath, content);
151
+ }
152
+ /**
153
+ * 解析数组
154
+ * @param sheetInfo 工作表信息
155
+ */
156
+ parseArray(sheetInfo) {
157
+ const { types, fields, data } = sheetInfo;
158
+ // 类型声明
159
+ this.parseTypeDeclare(sheetInfo);
160
+ // 解析内容
161
+ const content = [];
162
+ for (let i = 0; i < data.length; ++i) {
163
+ const info = {};
164
+ const col = data[i];
165
+ for (let j = 0; j < col.length; ++j) {
166
+ const field = fields[j];
167
+ if (field) {
168
+ const columns = data.map((v) => v[j]);
169
+ info[field] = this.parseValue(types[j], col[j], columns);
170
+ }
171
+ }
172
+ if (Object.keys(info).length) {
173
+ content.push(info);
174
+ }
175
+ }
176
+ // 写json文件
177
+ this.writeSheetSync(sheetInfo.outPath, content);
178
+ }
179
+ /**
180
+ * 解析键值表
181
+ * @param sheetInfo 工作表信息
182
+ */
183
+ parseKVMap(sheetInfo) {
184
+ const { types, data } = sheetInfo;
185
+ // 类型声明
186
+ this.parseTypeDeclare(sheetInfo);
187
+ // 解析内容
188
+ const content = {};
189
+ const [, type] = types;
190
+ for (let i = 0; i < data.length; ++i) {
191
+ const [field, value] = data[i];
192
+ if (field) {
193
+ content[field] = this.parseValue(type, value, [value]);
194
+ }
195
+ }
196
+ // 写json文件
197
+ this.writeSheetSync(sheetInfo.outPath, content);
198
+ }
199
+ /**
200
+ * 解析键值表
201
+ * @param sheetInfo 工作表信息
202
+ */
203
+ parseVMap(sheetInfo) {
204
+ const { data } = sheetInfo;
205
+ // 声明内容
206
+ this.parseTypeDeclare(sheetInfo);
207
+ // 表内容
208
+ const content = {};
209
+ for (let i = 0; i < data.length; ++i) {
210
+ const [field, type, value] = data[i];
211
+ if (field) {
212
+ content[field] = this.parseValue(type, value, [value]);
213
+ }
214
+ }
215
+ // 写json文件
216
+ this.writeSheetSync(sheetInfo.outPath, content);
217
+ }
218
+ /**
219
+ * 解析值
220
+ * @param type 值类型
221
+ * @param value 值
222
+ * @param columns 列数据
223
+ */
224
+ parseValue(type, value, columns) {
225
+ // 将值转换为字符串
226
+ const valueStr = String(value || "");
227
+ // 数组类型
228
+ const { baseType, separators } = this.splitTypeWithSeparators(type);
229
+ if (separators.length > 0) {
230
+ return this.toArray(baseType, separators, valueStr, columns);
231
+ }
232
+ // 基础类型
233
+ switch (type) {
234
+ case "int":
235
+ return parseInt(valueStr || "0");
236
+ case "float":
237
+ return parseFloat(valueStr || "0");
238
+ case "boolean":
239
+ return Boolean(valueStr || "0");
240
+ case "number":
241
+ return Number(valueStr || "0");
242
+ case "string":
243
+ if (valueStr) {
244
+ return valueStr.trim();
245
+ }
246
+ return undefined;
247
+ case "{}":
248
+ return JSON.parse(valueStr);
249
+ default:
250
+ console.log("未处理类型", type);
251
+ return valueStr;
252
+ }
253
+ }
254
+ /**
255
+ * 拆分类型字符串为基本类型和分隔符数组
256
+ * @param typeString 输入的类型字符串,如 "int[;][|]"
257
+ * @returns 包含基本类型和分隔符数组的对象
258
+ */
259
+ splitTypeWithSeparators(typeString) {
260
+ // 1. 使用正则表达式匹配基本类型和所有分隔符部分
261
+ const match = typeString.match(/^([^\[]+)((?:\[([^\]]*)\])*)$/);
262
+ if (!match) {
263
+ throw new Error(`Invalid type string: ${typeString}`);
264
+ }
265
+ const baseType = match[1];
266
+ const dimensionsPart = match[2];
267
+ // 2. 提取所有分隔符
268
+ const separators = [];
269
+ const separatorRegex = /\[([^\]]*)\]/g;
270
+ let separatorMatch;
271
+ while ((separatorMatch = separatorRegex.exec(dimensionsPart)) !== null) {
272
+ separators.push(separatorMatch[1]);
273
+ }
274
+ return {
275
+ baseType,
276
+ separators
277
+ };
278
+ }
279
+ /**
280
+ * 字符串转数组
281
+ * @param baseType 基础类型
282
+ * @param separators 分隔符
283
+ * @param valueStr 值
284
+ * @param columns 列数据,用于抽取数组分隔符
285
+ */
286
+ toArray(baseType, separators, valueStr, columns) {
287
+ if (!valueStr) {
288
+ return undefined;
289
+ }
290
+ // 分隔符数量
291
+ let separatorCount = separators.length;
292
+ // 逆序分隔符
293
+ let realSeparators = separators.filter((item) => item !== "").reverse();
294
+ // 从列中抽取分隔符
295
+ if (realSeparators.length <= 0 && separatorCount > 0) {
296
+ outer: for (let column of columns) {
297
+ if (!column) {
298
+ continue;
299
+ }
300
+ const columnSeparators = [];
301
+ // 遍历每个字符
302
+ for (const char of column) {
303
+ if (this.separators.includes(char) && !columnSeparators.includes(char)) {
304
+ columnSeparators.push(char);
305
+ if (columnSeparators.length == separatorCount) {
306
+ realSeparators = columnSeparators.reverse();
307
+ break outer;
308
+ }
309
+ }
310
+ }
311
+ }
312
+ // 兜底分隔符
313
+ if (realSeparators.length <= 0) {
314
+ realSeparators = Array.from({ length: separatorCount }).fill("?");
315
+ }
316
+ }
317
+ return this.splitStringToNestedArray(baseType, valueStr, realSeparators);
318
+ }
319
+ /**
320
+ * 将字符串按多级分隔符拆分为类型安全的嵌套数组
321
+ * @param baseType 基础类型
322
+ * @param valueStr 输入字符串
323
+ * @param delimiters 分隔符数组,决定嵌套层级和每层的分隔方式
324
+ * @returns 嵌套数组,深度与分隔符数组长度相同,完全类型安全
325
+ */
326
+ splitStringToNestedArray(baseType, valueStr, delimiters) {
327
+ // 递归终止条件:没有更多分隔符时返回字符串本身
328
+ if (delimiters.length === 0) {
329
+ return this.parseValue(baseType, valueStr, []);
330
+ }
331
+ const [currentDelimiter, ...remainingDelimiters] = delimiters;
332
+ // 如果当前层级不包含分隔符,直接进入下一层级
333
+ if (!valueStr.includes(currentDelimiter)) {
334
+ return [this.splitStringToNestedArray(baseType, valueStr, remainingDelimiters)];
335
+ }
336
+ // 分割当前层级并递归处理每个部分
337
+ return valueStr.split(currentDelimiter).map((part) => this.splitStringToNestedArray(baseType, part, remainingDelimiters));
338
+ }
339
+ /**
340
+ * 遍历目录获得指定扩展名的文件
341
+ * @param dir 目录
342
+ * @param exts 扩展名
343
+ * @param files 文件列表
344
+ */
345
+ findFilesWithExtensions(dir, extensions, files = []) {
346
+ dir = dir.trim();
347
+ if (!Array.isArray(extensions)) {
348
+ extensions = [extensions];
349
+ }
350
+ const fileList = fs_1.default.readdirSync(dir);
351
+ fileList.forEach((file) => {
352
+ const filePath = path_1.default.join(dir, file);
353
+ const fileStat = fs_1.default.statSync(filePath);
354
+ if (fileStat.isFile() && this.endsWithAny(file, extensions)) {
355
+ files.push(filePath);
356
+ }
357
+ else if (fileStat.isDirectory()) {
358
+ this.findFilesWithExtensions(filePath, extensions, files);
359
+ }
360
+ });
361
+ return files;
362
+ }
363
+ /**
364
+ * 判断一个字符串是否以一个数组中任意一个字符串结尾
365
+ * @param str 字符串
366
+ * @param suffixes 后缀数组
367
+ */
368
+ endsWithAny(str, suffixes) {
369
+ for (const suffix of suffixes) {
370
+ if (str.endsWith(suffix)) {
371
+ return true;
372
+ }
373
+ }
374
+ return false;
375
+ }
376
+ /**
377
+ * 向数组中添加元素
378
+ * @param arr 数组
379
+ * @param item 元素
380
+ * @param spaces 空格数
381
+ */
382
+ pushUnique(arr, item, spaces = 4) {
383
+ let str = " ".repeat(spaces) + item;
384
+ if (!arr.includes(str)) {
385
+ arr.push(str);
386
+ }
387
+ }
388
+ /**
389
+ * 类型声明
390
+ * @param sheetInfo 工作表信息
391
+ */
392
+ parseTypeDeclare(sheetInfo) {
393
+ const { intros, types, fields, xlsxName, basename, sheetType, typeName, data } = sheetInfo;
394
+ const lines = [];
395
+ switch (sheetType) {
396
+ case SheetType.VMap: {
397
+ this.pushUnique(lines, `/** ${xlsxName} */`, 0);
398
+ this.pushUnique(lines, `interface ${typeName} {`, 0);
399
+ for (let i = 0; i < data.length; ++i) {
400
+ let [field, type, , comment] = data[i];
401
+ if (field) {
402
+ type = this.removeExtraType(type);
403
+ this.pushUnique(lines, `/** ${comment} */`);
404
+ this.pushUnique(lines, `readonly ${field}: ${type};`);
405
+ }
406
+ }
407
+ this.pushUnique(lines, `}`, 0);
408
+ this.declareMap.set(typeName, lines);
409
+ break;
410
+ }
411
+ case SheetType.KVMap: {
412
+ let [key, type] = types;
413
+ type = this.removeExtraType(type);
414
+ this.pushUnique(lines, `/** 键: ${intros[0]} 值: ${type} */`);
415
+ this.pushUnique(lines, `type ${typeName} = Map<${key}, ${type}>;`);
416
+ this.declareMap.set(typeName, lines);
417
+ break;
418
+ }
419
+ case SheetType.Map: {
420
+ this.pushUnique(lines, `interface ${basename} {`, 0);
421
+ for (let i = 0; i < intros.length; ++i) {
422
+ const field = fields[i];
423
+ if (field) {
424
+ const type = this.removeExtraType(types[i]);
425
+ this.pushUnique(lines, `/** ${intros[i]} */`, 4);
426
+ this.pushUnique(lines, `readonly ${field}: ${type};`, 4);
427
+ }
428
+ }
429
+ this.pushUnique(lines, `}\n`, 0);
430
+ this.pushUnique(lines, `/** ${xlsxName} */`, 0);
431
+ this.pushUnique(lines, `type ${typeName} = Map<${types[0]}, ${basename}>;`, 0);
432
+ this.declareMap.set(typeName, lines);
433
+ break;
434
+ }
435
+ case SheetType.Array: {
436
+ this.pushUnique(lines, `/** ${xlsxName}行数据 */`, 0);
437
+ this.pushUnique(lines, `interface ${basename} {`, 0);
438
+ for (let i = 0; i < intros.length; ++i) {
439
+ const intro = intros[i];
440
+ const type = this.removeExtraType(types[i]);
441
+ const field = fields[i];
442
+ if (field) {
443
+ this.pushUnique(lines, `/** ${intro} */`);
444
+ this.pushUnique(lines, `readonly ${field}: ${type};`);
445
+ }
446
+ }
447
+ this.pushUnique(lines, `}\n`, 0);
448
+ this.pushUnique(lines, `/** ${xlsxName} */`, 0);
449
+ this.pushUnique(lines, `type ${typeName} = ${basename}[];`, 0);
450
+ this.declareMap.set(typeName, lines);
451
+ break;
452
+ }
453
+ default:
454
+ console.warn("未处理声明类型", sheetType);
455
+ break;
456
+ }
457
+ }
458
+ /**
459
+ * 去除多余类型字符
460
+ * @param str
461
+ */
462
+ removeExtraType(str) {
463
+ // 使用正则表达式匹配所有方括号中的内容
464
+ const pattern = /\[(.*?)\]/g;
465
+ let match;
466
+ let result = "";
467
+ let lastIndex = 0;
468
+ // 循环匹配方括号中的内容
469
+ while ((match = pattern.exec(str)) !== null) {
470
+ // 将方括号中的内容替换为中括号对
471
+ result += str.slice(lastIndex, match.index) + "[]";
472
+ lastIndex = pattern.lastIndex;
473
+ }
474
+ // 添加剩余的字符串部分
475
+ result += str.slice(lastIndex);
476
+ // 如果没有匹配到方括号中的内容,则返回原始字符串
477
+ return result;
478
+ }
479
+ /**
480
+ * 处理字符串,确保它不以数字开头,并且移除所有空格、制表符和换行符
481
+ * @param input
482
+ */
483
+ processString(input) {
484
+ // Remove leading digits
485
+ let processedStr = input.replace(/^\d+/, "");
486
+ // Remove whitespace, tabs, and newlines
487
+ processedStr = processedStr.replace(/[\s\t\n]/g, "");
488
+ return processedStr;
489
+ }
490
+ /**
491
+ * 合并JSON文件
492
+ */
493
+ mergeJson() {
494
+ const jsonDir = path_1.default.join(this.options.tmpDir);
495
+ const files = this.findFilesWithExtensions(jsonDir, [".json"]);
496
+ const json = {};
497
+ files.forEach((filePath) => {
498
+ const basename = path_1.default.basename(filePath);
499
+ const arr = this.processString(basename).split(".");
500
+ let sheetName = arr[0];
501
+ if (arr.length == 3) {
502
+ sheetName += `.${arr[1]}`;
503
+ }
504
+ json[sheetName] = require(filePath);
505
+ });
506
+ this.writeFileSync(this.options["xlsx.json"], json);
507
+ }
508
+ /**
509
+ * 写json文件到本地
510
+ * @param filePath 文件路径
511
+ * @param data 数据
512
+ */
513
+ writeSheetSync(filePath, data) {
514
+ const content = JSON.stringify(data, null, 4);
515
+ filePath = path_1.default.resolve(filePath);
516
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
517
+ fs_1.default.writeFileSync(filePath, content, { encoding: "utf-8" });
518
+ console.info("\x1b[32m%s\x1b[0m", "写文件: " + filePath);
519
+ }
520
+ /**
521
+ * 写文件
522
+ * @param filePath 文件路径
523
+ * @param content 文件内容
524
+ */
525
+ writeFileSync(filePath, content) {
526
+ if (typeof content != "string") {
527
+ content = JSON.stringify(content, null, 4);
528
+ }
529
+ console.info("\x1b[32m%s\x1b[0m", "写文件: " + filePath);
530
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
531
+ fs_1.default.writeFileSync(filePath, content, { encoding: "utf-8" });
532
+ }
533
+ /**
534
+ * 写ts文件到本地
535
+ */
536
+ writeTs() {
537
+ // xlsx.sheet.d.ts
538
+ let declareStr = `declare namespace sheet {`;
539
+ declareStr += `\n /** 整数 */`;
540
+ declareStr += `\n type int = number;`;
541
+ // 遍历声明表
542
+ this.declareMap.forEach((value) => {
543
+ if (value.length <= 0) {
544
+ return;
545
+ }
546
+ value = value.map((v) => " ".repeat(4) + v);
547
+ declareStr += "\n\n";
548
+ declareStr += value.join("\n");
549
+ });
550
+ declareStr += `\n}\n`;
551
+ this.writeFileSync(this.options["xlsx.sheet.d.ts"], declareStr);
552
+ // xlsx.ts
553
+ const jsonDir = path_1.default.join(this.options.tmpDir);
554
+ const templatePath = path_1.default.join(this.options.execDir, "template", "xlsx.txt");
555
+ let scriptStr = fs_1.default.readFileSync(templatePath, "utf8");
556
+ // 属性声明
557
+ let propertyStr = " ".repeat(4) + `public readonly version: XlsxVersion = "v1";\n`;
558
+ // 赋值声明
559
+ let assignStr = "";
560
+ const files = this.findFilesWithExtensions(jsonDir, [".json"]);
561
+ for (let i = 0; i < files.length; ++i) {
562
+ const filePath = files[i];
563
+ const basename = this.processString(path_1.default.basename(filePath));
564
+ const annotation = path_1.default.basename(path_1.default.dirname(filePath));
565
+ const arr = basename.split(".");
566
+ const [filename] = arr;
567
+ if (arr.length == 3) {
568
+ continue;
569
+ }
570
+ propertyStr += `\n`;
571
+ propertyStr += " ".repeat(4) + `/** ${annotation} */\n`;
572
+ propertyStr += " ".repeat(4) + `public readonly ${filename}: sheet.${filename};\n`;
573
+ assignStr += " ".repeat(8) + `(this.${filename} as any) = "${filename}";\n`;
574
+ }
575
+ scriptStr = scriptStr.replace("{0}", propertyStr);
576
+ scriptStr = scriptStr.replace("{1}", assignStr);
577
+ this.writeFileSync(this.options["xlsx.ts"], scriptStr);
578
+ }
579
+ }
580
+ exports.default = XlsxParser;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = require("commander");
16
+ const path_1 = __importDefault(require("path"));
17
+ const logger_1 = __importDefault(require("../../logger"));
18
+ const XlsxParser_1 = __importDefault(require("./XlsxParser"));
19
+ function main() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ commander_1.program
22
+ .name("xlsx")
23
+ .description("xlsx config table parser")
24
+ .version("1.0.0")
25
+ .requiredOption("-s, --source <path>", "source directory")
26
+ .requiredOption("-o, --output <path>", "output directory")
27
+ .requiredOption("--script <directory>", "script file directory")
28
+ .parse(process.argv);
29
+ const options = commander_1.program.opts();
30
+ let execDir = path_1.default.dirname(__dirname);
31
+ const scriptPath = path_1.default.resolve(__filename);
32
+ if (/\/snapshot\//.test(scriptPath)) {
33
+ execDir = path_1.default.dirname(process.execPath);
34
+ }
35
+ logger_1.default.info(`执行目录: ${execDir}`);
36
+ const xlsxParser = new XlsxParser_1.default({
37
+ execDir,
38
+ tmpDir: path_1.default.join(options.source, "json"),
39
+ xlsxDir: options.source,
40
+ "xlsx.ts": path_1.default.join(options.script, "xlsx.ts"),
41
+ "xlsx.sheet.d.ts": path_1.default.join(options.script, "xlsx.sheet.d.ts"),
42
+ "xlsx.json": path_1.default.join(options.output, "xlsx.json")
43
+ });
44
+ xlsxParser.parse();
45
+ });
46
+ }
47
+ void main().catch((err) => {
48
+ console.error(err);
49
+ process.exit(1);
50
+ });