My impression is that Middleman uses its sitemap to decide what ‘should’ be in the final build folder. Anything that’s not explicitly represented in the sitemap will be deleted during the build process.
This makes a kind of sense, because it ensures that you don’t get stale files lying around: if you delete something from the source folder and do a build, you want the corresponding file to be removed from the build directory. However, it does mean that Middleman will cheerfully blow away anything that is built by a non-Middleman process.
There are exceptions to this. The new ‘external pipeline’ feature invokes other tools to place content in the ‘build’ folder. Middleman can’t know what files are created by these, but when the build is done, those files are present in the build folder. However, I think that may be because the external pipeline runs after Middleman has already done all its work; on the next cycle, Middleman will delete those files and the external pipeline will recreate them (I think that’s how it works).
I’ve always wanted the ability to put an entry in config.rb that says “File X should be present; don’t delete it.” As far as I know, that doesn’t exist.
My guess is that what you need to do is to somehow add items to the sitemap, so that Middleman knows that they’re supposed to be present. This may involve manipulating the Sitemap object directly from Ruby code. It’s possible, however, that there may be a way to do it in a config file. The rather terse page on The Sitemap may be helpful here. Or it may not.
Sorry I can offer only vague speculation instead of concrete information, but perhaps this will help a little.