-
Notifications
You must be signed in to change notification settings - Fork 325
/
Makefile
59 lines (54 loc) · 1.8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Licensed under MIT.
# Copyright (2016) by Kevin van Zonneveld https://twitter.com/kvz
#
# https://www.npmjs.com/package/fakefile
#
# Please do not edit this file directly, but propose changed upstream instead:
# https://github.com/kvz/fakefile/blob/master/Makefile
#
# This Makefile offers convience shortcuts into any Node.js project that utilizes npm scripts.
# It functions as a wrapper around the actual listed in `package.json`
# So instead of typing:
#
# $ npm script build:assets
#
# you could also type:
#
# $ make build-assets
#
# Notice that colons (:) are replaced by dashes for Makefile compatibility.
#
# The benefits of this wrapper are:
#
# - You get to keep the the scripts package.json, which is more portable
# (Makefiles & Windows are harder to mix)
# - Offer a polite way into the project for developers coming from different
# languages (npm scripts is obviously very Node centric)
# - Profit from better autocomplete (make <TAB><TAB>) than npm currently offers.
# OSX users will have to install bash-completion
# (http://davidalger.com/development/bash-completion-on-os-x-with-brew/)
ifeq ($(shell test -e ./yarn.lock && echo -n yes),yes)
RUNNER=yarn
INSTALLER=yarn install
else
RUNNER=npm run
INSTALLER=npm install
endif
define npm_script_targets
TARGETS := $(shell \
node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}'
| grep -v -E "^install$$"
)
$$(TARGETS):
$(RUNNER) $(shell \
node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"), k);}'
| grep -E "^$(MAKECMDGOALS)\s"
| head -n1
| awk '{print $$2}'
)
.PHONY: $$(TARGETS)
endef
$(eval $(call npm_script_targets))
# These npm run scripts are available, without needing to be mentioned in `package.json`
install:
$(INSTALLER)