-
Notifications
You must be signed in to change notification settings - Fork 82
/
Makefile
76 lines (63 loc) · 2.69 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
####################################################################################################
## VARIABLES
####################################################################################################
# Variables - Commands
UNDERSCORE ?= $(shell PATH=./bin:$$PATH which underscore)
ECHO ?= echo # MacOS compat: using abs path for 'echo' breaks. Alternatively, this gets fixed when using bash as the shell (vs 'sh')
ECHO_E ?= $(ECHO) $(shell $(ECHO) -e foo | perl -ne '/^foo/ and print "-e"')
PERL ?= $(shell which perl)
# Variables - Colors
GREEN ?= \033[32m
YELLOW ?= \033[38;5;226m
NOCOLOR ?= \033[39;0m
####################################################################################################
## TARGETS
####################################################################################################
.PHONY: build
build: lint test readme
.PHONY: readme rme
readme rme:
@$(ECHO_E) "$(YELLOW)Generating README.md from README.template$(NOCOLOR)"
$(UNDERSCORE) template -d '{}' README.template --trace > README.md
@$(ECHO_E) "$(YELLOW)Generating Examples.md$(NOCOLOR)"
$(UNDERSCORE) examples | $(PERL) -pe '\
/^underscore (\w+)/ and $$c=$$1; \
if ($$c ne $$l) { \
print "</code></pre>\n" if $$l; \
print "### $$c\n<pre><code>"; \
$$l=$$c; \
}; \
print "</code></pre>\n" if eof' > Examples.md
.PHONY: dist
VERSION = $(shell $(UNDERSCORE) -i package.json extract version --outfmt text)
dist:
@$(ECHO_E) "$(YELLOW)Packing up tarball$(NOCOLOR)"
rm -rf package
mkdir package
rsync -a bin lib example-data Makefile README.md README.template package.json index.js TODO.md package/
tar -czvf underscore-cli-$(VERSION).tgz package/
.PHONY: publish
publish: dist
git tag -f v$(VERSION)
git push --tags
npm publish underscore-cli-$(VERSION).tgz
.PHONY: lint
lint:
@$(ECHO_E) "$(YELLOW)Running JSHint$(NOCOLOR)"
jshint bin/underscore lib/*
.PHONY: test
test:
@$(ECHO_E) "$(YELLOW)Testing Examples...$(NOCOLOR)"
@bin/underscore examples > expected.txt
@cat expected.txt | grep -v '#' | grep . | perl -pe 's/underscore/bin\/underscore/' | while read line; do \
echo "$$line"; \
bash -c "$$line" | perl -pe 's/^/# /g'; \
echo; \
done | perl -pe 's/bin\/underscore/underscore/' > actual.txt
@diff -ur expected.txt actual.txt
@$(ECHO_E) "Done."
.PHONY: bump
bump:
@git diff package.json lib | grep . -q; if [ $$? == 0 ] ; then echo "package.json has been modified"; false; else true; fi
$(UNDERSCORE) -i package.json process 'vv=data.version.split("."); vv[2]++; data.version=vv.join("."); data' -o package.json
git commit package.json -m "version bump $$($(UNDERSCORE) -i package.json process 'data.version')"