angular-translate/angular-translate — pull request #708 by NickHeiner (2014-09-04 17:16:45+00:00)
Title: Fix npm install

This is related to #255.

Right now, `npm install` is broken for people trying to use npm to pull this in as a dependency who do not have `bower` globally installed. Here is the error we get:

```
nick.heiner:/tmp/angular-translate-fun $ npm install angular-translate

> angular-translate@2.2.1 postinstall /private/tmp/angular-translate-fun/node_modules/angular-translate
> bower install

sh: bower: command not found
npm ERR! angular-translate@2.2.1 postinstall: `bower install`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the angular-translate@2.2.1 postinstall script.
npm ERR! This is most likely a problem with the angular-translate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! bower install
npm ERR! You can get their info via:
npm ERR! npm owner ls angular-translate
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/Users/nick.heiner/.npm-global/bin/npm" "install" "angular-translate"
npm ERR! cwd /private/tmp/angular-translate-fun
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.20
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/tmp/angular-translate-fun/npm-debug.log
npm ERR! not ok code 0
```

The reason for this is that `bower` is a dev dependency of this module, but when I install it as someone who wants to use `angular-translate` in my own code, I won't get dev dependencies, so the `bower` command is not available.

Moreover, as a consumer of this module, I don't want the bower dependencies anyway - I just want the built `dist` file. The npm convention is to do any build step before publishing, which eliminates all sorts of pain around making your build step work consistently on every user's machine. (See the section entitled "NOTE: INSTALL SCRIPTS ARE AN ANTIPATTERN" in [these npm docs](https://www.npmjs.org/doc/misc/npm-scripts.html).)

We do want to do `bower install` before running tests and building, so I've added it in the npm `pretest` and `prepublish` commands. That way, when you run `npm test` and `npm publish`, the bower dependencies will automatically be taken care of. (Don't worry about running `bower install` on every test - if bower sees that the dependencies are already installed, it exits quickly and quietly.)

Additionally, I've added `grunt build` to the `prepublish` step, so that every time you do `npm publish`, the `dist` directory is up to date. I've also changed the `main` field to point to `dist/angular-translate.js`, so when someone pulls this module in with `browserify`, it will know which file to use. (People are free to manually pull in the other dist files if they want, but `dist/angular-translate.js` seems like the sensible default.)

I also did some other minor cleanup that is beyond the scope of what is strictly necessary to get this module working in npm. I will try to explain line-by-line what I'm doing. Feel free to tell me you don't want it.

I did a bunch of different commits in the hopes that would make my progression easier to follow, but I can certainly squash merge them if you'd like. (I can either do that now, or if/when this is ready to merge.)

Thanks!