chore: per-commit lint

This commit is contained in:
jialin
2025-03-03 14:30:55 +08:00
parent 1bb6c5fbfc
commit bb47b4475e
7 changed files with 321 additions and 12 deletions
+5
View File
@@ -26,5 +26,10 @@ To add a new language configuration, follow these steps:
- Translate the value of each key into your target language.
4. **Finalize the Configuration**
- Review and ensure all translations are complete.
- Your new language configuration is now ready for use!
5. **Check the Dir and File**
- `npm run check:locales`
+34
View File
@@ -0,0 +1,34 @@
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
import langConfigMap from './lang-config-map';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const localesDir = path.resolve(__dirname, './');
const existingEntries = new Set(fs.readdirSync(localesDir));
const errors: string[] = [];
Object.values(langConfigMap).forEach(({ lang }) => {
const expectedDir = lang;
const expectedFile = `${lang}.ts`;
const dirExists = existingEntries.has(expectedDir);
const fileExists = existingEntries.has(expectedFile);
if (dirExists || fileExists) {
if (!dirExists) errors.push(`❌ Missing directory: '${expectedDir}/'`);
if (!fileExists) errors.push(`❌ Missing file: '${expectedFile}'`);
}
});
if (errors.length) {
console.error('❌ Errors found:');
errors.forEach(console.error);
process.exit(1);
} else {
console.log('✅ All locales are correctly named.');
}