Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
i18-cli
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马旭烽
i18-cli
Commits
225d13d6
Commit
225d13d6
authored
Jun 26, 2023
by
马旭烽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🦄
refactor: 导入命令参数注入与执行分离
parent
22456237
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
len.ts
package/src/order/len.ts
+27
-0
len.ts
package/src/work/len.ts
+108
-0
No files found.
package/src/order/len.ts
0 → 100644
View file @
225d13d6
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
package/src/work/len.ts
0 → 100644
View file @
225d13d6
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment