The line const files = Module.FS.readdirSync(source); in your copyDirectory function is incorrect. Module.FS is used to interact with the virtual file system in WebAssembly. But you want to be reading the original file from your actual file system which is done with fs.readFileSync(source).
That is fs interacts with your actual file system Module.FS interacts with the virtual one in WebAssembly. Both have a similar API.
I’m starting to work on a branch to do generation with multiple files here but won’t have time to pick it up for a couple of weeks.