initial
This commit is contained in:
38
scripts/buildLocalesConfig.js
Normal file
38
scripts/buildLocalesConfig.js
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
3
scripts/prebuild.sh
Executable file
3
scripts/prebuild.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
npm run locales -- src/assets/rules/locales/ src/assets/configs/ .html locales.json
|
||||
npm run locales -- src/assets/translations/locales/ src/assets/configs/ .json translations.json
|
||||
Reference in New Issue
Block a user