@@ -13,6 +13,7 @@ import Logger from './logger.js';
13
13
import toTypescriptObject from './to-typescript-object.js' ;
14
14
import loadKeys from './loadKeys.js' ;
15
15
import Config from './config.js' ;
16
+ import toTypescriptObjectType from "./to-typescript-object-type.js" ;
16
17
17
18
export default (
18
19
logger : Logger ,
@@ -42,42 +43,51 @@ export default (
42
43
43
44
const content = readFileSync ( yamlPath , 'utf8' , ) ;
44
45
const data = parse ( content , ) ;
45
- const typeName = localConfig . isStrictTypes ? 'langType' : 'Partial<langType>' ;
46
46
if ( localConfig . isSplit && typeof data [ Object . keys ( data , ) . pop ( ) ] !== 'string' ) {
47
47
for ( const key of Object . keys ( data , ) ) {
48
+ const head = localConfig . isStrictTypes
49
+ ? (
50
+ localConfig . isVerbatimModuleSyntax
51
+ ? `import {\n lang as langType,\n} from './type-${ key } .js';\nconst lang: langType = `
52
+ : `import langType from './type-${ key } .js';\nconst lang: langType = `
53
+ )
54
+ : 'const lang = ' ;
48
55
writeFileSync (
49
56
`${ folder } /${ localConfig . targetDirectory } /${ lang } -${ key } .ts` ,
50
- localConfig . isVerbatimModuleSyntax
51
- ? `/* eslint max-len:0 */\nimport {\n lang as langType,\n} from './type-${ key } .js';\nconst lang: ${ typeName } = ${ toTypescriptObject ( data [ key ] , ) } ;\n\nexport default lang;\n`
52
- : `/* eslint max-len:0 */\nimport langType from './type-${ key } .js';\nconst lang: ${ typeName } = ${ toTypescriptObject ( data [ key ] , ) } ;\n\nexport default lang;\n` ,
57
+ `/* eslint max-len:0 */\n${ head } ${ toTypescriptObject ( data [ key ] , ) } ;\n\nexport default lang;\n` ,
53
58
'utf8' ,
54
59
) ;
55
60
files . push ( `${ lang } -${ key } ` , ) ;
56
- if ( lang === 'en' ) {
61
+ if ( lang === 'en' && localConfig . isStrictTypes ) {
57
62
writeFileSync (
58
63
`${ folder } /${ localConfig . targetDirectory } /type-${ key } .ts` ,
59
64
localConfig . isVerbatimModuleSyntax
60
- ? `/* eslint max-len:0 */\ntype ln = ${ toTypescriptObject ( data [ key ] , ) . replace ( / : ' . * ? ' , / ug , ': string,' , ) } ;\n\nexport type lang = ln;\n`
61
- : `/* eslint max-len:0 */\ntype lang = ${ toTypescriptObject ( data [ key ] , ) . replace ( / : ' . * ? ' , / ug , ': string,' , ) } ;\n\nexport default lang;\n` ,
65
+ ? `/* eslint max-len:0 */\ntype ln = ${ toTypescriptObjectType ( data [ key ] , ) } ;\n\nexport type lang = ln;\n`
66
+ : `/* eslint max-len:0 */\ntype lang = ${ toTypescriptObjectType ( data [ key ] , ) } ;\n\nexport default lang;\n` ,
62
67
'utf8' ,
63
68
) ;
64
69
}
65
70
}
66
71
} else {
72
+ const head = localConfig . isStrictTypes
73
+ ? (
74
+ localConfig . isVerbatimModuleSyntax
75
+ ? `import {\n lang as langType,\n} from './type.js';\nconst lang: langType = `
76
+ : `import langType from './type.js';\nconst lang: langType = `
77
+ )
78
+ : 'const lang = ' ;
67
79
writeFileSync (
68
80
`${ folder } /${ localConfig . targetDirectory } /${ lang } .ts` ,
69
- localConfig . isVerbatimModuleSyntax
70
- ? `/* eslint max-len:0 */\nimport {\n lang as langType,\n} from './type.js';\nconst lang: ${ typeName } = ${ toTypescriptObject ( data , ) } ;\n\nexport default lang;\n`
71
- : `/* eslint max-len:0 */\nimport langType from './type.js';\nconst lang: ${ typeName } = ${ toTypescriptObject ( data , ) } ;\n\nexport default lang;\n` ,
81
+ `/* eslint max-len:0 */\n${ head } ${ toTypescriptObject ( data , ) } ;\n\nexport default lang;\n` ,
72
82
'utf8' ,
73
83
) ;
74
84
files . push ( `${ lang } ` , ) ;
75
- if ( lang === 'en' ) {
85
+ if ( lang === 'en' && localConfig . isStrictTypes ) {
76
86
writeFileSync (
77
87
`${ folder } /${ localConfig . targetDirectory } /type.ts` ,
78
88
localConfig . isVerbatimModuleSyntax
79
- ? `/* eslint max-len:0 */\ntype ln = ${ toTypescriptObject ( data , ) . replace ( / : ' . * ? ' , / ug , ': string,' , ) } ;\n\nexport type lang = ln;\n`
80
- : `/* eslint max-len:0 */\ntype lang = ${ toTypescriptObject ( data , ) . replace ( / : ' . * ? ' , / ug , ': string,' , ) } ;\n\nexport default lang;\n` ,
89
+ ? `/* eslint max-len:0 */\ntype ln = ${ toTypescriptObjectType ( data , ) } ;\n\nexport type lang = ln;\n`
90
+ : `/* eslint max-len:0 */\ntype lang = ${ toTypescriptObjectType ( data , ) } ;\n\nexport default lang;\n` ,
81
91
'utf8' ,
82
92
) ;
83
93
}
0 commit comments