2024-09-26 22:54:26 +00:00
|
|
|
/*
|
|
|
|
DRAGONROLL PREBUILD SCRIPT
|
|
|
|
*/
|
|
|
|
|
2024-09-12 21:55:22 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2024-09-26 22:54:26 +00:00
|
|
|
const plugins = fs.readdirSync('./plugins')
|
|
|
|
|
|
|
|
// #region icons
|
2024-09-12 21:55:22 +00:00
|
|
|
const folderPaths = [
|
|
|
|
'./client/public/icons/weapons',
|
|
|
|
'./client/public/icons/equipment',
|
|
|
|
'./client/public/icons/consumables',
|
|
|
|
'./client/public/icons/magic',
|
|
|
|
'./client/public/icons/skills',
|
|
|
|
'./client/public/icons/sundries',
|
|
|
|
'./client/public/icons/tools',
|
|
|
|
'./client/public/icons/commodities',
|
|
|
|
'./client/public/icons/containers',
|
|
|
|
'./client/public/icons/creatures',
|
|
|
|
'./client/public/icons/environment',
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2024-09-26 22:54:26 +00:00
|
|
|
const outputPath = 'client/public/data/data.json'
|
|
|
|
fs.mkdirSync('client/public/data', { recursive: true });
|
2024-09-26 22:57:52 +00:00
|
|
|
fs.mkdirSync('client/src/locales', { recursive: true });
|
2024-09-26 22:54:26 +00:00
|
|
|
|
2024-09-12 21:55:22 +00:00
|
|
|
let result = [];
|
|
|
|
|
|
|
|
let iconCount = 0;
|
|
|
|
for(let i = 0; i < folderPaths.length; i++){
|
|
|
|
const files = fs.readdirSync(folderPaths[i], { recursive: true });
|
|
|
|
for(let j = 0; j < files.length; j++){
|
|
|
|
let absPath = folderPaths[i] + "/" + files[j]
|
|
|
|
if(fs.lstatSync(absPath).isFile()){
|
|
|
|
result.push({
|
|
|
|
path: absPath.replace(/^(\.\/client\/public\/)/,""),
|
|
|
|
name: path.parse(absPath).name
|
|
|
|
});
|
|
|
|
iconCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-09-26 22:54:26 +00:00
|
|
|
let icons = {files: result};
|
2024-09-12 21:55:22 +00:00
|
|
|
|
|
|
|
console.log('File list generated successfully!');
|
2024-09-22 21:57:15 +00:00
|
|
|
console.log("Generated " + iconCount + " icons");
|
|
|
|
|
2024-09-26 22:54:26 +00:00
|
|
|
// #endregion
|
|
|
|
// #region locales
|
|
|
|
|
|
|
|
const locales = fs.readdirSync("./locales");
|
2024-09-22 21:57:15 +00:00
|
|
|
|
|
|
|
function deepMerge(obj1, obj2) {
|
|
|
|
for (let key in obj2) {
|
|
|
|
if (obj2.hasOwnProperty(key)) {
|
|
|
|
if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
|
|
|
|
obj1[key] = deepMerge(obj1[key], obj2[key]);
|
|
|
|
} else {
|
|
|
|
obj1[key] = obj2[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj1;
|
|
|
|
}
|
|
|
|
|
2024-09-26 22:54:26 +00:00
|
|
|
let originalJson = JSON.parse(fs.readFileSync("./locales/en-US.json"));
|
|
|
|
for(let i = 0; i < locales.length; i++){
|
|
|
|
let data = JSON.parse(fs.readFileSync("./locales/" + locales[i]));
|
|
|
|
fs.writeFileSync("./locales/" + locales[i], JSON.stringify(deepMerge(structuredClone(originalJson), data), null, 2));
|
2024-09-22 21:57:15 +00:00
|
|
|
};
|
2024-09-26 22:54:26 +00:00
|
|
|
|
|
|
|
for(let i = 0; i < locales.length; i++){
|
|
|
|
let originalLocale = JSON.parse(fs.readFileSync('./locales/' + locales[i]));
|
|
|
|
for(let j = 0; j < plugins.length; j++){
|
|
|
|
if(fs.existsSync(`./plugins/${plugins[j]}/locales/${locales[i]}`)){
|
|
|
|
let pluginLocale = JSON.parse(fs.readFileSync(`./plugins/${plugins[j]}/locales/${locales[i]}`));
|
|
|
|
let mergeJson = {plugins: {}};
|
|
|
|
mergeJson.plugins[plugins[j]] = pluginLocale;
|
|
|
|
originalLocale = deepMerge(originalLocale, mergeJson);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fs.writeFileSync("./client/src/locales/" + locales[i], JSON.stringify(originalLocale, null, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Updated Locales")
|
2024-10-19 12:20:21 +00:00
|
|
|
|
2024-09-26 22:54:26 +00:00
|
|
|
// #endregion
|
|
|
|
// #region plugins
|
|
|
|
|
|
|
|
for(let j = 0; j < plugins.length; j++){
|
2024-10-19 12:20:21 +00:00
|
|
|
// Cient scripts and views
|
2024-09-26 22:54:26 +00:00
|
|
|
if(fs.existsSync(`./plugins/${plugins[j]}/client/`)){
|
|
|
|
fs.cpSync(`./plugins/${plugins[j]}/client/`, `./client/plugins/${plugins[j]}`, {recursive: true});
|
2024-09-27 23:41:47 +00:00
|
|
|
fs.copyFileSync(`./plugins/${plugins[j]}/plugin.json`, `./client/plugins/${plugins[j]}/plugin.json`);
|
2024-09-26 22:54:26 +00:00
|
|
|
}
|
2024-09-27 10:23:36 +00:00
|
|
|
|
2024-10-19 12:20:21 +00:00
|
|
|
// Backend scripts
|
2024-10-01 12:57:53 +00:00
|
|
|
if(fs.existsSync(`./plugins/${plugins[j]}/backend/`)){
|
|
|
|
fs.cpSync(`./plugins/${plugins[j]}/backend/`, `./backend/plugins/${plugins[j]}`, {recursive: true});
|
|
|
|
fs.copyFileSync(`./plugins/${plugins[j]}/plugin.json`, `./backend/plugins/${plugins[j]}/plugin.json`);
|
|
|
|
}
|
|
|
|
|
2024-10-19 12:20:21 +00:00
|
|
|
// Public folder
|
2024-09-27 10:23:36 +00:00
|
|
|
if(fs.existsSync(`./plugins/${plugins[j]}/public/`)){
|
|
|
|
fs.cpSync(`./plugins/${plugins[j]}/public/`, `./client/public/plugins/${plugins[j]}`, {recursive: true});
|
|
|
|
}
|
2024-10-19 12:20:21 +00:00
|
|
|
|
|
|
|
// Datagen
|
|
|
|
if(fs.existsSync(`./plugins/${plugins[j]}/datagen`)){
|
|
|
|
fs.readdirSync(`./plugins/${plugins[j]}/datagen`).forEach(d => {
|
|
|
|
fs.cpSync(`./plugins/${plugins[j]}/datagen/${d}`, `./backend/datagen/${plugins[j]}/${d}`, {recursive: true});
|
|
|
|
})
|
|
|
|
}
|
2024-09-26 22:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(outputPath, JSON.stringify({
|
|
|
|
icons,
|
|
|
|
plugins
|
|
|
|
}, null, "\t"));
|
2024-09-27 13:02:19 +00:00
|
|
|
console.log("Installed plugins")
|
2024-09-26 22:54:26 +00:00
|
|
|
// #endregion
|