Main.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. var FileUtil_1 = require("./FileUtil");
  5. var Config_1 = require("./Config");
  6. var path = require("path");
  7. var ExcelUtil_1 = require("./ExcelUtil");
  8. var yargs = require("yargs");
  9. var outPutType = ['js', 'ts', 'csv', 'hsv', 'jsjson', 'tsjson', 'tsjsonmin', 'ts_alone', 'js_alone'];
  10. var argv = yargs.options({
  11. h: { alias: 'help', describe: 'Show help' },
  12. v: { alias: 'version', describe: 'Show version number' },
  13. i: { type: 'string', alias: 'input', default: Config_1.Config.inputDir, describe: 'Excel config import path' },
  14. o: { type: 'string', alias: 'output', default: Config_1.Config.outPutDir, describe: 'Output config export path' },
  15. t: { type: 'array', alias: 'type', default: outPutType, choices: outPutType, describe: 'Output config type' },
  16. c: { type: 'boolean', alias: 'check', default: false, describe: 'Check only not output' },
  17. y: { type: 'number', alias: 'yuan', default: Config_1.Config.yuanRate, describe: '$num$ Rate' },
  18. r: { type: 'string', alias: 'replace', default: Config_1.Config.replaceStr, describe: '¥string¥ replace new string' },
  19. }).usage('Usage: excel2x [options]')
  20. .example('excel2x -i D:\\zedu_jxb\\config -o D:\\zedu_jxb\\config\\output -t ts_alone', '')
  21. .epilog('--------------------------------------------')
  22. .argv;
  23. var Main = /** @class */ (function () {
  24. function Main() {
  25. }
  26. Main.prototype.run = function () {
  27. Config_1.Config.inputDir = argv.i;
  28. Config_1.Config.outPutDir = argv.o;
  29. Config_1.Config.yuanRate = argv.y;
  30. Config_1.Config.replaceStr = argv.r;
  31. if (!FileUtil_1.default.checkDir(Config_1.Config.inputDir)) {
  32. Config_1.Config.checkState(Config_1.RetCode.INPUT_DIR_IS_NOT_FOUND, "\u914D\u7F6E\u6587\u4EF6\u5939\uFF08inputDir\uFF09\u4E0D\u5B58\u5728 ".concat(Config_1.Config.inputDir));
  33. }
  34. var excelList = FileUtil_1.default.getFileList(Config_1.Config.inputDir, ['.xlsx']);
  35. var outPutData = [];
  36. for (var i = 0; i < excelList.length; i++) {
  37. FileUtil_1.default.printlog((i + 1) / excelList.length);
  38. var excelPath = path.join(Config_1.Config.inputDir, excelList[i]);
  39. var headInfo = ExcelUtil_1.default.getExcelInfo(excelPath);
  40. var data = ExcelUtil_1.default.creatObj(headInfo);
  41. if (argv.t.findIndex(function (v) { return v == 'ts_alone'; }) != -1) {
  42. FileUtil_1.default.saveTsAlone(data);
  43. }
  44. if (argv.t.findIndex(function (v) { return v == 'js_alone'; }) != -1) {
  45. FileUtil_1.default.saveJsAlone(data);
  46. }
  47. outPutData.push(data);
  48. }
  49. if (!argv.c) {
  50. FileUtil_1.default.checkAndMakeDir(Config_1.Config.outPutDir);
  51. if (argv.t.findIndex(function (v) { return v == 'js'; }) != -1) {
  52. FileUtil_1.default.saveJs(outPutData);
  53. }
  54. if (argv.t.findIndex(function (v) { return v == 'ts'; }) != -1) {
  55. FileUtil_1.default.saveTs(outPutData);
  56. }
  57. if (argv.t.findIndex(function (v) { return v == 'jsjson'; }) != -1) {
  58. FileUtil_1.default.saveJsJson(outPutData);
  59. }
  60. if (argv.t.findIndex(function (v) { return v == 'tsjson'; }) != -1) {
  61. FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.jsonOutputDir));
  62. FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.tsOutputDir));
  63. FileUtil_1.default.saveTsJson(outPutData);
  64. }
  65. if (argv.t.findIndex(function (v) { return v == 'tsjsonmin'; }) != -1) {
  66. FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.jsonOutputDir));
  67. FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.tsOutputDir));
  68. FileUtil_1.default.saveTsJson(outPutData, true);
  69. }
  70. if (argv.t.findIndex(function (v) { return v == 'csv'; }) != -1) {
  71. FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, 'csv'));
  72. FileUtil_1.default.saveCsv(outPutData);
  73. }
  74. if (argv.t.findIndex(function (v) { return v == 'hsv'; }) != -1) {
  75. FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, 'hsv'));
  76. FileUtil_1.default.saveHsv(outPutData);
  77. }
  78. }
  79. process.exit(Config_1.Config.retCode);
  80. };
  81. return Main;
  82. }());
  83. new Main().run();