1
1
#! /usr/bin/env node
2
2
import { fontSplit , VERSION_CN_FONT_SPLIT } from '../dist/index.js' ;
3
- import fs from 'fs'
4
- const args = process . argv . slice ( 2 )
3
+ import fs from 'fs' ;
4
+ const args = process . argv . slice ( 2 ) ;
5
5
6
- let input = { }
7
- let help = false
6
+ let input = { } ;
7
+ let help = false ;
8
8
for ( let i of args ) {
9
- if ( i . startsWith ( "-" ) ) {
10
- const [ , keysString , val ] = i . match ( / ^ [ - ] { 1 , 2 } ( .* ?) ( = .* ?) ? $ / i
11
- )
12
- if ( [ 'h' , 'help' ] . some ( i => keysString === i ) ) help = true
9
+ if ( i . startsWith ( '-' ) ) {
10
+ const [ , keysString , val ] = i . match ( / ^ [ - ] { 1 , 2 } ( .* ?) ( = .* ?) ? $ / i) ;
11
+ if ( [ 'h' , 'help' ] . some ( ( i ) => keysString === i ) ) help = true ;
13
12
14
-
15
- let prev = input
16
- const keys = keysString . split ( '.' )
13
+ let prev = input ;
14
+ const keys = keysString . split ( '.' ) ;
17
15
for ( const iterator of keys ) {
18
16
if ( iterator === keys [ keys . length - 1 ] ) {
19
17
if ( ! val ) {
20
- prev [ iterator ] = true
18
+ prev [ iterator ] = true ;
21
19
} else {
22
- prev [ iterator ] = stringToValue ( val . slice ( 1 ) )
20
+ prev [ iterator ] = stringToValue ( val . slice ( 1 ) ) ;
23
21
}
24
- break
22
+ break ;
25
23
}
26
24
if ( ! prev [ iterator ] ) {
27
- prev [ iterator ] = { }
25
+ prev [ iterator ] = { } ;
28
26
}
29
- prev = prev [ iterator ]
27
+ prev = prev [ iterator ] ;
30
28
}
31
29
}
32
30
}
33
31
34
32
if ( help ) {
35
- console . log ( `//========== cn-font-split help ${ VERSION_CN_FONT_SPLIT } ===========` )
36
- console . log ( " use . to set the input value." )
37
- console . log ( " cn-font-split -i=./a.ttf -o=./dist" )
38
- console . log ( "//==== more params " )
39
- console . log ( fs . readFileSync ( new URL ( '../src/interface.ts' , import . meta. url ) , 'utf-8' ) . match ( / (?< = I n p u t T e m p l a t e = ) ( [ \s \S ] + ) / mg) [ 0 ] )
40
- console . log ( `//========== cn-font-split help ${ VERSION_CN_FONT_SPLIT } ===========` )
33
+ console . log (
34
+ `//========== cn-font-split help ${ VERSION_CN_FONT_SPLIT } ===========` ,
35
+ ) ;
36
+ console . log ( ' use . to set the input value.' ) ;
37
+ console . log ( ' cn-font-split -i=./a.ttf -o=./dist' ) ;
38
+ console . log ( '//==== more params ' ) ;
39
+ console . log (
40
+ fs
41
+ . readFileSync (
42
+ new URL ( '../src/interface.ts' , import . meta. url ) ,
43
+ 'utf-8' ,
44
+ )
45
+ . match ( / (?< = I n p u t T e m p l a t e = ) ( [ \s \S ] + ) / gm) [ 0 ] ,
46
+ ) ;
47
+ console . log (
48
+ `//========== cn-font-split help ${ VERSION_CN_FONT_SPLIT } ===========` ,
49
+ ) ;
41
50
} else {
42
- input . FontPath = input . FontPath || input . i || input . input
43
- input . destFold = input . destFold || input . o || input . output || input . d
44
- console . log ( VERSION_CN_FONT_SPLIT )
51
+ input . FontPath = input . FontPath || input . i || input . input ;
52
+ input . destFold = input . destFold || input . o || input . output || input . d ;
53
+ console . log ( VERSION_CN_FONT_SPLIT ) ;
45
54
if ( input . FontPath && input . destFold ) {
46
- fontSplit ( input )
55
+ fontSplit ( input ) ;
47
56
} else {
48
- console . log ( " Error: -i or -o must be filled!" )
57
+ console . log ( ' Error: -i or -o must be filled!' ) ;
49
58
}
50
59
}
51
60
52
-
53
61
function stringToValue ( val ) {
54
62
if ( val . toLowerCase ( ) === 'true' ) {
55
- return true
63
+ return true ;
56
64
} else if ( val . toLowerCase ( ) === 'false' ) {
57
- return false
65
+ return false ;
58
66
} else if ( '1234567890' . includes ( val [ 0 ] ) ) {
59
- return + val
67
+ return + val ;
60
68
}
61
- return val
62
- }
69
+ return val ;
70
+ }
0 commit comments