Fixed so Pack handling works recursively for deep compendium folders (#47)

This commit is contained in:
WBHarry 2025-05-25 01:33:07 +02:00 committed by GitHub
parent ad1e968888
commit 6672fa467c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
355 changed files with 16040 additions and 5064 deletions

View file

@ -5,11 +5,13 @@ import path from 'path';
const MODULE_ID = process.cwd();
const yaml = false;
const packs = await fs.readdir('./packs');
// const packs = await fs.readdir('./packs');
const packs = await deepGetDirectories('./packs');
console.log(packs);
for (const pack of packs) {
if (pack === '.gitattributes') continue;
console.log('Unpacking ' + pack);
const directory = `./src/packs/${pack}`;
const directory = `./src/${pack}`;
try {
for (const file of await fs.readdir(directory)) {
await fs.unlink(path.join(directory, file));
@ -18,7 +20,7 @@ for (const pack of packs) {
if (error.code === 'ENOENT') console.log('No files inside of ' + pack);
else console.log(error);
}
await extractPack(`${MODULE_ID}/packs/${pack}`, `${MODULE_ID}/src/packs/${pack}`, {
await extractPack(`${MODULE_ID}/${pack}`, `${MODULE_ID}/src/${pack}`, {
yaml,
transformName
});
@ -34,3 +36,23 @@ function transformName(doc) {
return `${doc.name ? `${prefix}_${safeFileName}_${doc._id}` : doc._id}.${yaml ? 'yml' : 'json'}`;
}
async function deepGetDirectories(distPath) {
const dirr = await fs.readdir(distPath);
const dirrsWithSub = [];
for (let file of dirr) {
const stat = await fs.stat(distPath + '/' + file);
if (stat.isDirectory()) {
if (file === 'packs') continue;
const deeper = await deepGetDirectories(distPath + '/' + file);
if (deeper.length > 0) {
dirrsWithSub.push(...deeper);
} else {
dirrsWithSub.push(distPath + '/' + file);
}
}
}
return dirrsWithSub;
}