Update "generatei18nResources" script to commit changes

This commit is contained in:
schroda
2025-07-03 22:15:14 +02:00
parent b69b0d4a48
commit 81bba4ffff

View File

@@ -8,6 +8,7 @@
import path from 'path';
import fs from 'fs';
import { execSync } from 'child_process';
import {
fetchWeblateLanguageStats,
getWeblateLanguageStatsFor,
@@ -16,7 +17,9 @@ import {
import { WeblateLanguageStatistic } from './Weblate.types.ts';
import { TRANSLATED_PERCENT_THRESHOLD } from './Weblate.constants.ts';
const outputFilePath = path.join(import.meta.dirname, '../../../src/i18n/index.ts');
const FILE_PATH = 'src/i18n/index.ts';
const outputFilePath = path.join(import.meta.dirname, `../../../${FILE_PATH}`);
const resourcesDirPath = path.join(import.meta.dirname, '../../../public/locales');
const extractLanguageCode = (resourceFileNames: string): string =>
@@ -57,6 +60,19 @@ const generateResources = async () => {
);
fs.writeFileSync(outputFilePath, updatedFileContent);
execSync('yarn tsc', { stdio: 'inherit' });
execSync(`yarn eslint --fix ${FILE_PATH}`, { stdio: 'inherit' });
const hasFileChanged = execSync('git status --porcelain').toString().includes(FILE_PATH);
if (!hasFileChanged) {
return;
}
execSync('git reset');
execSync(`git add ${FILE_PATH}`);
execSync('git commit -m "Update available languages"');
};
generateResources();