Makefile 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Licensed under MIT.
  2. # Copyright (2016) by Kevin van Zonneveld https://twitter.com/kvz
  3. #
  4. # This Makefile offers convience shortcuts into any Node.js project that utilizes npm scripts.
  5. # It functions as a wrapper around the actual listed in `package.json`
  6. # So instead of typing:
  7. #
  8. # $ npm script build:assets
  9. #
  10. # you could also type:
  11. #
  12. # $ make build-assets
  13. #
  14. # Notice that colons (:) are replaced by dashes for Makefile compatibility.
  15. #
  16. # The benefits of this wrapper are:
  17. #
  18. # - You get to keep the the scripts package.json, which is more portable
  19. # (Makefiles & Windows are harder to mix)
  20. # - Offer a polite way into the project for developers coming from different
  21. # languages (npm scripts is obviously very Node centric)
  22. # - Profit from better autocomplete (make <TAB><TAB>) than npm currently offers.
  23. # OSX users will have to install bash-completion
  24. # (http://davidalger.com/development/bash-completion-on-os-x-with-brew/)
  25. define npm_script_targets
  26. TARGETS := $(shell node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}')
  27. $$(TARGETS):
  28. npm run $(subst -,:,$(MAKECMDGOALS))
  29. .PHONY: $$(TARGETS)
  30. endef
  31. $(eval $(call npm_script_targets))