Here is something to start with. Using the following function you could get an array containing the list of files contained in a folder. To filter out ā*.jsā you need to apply your own checks.
function getFiles(folder){
var outFiles = [];
var fs = require('fs');
if ( typeof fs == 'undefined'){
return outFiles;
}
var dir = folder;
var files = fs.readdirSync(dir);
for(var i = 0; i < files.length; i++) {
var f = files[i];
var fn = f.substring(f.lastIndexOf('/')+1);
try{
var stats = fs.statSync(dir+f);
if (stats.isFile()) {
outFiles.push(dir+f);
}
}
catch(ex){
// Handle error(s) here
}
}
return outFiles;
}
Call it like:
var myFiles = getFiles('./mods/YourMod/YourFiles/');
Iād rather you just specify your js files manually. We might disallow using āfsā (as suggested by @alphabit) for security reasons so this might break your mod in the futureā¦
I wasnāt sure whether to post this code or not. It comes from a deprecated internal UL method, which we used in the early days for dynamically loading JS files (which we dropped later for obvious reasons).
I wasnāt aware that it will be disallowed in future. So I need to make sure that I donāt use it somewhere else in my other mods
Well, take my save backing up mod as an example
Although I could just store the backups in the regular data store anyway just like most other mods do, but it would get unneccesarily largeā¦