#!/usr/bin/env node import program from 'commander'; import { join } from 'path'; import { auction } from '../auction'; import { createConf, getConfig } from '../generate-conf'; import { handleCsvs } from '../handle-csv'; import { handleFiles } from '../handle-file'; import { handleLogs } from '../handle-log'; import { print } from '../utils/print'; import '../utils/program'; async function handle() { program.option('-t, --type ', '操作类型').option('-s --special ', '拍卖会场次'); // program.addOption(new Option('-t, --type ', '操作类型').choices(['auction'])); // program.option('-i, --input-dir ', '源文件的文件夹', '/root/input'); // program.option('-o, --output-dir ', '输出的文件夹', '/root/output'); // program.option('-g, --generate-conf', '创建配置文件到目录'); program.parse(process.argv); const cliOptions = program.opts(); const { type, inputDir, outputDir, generateConf } = cliOptions; if (generateConf) { createConf({ type, inputDir, outputDir, }); return; } // 需要配置文件的操作类型 const conf = ['log', 'csv'].includes(type) && (await getConfig(type)); switch (type) { case 'log': handleLogs(conf); break; case 'csv': handleCsvs(conf); break; case 'check': handleFiles({ inputDir, outputFilePath: join(outputDir, 'files-info.csv') }); break; case 'auction': auction.doAnalytics(cliOptions); break; default: break; } } handle().catch((err: Error) => { print(`error: ${err.message}`); });