-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"input": { | ||
"format": "nested", | ||
"path": "./input/default.json" | ||
}, | ||
"output": { | ||
"path": "./output/default.d.ts" | ||
}, | ||
"rules": [ | ||
{ | ||
"//": "Add pluralization placeholders", | ||
"condition": { "keyEndsWith": ["zero", "one", "other"] }, | ||
"transformer": { | ||
"addPlaceholder": { "name": "count", "type": ["number", "string"] }, | ||
"removeLastPart": true | ||
} | ||
}, | ||
{ | ||
"//": "Add interpolation values for matched placeholders", | ||
"condition": { "placeholderPattern": { "prefix": "{{", "suffix": "}}" } }, | ||
"transformer": { | ||
"addMatchedPlaceholder": { "type": ["string", "number"] } | ||
} | ||
} | ||
], | ||
"extra": { | ||
"prettierIgnore": true, | ||
"eslintDisablePrettier": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"animals": { | ||
"one": "{{count}} animal", | ||
"other": "{{count}} animals", | ||
"zero": "No animal" | ||
}, | ||
"welcome": "Welcome {{name}}", | ||
"age": "{{months}}m {{days}}d", | ||
"lorem": "Culpa et aliquip proident adipisicing in." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable prettier/prettier */ | ||
// prettier-ignore | ||
|
||
/** | ||
* Generated by i18n-type-generator | ||
* https://github.com/BeTomorrow/i18n-typegen | ||
*/ | ||
|
||
declare module "translations" { | ||
type Translations = { | ||
"animals": { count: number | string }; | ||
"welcome": { name: string | number }; | ||
"age": { months: string | number; days: string | number }; | ||
"lorem": undefined; | ||
}; | ||
|
||
type TranslationKeys = keyof Translations; | ||
|
||
type TranslationFunctionArgs<T extends TranslationKeys> = T extends TranslationKeys | ||
? Translations[T] extends undefined | ||
? [key: T] | ||
: [key: T, interpolates: Translations[T]] | ||
: never; | ||
|
||
type TranslationFunction = <T extends TranslationKeys>(...args: TranslationFunctionArgs<T>) => string; | ||
|
||
export { TranslationFunction, TranslationFunctionArgs, TranslationKeys }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// prettier-ignore | ||
|
||
/** | ||
* Generated by i18n-type-generator | ||
* https://github.com/BeTomorrow/i18n-typegen | ||
*/ | ||
|
||
declare module "translations" { | ||
type Translations = { | ||
"animals": { count: number | string }; | ||
"welcome": { name: string | number }; | ||
"age": { months: string | number; days: string | number }; | ||
"lorem": undefined; | ||
}; | ||
|
||
type TranslationKeys = keyof Translations; | ||
|
||
type TranslationFunctionArgs<T extends TranslationKeys> = T extends TranslationKeys | ||
? Translations[T] extends undefined | ||
? [key: T] | ||
: [key: T, interpolates: Translations[T]] | ||
: never; | ||
|
||
type TranslationFunction = <T extends TranslationKeys>(...args: TranslationFunctionArgs<T>) => string; | ||
|
||
export { TranslationFunction, TranslationFunctionArgs, TranslationKeys }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { exec } = require("child_process"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const binPath = path.join(__dirname, "..", "src", "index.ts"); | ||
const configPath = path.join(__dirname, "input", "default.config.json"); | ||
const outputPath = path.join(__dirname, "output", "default.d.ts"); | ||
const snapshotPath = path.join(__dirname, "snapshot", "default.d.ts"); | ||
|
||
// Function to compare files | ||
function compareFiles(file1, file2) { | ||
const content1 = fs.readFileSync(file1, "utf8"); | ||
const content2 = fs.readFileSync(file2, "utf8"); | ||
return content1 === content2; | ||
} | ||
|
||
// Run the Node.js program with the specified configuration | ||
exec(`npx ts-node ${binPath} codegen -c "${configPath}"`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error executing command: ${error}`); | ||
return; | ||
} | ||
|
||
// Compare the output file with the snapshot | ||
if (compareFiles(outputPath, snapshotPath)) { | ||
console.log("Test passed: Output matches the snapshot."); | ||
} else { | ||
console.log("Test failed: Output does not match the snapshot."); | ||
|
||
// Print the differences | ||
const diff = require("diff"); | ||
const outputContent = fs.readFileSync(outputPath, "utf8"); | ||
const snapshotContent = fs.readFileSync(snapshotPath, "utf8"); | ||
const differences = diff.createTwoFilesPatch( | ||
outputPath, | ||
snapshotPath, | ||
outputContent, | ||
snapshotContent | ||
); | ||
console.log(differences); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters