Skip to content

Commit dc5508f

Browse files
committed
1.2.4
1 parent d658b9c commit dc5508f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@idrinth/typescript-language-from-yaml",
3-
"version": "1.2.1",
3+
"version": "1.2.4",
44
"description": "Translates yaml files to ts for translation autocompletion, autocorrection and better developer support",
55
"bin": {
66
"itlfy": "bin/itlfy.js"

src/generate.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Logger from './logger.js';
1313
import toTypescriptObject from './to-typescript-object.js';
1414
import loadKeys from './loadKeys.js';
1515
import Config from './config.js';
16+
import toTypescriptObjectType from "./to-typescript-object-type.js";
1617

1718
export 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
}

src/to-typescript-object-type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import toTypescriptObject from './to-typescript-object.js';
2+
3+
export default (data: object,) => toTypescriptObject(data,)
4+
.replace(/: '.*?',\n/ug, ': string,\n',);

0 commit comments

Comments
 (0)