Commit 225d13d6 authored by 马旭烽's avatar 马旭烽

🦄 refactor: 导入命令参数注入与执行分离

parent 22456237
import type { useProgramType } from '../utils/commanderUtli';
import { importLenWrok } from '../work/len';
/** 多语言导入命令 */
const importLenCommand: useProgramType<any> = ( program ) => {
return program
.command('importLen')
.description('导入i18语言包,导出xlsx包,语言包')
.option('-zh,--zhCNPath <zhCNPath>','导入中文包路径')
.option('-len, --otherLenPath <otherLenPath>', '导入其它包语言路径')
.option('-lenType, --otherLenType <otherLenType>', '导入其它语言类型')
.option('-lenRatio, --otherLenRatio [otherLenRatio]', '导入其它语言系数,可选')
.option('-d,--debug', '测试打印部分执行路径', false)
.action(async (args, _program) => {
let { zhCNPath, otherLenPath, otherLenType, otherlenRdio, debug } = args;
await importLenWrok({
zhCNPath,
otherLenPath,
otherLenType,
otherlenRdio,
debug,
})
});
};
export default importLenCommand;
\ No newline at end of file
import { ImportModal } from '../modal/ImportModal';
import { ExportModal } from '../modal/ExportModal';
import { normalizeFilePath } from '../utils/fileUtil';
import { getOutputFilePath } from '../utils/pathUtil';
import { checkLenObjToNoAllowArrayV1, getLenObjToMetaLenObj, getLenRatio } from '../helper/i18';
import { LanguageNameTypeEnum, } from '../constants';
const importModal = new ImportModal();
const exportModal = new ExportModal();
interface AgrementsType {
zhCNPath: string;
otherLenPath: string;
otherLenType: string;
otherlenRdio?: number;
debug?: boolean;
}
export const importLenWrok = async (args: AgrementsType) => {
let { zhCNPath, otherLenPath, otherLenType, otherlenRdio: otherLenRdio, debug } = args;
console.log('启动命令')
debug && console.log('命令行打印参数', args)
//check is Allow Or Return
if(!(zhCNPath && otherLenPath&&otherLenType)){
throw new TypeError('导入参数缺失');
};
zhCNPath = await normalizeFilePath(zhCNPath);
otherLenPath = await normalizeFilePath(otherLenPath);
if(debug){
console.log('中文路径', zhCNPath , );
console.log('其它语言路径', otherLenPath,);
console.log('其它语言类型', otherLenPath);
}
const zhCNMap = await importModal.importFileToJSObj_V1(zhCNPath);
const otherLenMap = await importModal.importFileToJSObj_V1(otherLenPath);
const loseKeys = Object.keys(zhCNMap).filter(key => !otherLenMap[key]);
console.log('语言包缺失内容关键地图',loseKeys);
if(debug){
console.log('对应的中文包解析', zhCNMap, typeof zhCNMap);
console.log('对应其它语言解析', otherLenMap);
console.log(otherLenPath, otherLenType, otherLenRdio)
}
const zhCNRatio = getLenRatio(LanguageNameTypeEnum.zhCN);
otherLenRdio = otherLenRdio || getLenRatio(otherLenType, otherLenRdio);
if(debug){
console.log('中文长度系数', zhCNRatio);
console.log('其它语言长度系数', otherLenRdio)
}
const zhCNMetaMap = getLenObjToMetaLenObj(zhCNMap, zhCNRatio);
const otherLenMetaMap = getLenObjToMetaLenObj(otherLenMap, otherLenRdio, zhCNMap);
if(debug){
console.log('中文元数据', zhCNMetaMap);
console.log('其它元数据', otherLenMetaMap);
}
const generateZhCNJsonFilePath = await getOutputFilePath(`${'zhCN'}.json`);
const generateXlsxFilePath = await getOutputFilePath(`${otherLenType}.xlsx`);
const generateJsonFilePath = await getOutputFilePath(`${otherLenType}.json`);
const checkNoAlowArray = checkLenObjToNoAllowArrayV1(otherLenMetaMap);
console.log(['生成文件路径', generateXlsxFilePath, generateJsonFilePath].join('\n'));
console.log('不达标长度', checkNoAlowArray);
await Promise.all([
exportModal.exportJSObjToJSONV1(zhCNMap, generateZhCNJsonFilePath),
// 其它语言包
exportModal.epportJSObjToXlsxV1(otherLenMetaMap, generateXlsxFilePath),
exportModal.exportJSObjToJSONV1(otherLenMap, generateJsonFilePath),
]);
if(loseKeys.length > 1) {
const outputPath = await getOutputFilePath('缺少键值.json');
await exportModal.exportJSObjToJSONV1(
{loseKeys}
,
outputPath
);
}
if(checkNoAlowArray.length > 0) {
const outputPath = await getOutputFilePath(`检验不通过.${otherLenType}.json`);
await exportModal.exportJSObjToJSONV1(
{checkLenObjToNoAllowArrayV1}
,
outputPath
);
};
console.log('执行结束');
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment