-
Notifications
You must be signed in to change notification settings - Fork 4
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
4 changed files
with
63 additions
and
50 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,69 +1,78 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const directory = process.argv[2]; // Take directory as an input argument | ||
const baseDirectory = './langs'; // Adjust if your base directory differs | ||
const conversionFile = './languages-conversion.json'; | ||
|
||
let foundErrors = false; | ||
|
||
try { | ||
const files = fs.readdirSync(directory); | ||
const conversionData = fs.readFileSync(conversionFile, 'utf8'); | ||
const languageMap = JSON.parse(conversionData); | ||
|
||
if (files.length === 0) { | ||
console.log("No JSON files found in the directory."); | ||
process.exit(0); | ||
} | ||
|
||
console.log(`Found ${files.length} files in the directory.`); | ||
Object.entries(languageMap).forEach(([key, value]) => { | ||
const directory = path.join(baseDirectory, value, 'bot', 'slash_commands'); | ||
if (!fs.existsSync(directory)) { | ||
console.log(`Skipping non-existent directory: ${directory} for language code ${key}`); | ||
return; | ||
} | ||
|
||
files.forEach(file => { | ||
if (!file.endsWith('.json')) { | ||
console.log(`Skipping non-JSON file: ${file}`); | ||
const files = fs.readdirSync(directory); | ||
if (files.length === 0) { | ||
console.log(`No JSON files found in ${directory}.`); | ||
return; | ||
} | ||
|
||
const filePath = path.join(directory, file); | ||
try { | ||
const data = fs.readFileSync(filePath, 'utf8'); | ||
const jsonData = JSON.parse(data); | ||
files.forEach(file => { | ||
if (!file.endsWith('.json')) { | ||
console.log(`Skipping non-JSON file: ${file}`); | ||
return; | ||
} | ||
|
||
console.log(`Processing ${file}...`); | ||
console.log(`Validating ${value}/${file}...`) | ||
const filePath = path.join(directory, file); | ||
try { | ||
const data = fs.readFileSync(filePath, 'utf8'); | ||
const jsonData = JSON.parse(data); | ||
|
||
function checkFields(obj, path = '') { | ||
Object.keys(obj).forEach(key => { | ||
const value = obj[key]; | ||
const currentPath = path ? `${path}.${key}` : key; | ||
|
||
if (typeof value === 'string') { | ||
if (path.endsWith('.description') && value.length > 100) { | ||
console.error(`${file}: Description exceeds 100 characters at '${currentPath}'`); | ||
foundErrors = true; | ||
} | ||
if (path.endsWith('.name') && value.includes(' ')) { | ||
console.error(`${file}: Name contains space at '${currentPath}'`); | ||
foundErrors = true; | ||
function checkFields(obj, path = '') { | ||
Object.keys(obj).forEach(key => { | ||
const value = obj[key]; | ||
const currentPath = path ? `${path}.${key}` : key; | ||
|
||
if (typeof value === 'string') { | ||
if (currentPath.endsWith('.description') && value.length > 100) { | ||
console.error(`Validation error: ${directory}/${file}: Description exceeds 100 characters at '${currentPath}'`); | ||
foundErrors = true; | ||
} | ||
if (currentPath.endsWith('.name') && value.includes(' ')) { | ||
console.error(`Validation error: ${directory}/${file}: Name contains space at '${currentPath}'`); | ||
foundErrors = true; | ||
} | ||
} else if (typeof value === 'object' && value !== null) { | ||
checkFields(value, currentPath); | ||
} | ||
} else if (typeof value === 'object' && value !== null) { | ||
checkFields(value, currentPath); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
checkFields(jsonData); | ||
checkFields(jsonData); | ||
|
||
} catch (err) { | ||
console.error(`Error processing ${file}:`, err); | ||
foundErrors = true; | ||
} | ||
} catch (err) { | ||
console.error(`Error processing ${file}:`, err); | ||
foundErrors = true; | ||
} | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error("Error reading the directory:", err); | ||
process.exit(1); | ||
} | ||
|
||
if (foundErrors) { | ||
console.error("Validation errors found in the files. Please check the logs above."); | ||
if (foundErrors) { | ||
console.error("Validation errors found in some JSON files. Please check the logs above."); | ||
process.exit(1); | ||
} else { | ||
console.log("All files validated successfully."); | ||
process.exit(0); | ||
} | ||
|
||
} catch (err) { | ||
console.error("Error reading the conversion file or directory:", err); | ||
process.exit(1); | ||
} else { | ||
console.log("All files validated successfully."); | ||
process.exit(0); | ||
} |
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,5 @@ | ||
{ | ||
"en-US": "en_us", | ||
"en-GB": "en_gb", | ||
"tr": "tr" | ||
} |
This file was deleted.
Oops, something went wrong.