Update generate_code_version with @ozten's suggestions.

* Move generate_code_version.js into lib.
* Simplify generate_code_version.js's logic.
* Bubble error messages up to invoking functions.
* Use generate_code_version.js when fetching '/build/code_version.js'
* Only server '/build/code_version.js' in non-production environments.