@@ -16,94 +16,94 @@ type CompileOptions = {
16
16
mode ?: string
17
17
}
18
18
19
- export const command = 'compile'
20
- export const aliases = 'cp'
21
- export const describe = t ( 'compile the i18n resources' )
19
+ export default function defineCommand ( ) {
20
+ const command = 'compile'
21
+ const aliases = 'cp'
22
+ const describe = t ( 'compile the i18n resources' )
22
23
23
- export const builder = ( args : Argv ) : Argv < CompileOptions > => {
24
- return args
25
- . option ( 'source' , {
26
- type : 'string' ,
27
- alias : 's' ,
28
- describe : t ( 'the i18n resource source path' ) ,
29
- demandOption : true
30
- } )
31
- . option ( 'output' , {
32
- type : 'string' ,
33
- alias : 'o' ,
34
- describe : t ( 'the compiled i18n resource output path' )
35
- } )
36
- . option ( 'mode' , {
37
- type : 'string' ,
38
- alias : 'm' ,
39
- default : 'production' ,
40
- describe : t (
41
- "the compiled i18n resource mode, 'production' or 'development' (default: 'production')"
42
- )
43
- } )
44
- }
24
+ const builder = ( args : Argv ) : Argv < CompileOptions > => {
25
+ return args
26
+ . option ( 'source' , {
27
+ type : 'string' ,
28
+ alias : 's' ,
29
+ describe : t ( 'the i18n resource source path' ) ,
30
+ demandOption : true
31
+ } )
32
+ . option ( 'output' , {
33
+ type : 'string' ,
34
+ alias : 'o' ,
35
+ describe : t ( 'the compiled i18n resource output path' )
36
+ } )
37
+ . option ( 'mode' , {
38
+ type : 'string' ,
39
+ alias : 'm' ,
40
+ default : 'production' ,
41
+ describe : t (
42
+ "the compiled i18n resource mode, 'production' or 'development' (default: 'production')"
43
+ )
44
+ } )
45
+ }
45
46
46
- export const handler = async (
47
- args : Arguments < CompileOptions >
48
- ) : Promise < void > => {
49
- const output =
50
- args . output != null ? path . resolve ( dirname , args . output ) : process . cwd ( )
51
- const ret = await compile ( args . source , output , {
52
- mode : args . mode as DevEnv ,
53
- onCompile : ( source : string , output : string ) : void => {
54
- console . log (
55
- chalk . green (
56
- t ( 'Success compilation: {source} -> {output}' , { source, output } )
47
+ const handler = async ( args : Arguments < CompileOptions > ) : Promise < void > => {
48
+ const output =
49
+ args . output != null ? path . resolve ( dirname , args . output ) : process . cwd ( )
50
+ const ret = await compile ( args . source , output , {
51
+ mode : args . mode as DevEnv ,
52
+ onCompile : ( source : string , output : string ) : void => {
53
+ console . log (
54
+ chalk . green (
55
+ t ( 'Success compilation: {source} -> {output}' , { source, output } )
56
+ )
57
57
)
58
- )
59
- } ,
60
- onError : (
61
- code : number ,
62
- source : string ,
63
- output : string ,
64
- msg ?: string
65
- ) : void => {
66
- switch ( code ) {
67
- case CompileErrorCodes . NOT_SUPPORTED_FORMAT :
68
- const parsed = path . parse ( source )
69
- console . warn (
70
- chalk . yellow (
71
- t ( "{source}: Ignore compilation due to not supported '{ ext}'" , {
72
- named : { ext : parsed . ext }
73
- } )
58
+ } ,
59
+ onError : (
60
+ code : number ,
61
+ source : string ,
62
+ output : string ,
63
+ msg ? : string
64
+ ) : void => {
65
+ switch ( code ) {
66
+ case CompileErrorCodes . NOT_SUPPORTED_FORMAT :
67
+ const parsed = path . parse ( source )
68
+ console . warn (
69
+ chalk . yellow (
70
+ t ( "{source}: Ignore compilation due to not supported '{ext}'" , {
71
+ named : { ext : parsed . ext }
72
+ } )
73
+ )
74
74
)
75
- )
76
- break
77
- case CompileErrorCodes . INTERNAL_COMPILE_WARNING :
78
- console . log (
79
- chalk . yellow (
80
- t ( 'Warning compilation : {source} -> { output}, { msg}' , {
81
- named : { source , output , msg }
82
- } )
75
+ break
76
+ case CompileErrorCodes . INTERNAL_COMPILE_WARNING :
77
+ console . log (
78
+ chalk . yellow (
79
+ t ( 'Warning compilation: {source} -> {output}, {msg}' , {
80
+ named : { source, output, msg }
81
+ } )
82
+ )
83
83
)
84
- )
85
- break
86
- case CompileErrorCodes . INTERNAL_COMPILE_ERROR :
87
- console . log (
88
- chalk . green (
89
- t ( 'Error compilation : {source} -> { output}, { msg}' , {
90
- named : { source , output , msg }
91
- } )
84
+ break
85
+ case CompileErrorCodes . INTERNAL_COMPILE_ERROR :
86
+ console . log (
87
+ chalk . green (
88
+ t ( 'Error compilation: {source} -> {output}, {msg}' , {
89
+ named : { source, output, msg }
90
+ } )
91
+ )
92
92
)
93
- )
94
- break
95
- default :
96
- break
93
+ break
94
+ default :
95
+ break
96
+ }
97
97
}
98
- }
99
- } )
100
- debug ( 'compile: ' , ret )
101
- }
98
+ } )
99
+ debug ( 'compile: ' , ret )
100
+ }
102
101
103
- export default {
104
- command,
105
- aliases,
106
- describe,
107
- builder,
108
- handler
102
+ return {
103
+ command,
104
+ aliases,
105
+ describe,
106
+ builder,
107
+ handler
108
+ }
109
109
}
0 commit comments