summaryrefslogtreecommitdiff
path: root/Makefile
blob: e8ff7aab5a5fafa389605996a89e4f106d5b8c0d (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# This makefile is meant to be run on OSX/Linux.  Make sure any dist/ artifacts
# created here are checked in so people on all platforms can run npm scripts.
# This build should be run once per release.

SHELL=/bin/bash
export PATH := ./node_modules/.bin/:$(PATH):./bin/

PACKAGE = asyncjs
REQUIRE_NAME = async
UGLIFY = uglifyjs
XYZ = support/xyz.sh --repo git@github.com:caolan/async.git

BUILDDIR = build
BUILD_ES = build-es
DIST = dist
JS_INDEX = lib/index.js
SCRIPTS = ./support
JS_SRC := $(shell find lib/ -type f -name '*.js') lib/index.js
INDEX_SRC := $(filter-out $(JS_INDEX),$(JS_SRC)) $(SCRIPTS)/index-template.js $(SCRIPTS)/aliases.txt ${SCRIPTS}/generate-index.js
LINT_FILES := lib/ test/ $(shell find perf/ -maxdepth 2 -type f) $(shell find support/ -maxdepth 2 -type f -name "*.js") karma.conf.js

UMD_BUNDLE := $(BUILDDIR)/dist/async.js
UMD_BUNDLE_MIN := $(BUILDDIR)/dist/async.min.js
UMD_BUNDLE_MAP := $(BUILDDIR)/dist/async.min.map
ALIAS_ES := $(addprefix build-es/, $(addsuffix .js, $(shell cat $(SCRIPTS)/aliases.txt | cut -d ' ' -f1)))
ALIAS_CJS := $(patsubst build-es/%, build/%, $(ALIAS_ES))
ES_MODULES := $(patsubst lib/%.js, build-es/%.js, $(JS_SRC)) $(ALIAS_ES)
CJS_MODULES := $(patsubst lib/%.js, build/%.js,  $(JS_SRC)) $(ALIAS_CJS)

define ALIAS_SRC =
$(shell cat $(SCRIPTS)/aliases.txt | grep "$(basename $(notdir $(1))) " | cut -d" " -f2 )
endef

define COMPILE_ALIAS =
SRC_$(A) := lib/$(call ALIAS_SRC,$(A)).js
$(A): $$(SRC_$(A))
	mkdir -p "$$(@D)"
	node $$(SCRIPTS)/build/compile-module.js --file $$< --output $$@
endef
$(foreach A,$(ALIAS_CJS),$(eval $(COMPILE_ALIAS)))

define COPY_ES_ALIAS =
SRC_$(A) := lib/$(call ALIAS_SRC,$(A)).js
$(A): $$(SRC_$(A))
	mkdir -p "$$(@D)"
	cp $$< $$@
endef
$(foreach A,$(ALIAS_ES),$(eval $(COPY_ES_ALIAS)))

all: clean lint build test

test:
	npm test

clean:
	rm -rf $(BUILDDIR)
	rm -rf $(BUILD_ES)
	rm -rf $(DIST)
	rm -rf $(JS_INDEX)
	rm -rf tmp/ docs/ .nyc_output/ coverage/
	rm -rf perf/versions/

lint:
	eslint $(LINT_FILES)

# Compile the ES6 modules to singular bundles, and individual bundles
build-bundle: build-modules $(UMD_BUNDLE)

build-modules: $(CJS_MODULES)

$(JS_INDEX): $(INDEX_SRC)
	node $(SCRIPTS)/generate-index.js > $@

$(BUILDDIR)/%.js: lib/%.js
	mkdir -p "$(@D)"
	node $(SCRIPTS)/build/compile-module.js --file $< --output $@


$(UMD_BUNDLE): $(ES_MODULES) package.json
	mkdir -p "$(@D)"
	node $(SCRIPTS)/build/aggregate-bundle.js

# Create the minified UMD versions and copy them to dist/ for bower
build-dist: $(DIST) $(DIST)/async.js $(DIST)/async.min.js $(DIST)/async.min.map

$(DIST):
	mkdir -p $@

$(UMD_BUNDLE_MIN): $(UMD_BUNDLE)
	mkdir -p "$(@D)"
	$(UGLIFY) $< --mangle --compress \
		--source-map $(UMD_BUNDLE_MAP) \
		--source-map-url async.min.map \
		-o $@

$(DIST)/async.js: $(UMD_BUNDLE)
	cp $< $@

$(DIST)/async.min.js: $(UMD_BUNDLE_MIN)
	cp $< $@

$(DIST)/async.min.map: $(UMD_BUNDLE_MIN)
	cp $(UMD_BUNDLE_MAP) $@

build-es: $(ES_MODULES)

$(BUILD_ES)/%.js: lib/%.js
	mkdir -p "$(@D)"
	cat $< > $@

test-build: $(UMD_BUNDLE) $(UMD_BUNDLE_MIN)
	mocha support/build.test.js

build-config: $(BUILDDIR)/package.json $(BUILDDIR)/bower.json $(BUILDDIR)/README.md $(BUILDDIR)/LICENSE $(BUILDDIR)/CHANGELOG.md

build-es-config: $(BUILD_ES)/package.json $(BUILD_ES)/README.md $(BUILD_ES)/LICENSE $(BUILD_ES)/CHANGELOG.md

$(BUILDDIR)/package.json: package.json
	mkdir -p "$(@D)"
	support/sync-cjs-package.js > $@

$(BUILDDIR)/%: %
	mkdir -p "$(@D)"
	cp $< $@

$(BUILD_ES)/package.json: package.json
	mkdir -p "$(@D)"
	support/sync-es-package.js > $@

$(BUILD_ES)/README.md: README.es.md
	mkdir -p "$(@D)"
	cp $< $@

$(BUILD_ES)/%: %
	mkdir -p "$(@D)"
	cp $< $@

.PHONY: build-modules build-bundle build-dist build-es build-config build-es-config test-build

build: build-bundle build-dist build-es build-config build-es-config test-build

.PHONY: test lint build all clean

.PHONY: release-major release-minor release-patch release-prerelease
release-major release-minor release-patch release-prerelease: all
	npm i # ensure dependencies are up to date (#1158)
	git add --force $(DIST)
	git commit -am "Update built files"; true
	$(XYZ) --increment $(@:release-%=%)
	# build again to propagate the version
	$(MAKE) build-config
	$(MAKE) build-es-config
	cd build/ && npm publish
	cd build-es/ && npm publish
	$(MAKE) publish-doc

.PHONY: doc publish-doc
doc:
	jsdoc -c ./support/jsdoc/jsdoc.json
	node support/jsdoc/jsdoc-fix-html.js

publish-doc: doc
	git diff-files --quiet # fail if unstaged changes
	git diff-index --quiet HEAD # fail if uncommited changes
	npm run-script jsdoc
	gh-pages-deploy

.PHONY: list
list:
	@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'