Skip to content

Instantly share code, notes, and snippets.

@pylixonly
Created May 26, 2023 15:56
Show Gist options
  • Save pylixonly/647194bdd0000e35c9035daef8060383 to your computer and use it in GitHub Desktop.
Save pylixonly/647194bdd0000e35c9035daef8060383 to your computer and use it in GitHub Desktop.
Flattening the directory hierarchy for Plumpy
// Create a new directory called "Plumper" and dump all the files from "Plumpy" flat-ly into it
// Example: Plumpy/images/native/1.png -> Plumper/images_native_1.png
// Probably does not convert *all* but it does the most
// Packs from:
// https://github.com/acquitelol/rosiecord/tree/master/Packs/Plumpy
const fs = require("fs");
const path = require("path");
const origPath = path.join(__dirname, "Plumpy");
const dumpPath = path.join(__dirname, "Plumper");
try {
// Remove the "dump" directory if it exists
fs.rmSync(dumpPath, { recursive: true });
} finally {
// Create a new "dump" directory
fs.mkdirSync(dumpPath, { recursive: true });
}
const walk = (dir, callback) => {
fs.readdirSync(dir).forEach(f => {
const dirPath = path.join(dir, f);
const isDirectory = fs.statSync(dirPath).isDirectory();
isDirectory ? walk(dirPath, callback) : callback(path.join(dir, f));
});
}
walk(origPath, filePath => {
if (filePath.includes("Assets.car")) return; // What even is this?
// Example: Plumpy/images/native/1.png -> Plumper/images_native_1.png
const assetName = filePath
.replace(origPath + "\\", "") // Remove the original directory path
.replace(/\\/g, "_").replace(/\//g, "_") // Replace all \ and / with _
.replace(/@[0-9]+x/, "") // Remove @[number]x from the file name
.replace(/-/g, "") // Replace all '-' with nothing
// Dump the file to the dump directory
fs.copyFileSync(filePath, path.join(dumpPath, assetName));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment