Skip to content

Instantly share code, notes, and snippets.

@micklove
Created February 9, 2020 10:58
Show Gist options
  • Save micklove/c2c9cfaf74baf2e0e269007314d11ede to your computer and use it in GitHub Desktop.
Save micklove/c2c9cfaf74baf2e0e269007314d11ede to your computer and use it in GitHub Desktop.
make for executing npm scripts
# Use jq to grab the various scripts from package.json and expose them as a make targets
# Based on the awesome script from https://gist.github.com/kvz/79554af7f2d1b1379536
# (but with jq... for something different)
# can use autocomplete (make <TAB><TAB> )
TARGETS:=$(shell jq -r ".scripts | keys | .[]" package.json | sed 's/:/-/g')
define npm_script_targets
$$(TARGETS):
npm run $(subst -,:,$(MAKECMDGOALS))
.PHONY: $$(TARGETS)
endef
$(eval $(call npm_script_targets))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment