#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var FileUtil_1 = require("./FileUtil"); var Config_1 = require("./Config"); var path = require("path"); var ExcelUtil_1 = require("./ExcelUtil"); var yargs = require("yargs"); var outPutType = ['js', 'ts', 'csv', 'hsv', 'jsjson', 'tsjson', 'tsjsonmin', 'ts_alone', 'js_alone']; var argv = yargs.options({ h: { alias: 'help', describe: 'Show help' }, v: { alias: 'version', describe: 'Show version number' }, i: { type: 'string', alias: 'input', default: Config_1.Config.inputDir, describe: 'Excel config import path' }, o: { type: 'string', alias: 'output', default: Config_1.Config.outPutDir, describe: 'Output config export path' }, t: { type: 'array', alias: 'type', default: outPutType, choices: outPutType, describe: 'Output config type' }, c: { type: 'boolean', alias: 'check', default: false, describe: 'Check only not output' }, y: { type: 'number', alias: 'yuan', default: Config_1.Config.yuanRate, describe: '$num$ Rate' }, r: { type: 'string', alias: 'replace', default: Config_1.Config.replaceStr, describe: '¥string¥ replace new string' }, }).usage('Usage: excel2x [options]') .example('excel2x -i D:\\zedu_jxb\\config -o D:\\zedu_jxb\\config\\output -t ts_alone', '') .epilog('--------------------------------------------') .argv; var Main = /** @class */ (function () { function Main() { } Main.prototype.run = function () { Config_1.Config.inputDir = argv.i; Config_1.Config.outPutDir = argv.o; Config_1.Config.yuanRate = argv.y; Config_1.Config.replaceStr = argv.r; if (!FileUtil_1.default.checkDir(Config_1.Config.inputDir)) { 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)); } var excelList = FileUtil_1.default.getFileList(Config_1.Config.inputDir, ['.xlsx']); var outPutData = []; for (var i = 0; i < excelList.length; i++) { FileUtil_1.default.printlog((i + 1) / excelList.length); var excelPath = path.join(Config_1.Config.inputDir, excelList[i]); var headInfo = ExcelUtil_1.default.getExcelInfo(excelPath); var data = ExcelUtil_1.default.creatObj(headInfo); if (argv.t.findIndex(function (v) { return v == 'ts_alone'; }) != -1) { FileUtil_1.default.saveTsAlone(data); } if (argv.t.findIndex(function (v) { return v == 'js_alone'; }) != -1) { FileUtil_1.default.saveJsAlone(data); } outPutData.push(data); } if (!argv.c) { FileUtil_1.default.checkAndMakeDir(Config_1.Config.outPutDir); if (argv.t.findIndex(function (v) { return v == 'js'; }) != -1) { FileUtil_1.default.saveJs(outPutData); } if (argv.t.findIndex(function (v) { return v == 'ts'; }) != -1) { FileUtil_1.default.saveTs(outPutData); } if (argv.t.findIndex(function (v) { return v == 'jsjson'; }) != -1) { FileUtil_1.default.saveJsJson(outPutData); } if (argv.t.findIndex(function (v) { return v == 'tsjson'; }) != -1) { FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.jsonOutputDir)); FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.tsOutputDir)); FileUtil_1.default.saveTsJson(outPutData); } if (argv.t.findIndex(function (v) { return v == 'tsjsonmin'; }) != -1) { FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.jsonOutputDir)); FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, Config_1.Config.tsOutputDir)); FileUtil_1.default.saveTsJson(outPutData, true); } if (argv.t.findIndex(function (v) { return v == 'csv'; }) != -1) { FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, 'csv')); FileUtil_1.default.saveCsv(outPutData); } if (argv.t.findIndex(function (v) { return v == 'hsv'; }) != -1) { FileUtil_1.default.checkAndMakeDir(path.join(Config_1.Config.outPutDir, 'hsv')); FileUtil_1.default.saveHsv(outPutData); } } process.exit(Config_1.Config.retCode); }; return Main; }()); new Main().run();