Skip to content

Commit

Permalink
chore: Update .npmignore and .gitignore
Browse files Browse the repository at this point in the history
- Add setupTests.js to .npmignore
- Add physicalTest to .gitignore
- Add new tests
- Test: covering the tests
  • Loading branch information
gabriel-logan committed Oct 4, 2024
1 parent 18a065e commit fcd6e84
Show file tree
Hide file tree
Showing 16 changed files with 810 additions and 314 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
"jest.config.js",
"dist",
"/types/",
"geraTraducoes.js"
"geraTraducoes.js",
"setupTests.js",
],
parser: '@typescript-eslint/parser',
parserOptions: {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage/
.env
multiFolderGeneratedTranslations/
unicFolderGeneratedTranslations/
physicalTest
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ unicFolderGeneratedTranslations/
.yarnrc.*
.env
.env.*
setupTests.js
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
modulePathIgnorePatterns: ['<rootDir>/docs/'],
modulePathIgnorePatterns: ["<rootDir>/docs/", "<rootDir>/dist/"],
setupFilesAfterEnv: ["<rootDir>/setupTests.js"],
};

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"test": "jest --verbose",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"test:file": "jest tests/translate",
"test:silent": "jest --watchAll --silent --noStackTrace",
"build:dist": "tsc",
Expand Down
4 changes: 4 additions & 0 deletions setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
beforeAll(() => {
jest.spyOn(console, "log").mockImplementation(() => {});
jest.spyOn(console, "error").mockImplementation(() => {});
});
8 changes: 5 additions & 3 deletions src/translateToMultipleFolders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export default function translateToMultipleFolders(
const traducoesDir: string = path.join(process.cwd(), folderNamePath);

if (!fs.existsSync(traducoesDir)) {
fs.mkdirSync(traducoesDir, { recursive: true }); // Use { recursive: true } para criar pastas recursivamente, se necessário
fs.mkdirSync(traducoesDir, { recursive: true });
}

async function translateAndSave(lang: string) {
const langDir = path.join(traducoesDir, lang);

if (!fs.existsSync(langDir)) {
fs.mkdirSync(langDir);
fs.mkdirSync(langDir, { recursive: true });
}

const translations = await translate(
Expand All @@ -80,7 +80,9 @@ export default function translateToMultipleFolders(

const outputFileName = path.join(langDir, `${lang}.json`);

fs.writeFileSync(outputFileName, JSON.stringify(translations, null, 4));
fs.writeFileSync(outputFileName, JSON.stringify(translations, null, 4), {
encoding: "utf8",
});

// eslint-disable-next-line no-console
console.log(`Translations for ${lang} saved in ${outputFileName} \n\n`);
Expand Down
4 changes: 3 additions & 1 deletion src/translateToUnicFolder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export default function translateToUnicFolder(

const outputFileName = path.join(traducoesDir, `${lang}.json`);

fs.writeFileSync(outputFileName, JSON.stringify(translations, null, 4));
fs.writeFileSync(outputFileName, JSON.stringify(translations, null, 4), {
encoding: "utf8",
});

// eslint-disable-next-line no-console
console.log(`Translations for ${lang} saved in ${outputFileName} \n\n`);
Expand Down
Loading

0 comments on commit fcd6e84

Please sign in to comment.