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
058def7e
Commit
058def7e
authored
Jun 26, 2023
by
马旭烽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
feat: 添加 list 命令 (缓存命令功能)
parent
3663c23e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
180 additions
and
3 deletions
+180
-3
package.json
package/package.json
+2
-1
index.ts
package/src/constants/index.ts
+8
-2
index.ts
package/src/index.ts
+3
-0
ListManagerModal.ts
package/src/modal/ListManagerModal.ts
+92
-0
list.ts
package/src/order/list.ts
+75
-0
No files found.
package/package.json
View file @
058def7e
...
...
@@ -8,7 +8,8 @@
"test"
:
"ts-node bin/i18-cli.ts"
,
"dev:comment"
:
"启动开发环境"
,
"importLen-dev"
:
"ts-node-dev --respawn --transpile-only src/index.ts importLen -zh mock/input/zhCN/V1.ts -len mock/input/en/V1.ts -lenType enUs"
,
"importLen"
:
"ts-node src/index.ts importLen -zh mock/input/zhCN/V1.ts -len mock/input/en/V1.ts -lenType enUs"
"importLen"
:
"ts-node src/index.ts importLen -zh mock/input/zhCN/V1.ts -len mock/input/en/V1.ts -lenType enUs"
,
"listAdd"
:
"ts-node src/index.ts list -a add -zh mock/input/zhCN/v2.ts"
},
"files"
:
[
"bin"
,
...
...
package/src/constants/index.ts
View file @
058def7e
import
path
from
'path'
;
export
enum
LanguageNameTypeEnum
{
/** 中文 */
...
...
@@ -44,4 +45,9 @@ export interface CenterLanguageItemTypeV1 {
[
key
:
string
]:
string
,
}
export
type
SheettRowItemKey_V1
=
'唯一标识'
|
'翻译字段'
|
'建议长度'
;
\ No newline at end of file
export
type
SheettRowItemKey_V1
=
'唯一标识'
|
'翻译字段'
|
'建议长度'
;
/** 包路径 */
export
const
PACKAGE_PATH
=
path
.
join
(
__dirname
,
'..'
,
'..'
);
/** 生成默认配置目录 */
export
const
I18_GEN_PACKAGE_PATH
=
path
.
join
(
PACKAGE_PATH
,
'.i18'
);
\ No newline at end of file
package/src/index.ts
View file @
058def7e
...
...
@@ -5,6 +5,7 @@ import { registerUseProgram } from './utils/commanderUtli';
import
{
normalizeFilePath
}
from
'./utils/fileUtil'
;
import
{
getOutputFilePath
}
from
'./utils/pathUtil'
;
import
{
checkLenObjToNoAllowArrayV1
,
getLenObjToMetaLenObj
,
getLenRatio
}
from
'./helper/i18'
;
import
listCommand
from
'./order/list'
;
import
{
LanguageNameTypeEnum
,
}
from
'./constants'
;
program
...
...
@@ -114,6 +115,7 @@ const newProgram = registerUseProgram<{}>(program, [
console
.
log
(
'执行结束'
);
});
},
listCommand
,
],
{});
newProgram
.
parse
(
process
.
argv
);
\ No newline at end of file
package/src/modal/ListManagerModal.ts
0 → 100644
View file @
058def7e
import
path
from
'path'
;
import
fp
from
'fs/promises'
;
import
{
I18_GEN_PACKAGE_PATH
}
from
'../constants'
enum
ClassStatus
{
uninit
=
0
,
init
=
1
,
}
export
interface
CommandOption
{
/** 中文导入路径 */
zhCNPath
:
string
/** 其它语言导入路径 */
otherLenPath
:
string
/** 其它导入语言类型 */
lenType
:
string
/** lenRatio */
lenRatio
?:
string
;
}
interface
ManagerJson
{
list
:
CommandOption
[]
}
const
initJson
:
ManagerJson
=
{
list
:
[],
}
const
FILE_PATH
=
path
.
join
(
I18_GEN_PACKAGE_PATH
,
'list.manager.json'
);
const
getKey
=
(
item
:
CommandOption
)
=>
item
.
zhCNPath
+
item
.
otherLenPath
+
item
.
lenType
const
getKeys
=
(
items
:
CommandOption
[])
=>
items
.
map
(
getKey
);
export
class
ListManagerModal
{
status
:
ClassStatus
constructor
(){
this
.
status
=
ClassStatus
.
uninit
;
}
async
checkIsInit
()
{
try
{
await
fp
.
stat
(
FILE_PATH
)
this
.
status
=
ClassStatus
.
init
;
return
true
;
}
catch
(
error
)
{
return
false
}
}
async
generateInitFile
()
{
return
await
fp
.
writeFile
(
FILE_PATH
,
JSON
.
stringify
(
initJson
,
null
,
2
));
}
async
init
()
{
const
isInit
=
await
this
.
checkIsInit
();
if
(
!
isInit
)
{
await
this
.
generateInitFile
();
};
}
async
readContent
():
Promise
<
ManagerJson
>
{
if
(
ClassStatus
.
uninit
==
this
.
status
)
{
await
this
.
init
();
}
const
content
=
await
fp
.
readFile
(
FILE_PATH
,
{
encoding
:
'utf8'
});
const
format
=
(
content
:
string
)
=>
JSON
.
parse
(
content
);
return
format
(
content
);
}
private
writeContent
(
data
:
ManagerJson
)
{
return
fp
.
writeFile
(
FILE_PATH
,
JSON
.
stringify
(
data
,
null
,
2
));
}
async
addItems
(
items
:
CommandOption
[])
{
const
originData
=
await
this
.
readContent
();
const
newData
=
{
...
originData
};
newData
.
list
=
originData
.
list
.
concat
(...
items
);
await
this
.
writeContent
(
newData
);
return
this
;
}
async
removeItems
(
items
:
CommandOption
[])
{
const
filterKeys
=
getKeys
(
items
);
const
originData
=
await
this
.
readContent
();
const
newData
=
{
...
originData
};
newData
.
list
=
originData
.
list
.
filter
((
originItem
)
=>
!
filterKeys
.
includes
(
getKey
(
originItem
)));
await
this
.
writeContent
(
newData
);
return
this
;
}
}
\ No newline at end of file
package/src/order/list.ts
0 → 100644
View file @
058def7e
import
path
from
'path'
;
import
childProcess
from
'child_process'
;
import
{
LanguageNameTypeEnum
,
}
from
'../constants'
;
import
{
ListManagerModal
,
CommandOption
}
from
'../modal/ListManagerModal'
;
import
type
{
useProgramType
}
from
'../utils/commanderUtli'
;
enum
ActionType
{
see
=
'see'
,
add
=
'add'
,
remove
=
'remove'
,
run
=
'run'
,
}
const
checkIsActionType
=
(
action
:
unknown
):
action
is
ActionType
=>
{
return
[
ActionType
.
see
,
ActionType
.
add
,
ActionType
.
remove
,
ActionType
.
run
,
].
includes
(
action
as
ActionType
);
};
const
listMandagerModal
=
new
ListManagerModal
();
/**
* 管理输入输出命令
* @param program
* @returns
*/
const
listCommand
:
useProgramType
<
any
>
=
(
program
)
=>
{
return
program
.
command
(
'list'
,)
.
option
(
'-a,--action <action>'
,
'设置输入输出批操作 see/add/remove/run'
)
.
option
(
'-zh,--zhCNPath <zhCNPath>'
,
'设置中文路径'
)
.
description
(
'设置语言路径'
)
.
action
(
async
(
args
)
=>
{
const
{
action
,
zhCNPath
}
=
args
;
const
isActionType
=
checkIsActionType
(
action
);
const
iszhCNPath
=
!!
zhCNPath
;
const
isAllowed
=
isActionType
&&
iszhCNPath
;
if
(
!
isAllowed
)
{
throw
new
TypeError
(
'命令参数错误'
,
);
}
switch
(
action
)
{
case
ActionType
.
add
:
const
dirPath
=
path
.
dirname
(
zhCNPath
);
const
genInputPath
=
(
lenType
:
LanguageNameTypeEnum
)
=>
path
.
join
(
dirPath
,
'..'
,
lenType
);
const
lenTypes
=
[
LanguageNameTypeEnum
.
enUS
,
LanguageNameTypeEnum
.
koKR
];
const
lenTypeCommands
:
CommandOption
[]
=
lenTypes
.
map
(
lenType
=>
({
zhCNPath
,
otherLenPath
:
genInputPath
(
lenType
),
lenType
,
}))
await
listMandagerModal
.
addItems
(
lenTypeCommands
)
break
;
case
ActionType
.
run
:
const
{
list
}
=
await
listMandagerModal
.
readContent
();
list
.
forEach
(
item
=>
{
childProcess
.
spawn
(
'node'
,
[
''
])
})
}
})
};
export
default
listCommand
;
\ 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