const fs = require('fs');
const path = require('path');
const os = require('os');
function scan(dir, slash = '\\') {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
scan(filePath);
} else {
const filePathSplit = filePath.split(slash);
filePathSplit.splice(0, 2);
const fileName = filePathSplit.splice(-1, 1);
if(!actionsFiles[filePathSplit[0]]) {
actionsFiles[filePathSplit[0]] = {};
}
if(!actionsFiles[filePathSplit[0]][filePathSplit[1]]) {
actionsFiles[filePathSplit[0]][filePathSplit[1]] = {};
}
if(!actionsFiles[filePathSplit[0]][filePathSplit[1]][filePathSplit[2]]) {
actionsFiles[filePathSplit[0]][filePathSplit[1]][filePathSplit[2]] = [];
}
actionsFiles[filePathSplit[0]][filePathSplit[1]][filePathSplit[2]].push(fileName[0]);
}
});
}
const actionsFiles = {};
scan('images/actions', (os.platform() === 'win32' ? '\\' : '/'));
console.log(JSON.stringify(actionsFiles));
var writeStream = fs.createWriteStream('js/actions.js');
writeStream.write('SugarCube.setup.actions = ' + JSON.stringify(actionsFiles) + ';');
writeStream.end();