Generate include js

This is a first step toward #1199 and #1971.

Reviewer: It should be easiest to follow this if you look at each commit individually -- I took care to make sure the progression was natural.