Build script fixes

I had a few problems with the build script, so I fixed them the best I could.

* use utility function `utf8_open` just to make short and less error prone lines
* made sure `package.json` was being written in utf-8 because the names with unicode messed up if it wasn't
* made `build_amd` use the already very similar function `build_browser` with an optional boolean `isAMD`
* fix the cdn build type