39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
/**
|
|
* Builds a configuration file for rules locales based on the input directory.
|
|
* This script generates a configuration file containing a list of locales,
|
|
* based on the existing files with the specified extension in the input directory.
|
|
* This enhances the game's accessibility to different languages.
|
|
*
|
|
* @param {string} inputDirectory - The directory to read the files from.
|
|
* @param {string} outputDirectory - The directory to write the configuration file to.
|
|
* @param {string} extname - The extension of the files to be included.
|
|
* @param {string} outputFileName - The name of output file.
|
|
* @returns {void}
|
|
*/
|
|
function buildLocalesConfig(inputDirectory, outputDirectory, extname, outputFileName) {
|
|
// Get all files from the input directory
|
|
const files = fs.readdirSync(inputDirectory);
|
|
|
|
// Filter only files with the provided extension
|
|
const filteredFiles = files.filter(file => path.extname(file) === extname);
|
|
|
|
// Remove extensions from filenames
|
|
const fileNamesWithoutExtensions = filteredFiles.map(file => path.parse(file).name);
|
|
|
|
// Write the array of filenames to the new file in the output directory
|
|
fs.writeFileSync(
|
|
path.join(outputDirectory, outputFileName),
|
|
JSON.stringify(fileNamesWithoutExtensions, null, 2) // 2 spaces for indentation in the output json
|
|
);
|
|
}
|
|
|
|
const inputDirectory = process.argv[2];
|
|
const outputDirectory = process.argv[3];
|
|
const extname = process.argv[4];
|
|
const outputFileName = process.argv[5];
|
|
|
|
buildLocalesConfig(inputDirectory, outputDirectory, extname, outputFileName);
|