@@ -13,6 +13,7 @@ import Logger from './logger.js';
1313import toTypescriptObject from './to-typescript-object.js' ;
1414import loadKeys from './loadKeys.js' ;
1515import Config from './config.js' ;
16+ import toTypescriptObjectType from "./to-typescript-object-type.js" ;
1617
1718export default (
1819 logger : Logger ,
@@ -42,42 +43,51 @@ export default (
4243
4344 const content = readFileSync ( yamlPath , 'utf8' , ) ;
4445 const data = parse ( content , ) ;
45- const typeName = localConfig . isStrictTypes ? 'langType' : 'Partial<langType>' ;
4646 if ( localConfig . isSplit && typeof data [ Object . keys ( data , ) . pop ( ) ] !== 'string' ) {
4747 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 = ' ;
4855 writeFileSync (
4956 `${ 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` ,
5358 'utf8' ,
5459 ) ;
5560 files . push ( `${ lang } -${ key } ` , ) ;
56- if ( lang === 'en' ) {
61+ if ( lang === 'en' && localConfig . isStrictTypes ) {
5762 writeFileSync (
5863 `${ folder } /${ localConfig . targetDirectory } /type-${ key } .ts` ,
5964 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` ,
6267 'utf8' ,
6368 ) ;
6469 }
6570 }
6671 } 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 = ' ;
6779 writeFileSync (
6880 `${ 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` ,
7282 'utf8' ,
7383 ) ;
7484 files . push ( `${ lang } ` , ) ;
75- if ( lang === 'en' ) {
85+ if ( lang === 'en' && localConfig . isStrictTypes ) {
7686 writeFileSync (
7787 `${ folder } /${ localConfig . targetDirectory } /type.ts` ,
7888 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` ,
8191 'utf8' ,
8292 ) ;
8393 }
0 commit comments