rpellerin / dotfiles

My favorite *NIX dotfiles
5 stars 0 forks source link

Optimizing the npm install at the end #1

Closed jayands closed 7 years ago

jayands commented 7 years ago

I personally run Antergos (like a half-crazy person), but all of these utilities are basic Linux commands. Just out of curiosity, though, is there a reason you're not using nvm? Also, I got and adapted the idea for this code from the eslint-config-airbnb Readme.

(
  # assuming Yarn's global path is in you $PATH; otherwise use [sudo] npm install --global
  # See https://yarnpkg.com/lang/en/docs/cli/global/ for more info
  export NPMGS="eslint cloc sloc gnomon livedown peerflix castnow"
  for cfg in $NPMGS; do npm info "$cfg@latest" peerDpendencies --json |  command sed 's/[\{\},]//g ; s/: /@/g' | xargs yarn global add; done
  for cfg in $NPMGS; do yarn global add "$cfg@latest"; done
)

I've used it for babel-* code, as well as eslint and/or tslint args:

for cfg in core preset-stage-0 preset-env plugin-lodash plugin-istanbul eslint; do echo "babel-$cfg"| xargs yarn add --dev; done; yarn add --dev eslint eslint-config-standard stylelint stylelint-config-standard

It lends itself to duplication code quite well; though I'd suppose the "more DRY" way to write that would be:

(
  for tool in core eslint; do echo "babel-$tool"| xargs yarn add --dev; done; for preset in stage-0 env; do echo "babel-preset-$preset"| xargs yarn add --dev; done; for plugin in lodash istanbul; do echo "babel-plugin-$plugin"| xargs yarn add --dev; done
  for lint in eslint stylelint; do echo "$lint $lint-config-standard"| xargs yarn add --dev; done; 
)

but that's beside the point.

rpellerin commented 7 years ago

There is absolutely no reason I'm not using nvm. I don't program much on my personal laptop thus no need to switch beetween versions. Thanks for sharing your tips!