Skip to content

Instantly share code, notes, and snippets.

@fictorial
Last active March 27, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fictorial/170646d403ff6be0606ed9c8025aef2b to your computer and use it in GitHub Desktop.
Save fictorial/170646d403ff6be0606ed9c8025aef2b to your computer and use it in GitHub Desktop.
Install Node.js packages from NPM for any referenced package in JavaScript under current directory
#!/bin/bash
set -eu
trap 'rm -f .all .used' 0 1 2 3 6 9 15
curl -s https://raw.githubusercontent.com/sindresorhus/builtin-modules/master/builtin-modules.json | jq -c '.[]' | sed -e 's/"//g' > .all
ack --js -h "require\('([^']+)'" --output '$1' | egrep -v '^\.' | sort -u > .used
npm i -S $(grep -Fvxf .all .used)
@fictorial
Copy link
Author

assumes you have ack, jq, and npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment