Programatically build .js or other files

What’s the best way to programatically build a .js file ?

I have recently been in the need to add some data from the data/ folder into a myfile.js JavaScript file. So I though, easy, I just need to add the .erb extension and it will first be evaluated by that template language. That’s not the case, instead middleman drops the .js extension and produces a myfile.html instead.

EDIT: Just found that Sprockets in Rails supports that: http://guides.rubyonrails.org/asset_pipeline.html#javascript-coffeescript-and-erb

EDIT2: Tried with middleman 3.1.6 and 3.2.0

One solution in the config.rb

page "/myfile*", :layout => false, :directory_index => false
proxy "/myfile.js", "/myfile.html"

This probably only works if the script is in isolation. It also leaves the myfile.html standing.