Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate index.js from a template #1483

Merged
merged 3 commits into from Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 31 additions & 10 deletions Makefile
Expand Up @@ -9,20 +9,24 @@ PACKAGE = asyncjs
REQUIRE_NAME = async
UGLIFY = uglifyjs
XYZ = support/xyz.sh --repo git@github.com:caolan/async.git
COPY_ES = sed -E "s/(import.+)lodash/\1lodash-es/g"

BUILDDIR = build
BUILD_ES = build-es
DIST = dist
SRC = lib/index.js
JS_INDEX = lib/index.js
SCRIPTS = ./support
JS_SRC = $(shell find lib/ -type f -name '*.js')
JS_SRC = $(shell find lib/ -type f -name '*.js') lib/index.js
INDEX_SRC = $(shell find lib/ -type f -name '*.js' | grep -v 'index') $(SCRIPTS)/index-template.js $(SCRIPTS)/aliases.json ${SCRIPTS}/generate-index.js
LINT_FILES = lib/ mocha_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
ES_MODULES = $(patsubst lib/%.js, build-es/%.js, $(JS_SRC))
CJS_MODULES = $(patsubst lib/%.js, build/%.js, $(JS_SRC))
ALIAS_ES = $(shell node $(SCRIPTS)/list-aliases.js build-es/)
ES_MODULES = $(patsubst lib/%.js, build-es/%.js, $(JS_SRC)) $(ALIAS_ES)
ALIAS_CJS = $(shell node $(SCRIPTS)/list-aliases.js build/)
CJS_MODULES = $(patsubst lib/%.js, build/%.js, $(JS_SRC)) $(ALIAS_CJS)


all: clean lint build test
Expand All @@ -34,6 +38,7 @@ 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/

Expand All @@ -45,16 +50,27 @@ build-bundle: build-modules $(UMD_BUNDLE)

build-modules: $(CJS_MODULES)

$(JS_INDEX): $(INDEX_SRC)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be added as a dependency of build-dist?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it already is, sorry.

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

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


define COMPILE_ALIAS
$A: $(shell node $(SCRIPTS)/get-alias.js $A)
mkdir -p "$$(@D)"
node $(SCRIPTS)/build/compile-module.js --file $$< --output $$@
endef
$(foreach A,$(ALIAS_CJS),$(eval $(COMPILE_ALIAS)))

$(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) $(UMD_BUNDLE) $(UMD_BUNDLE_MIN) $(DIST)/async.js $(DIST)/async.min.js $(DIST)/async.min.map
build-dist: $(DIST) $(DIST)/async.js $(DIST)/async.min.js $(DIST)/async.min.map

$(DIST):
mkdir -p $@
Expand All @@ -66,22 +82,27 @@ $(UMD_BUNDLE_MIN): $(UMD_BUNDLE)
--source-map-url async.min.map \
-o $@

$(UMD_BUNDLE_MAP): $(UMD_BUNDLE_MIN)

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

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

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

build-es: $(ES_MODULES)

$(BUILD_ES)/%.js: lib/%.js
mkdir -p "$(@D)"
sed -E "s/(import.+)lodash/\1lodash-es/g" $< > $@
$(COPY_ES) $< > $@

define COPY_ES_ALIAS
$A: $(shell node $(SCRIPTS)/get-alias.js $A)
mkdir -p "$$(@D)"
$(COPY_ES) $$< > $$@
endef
$(foreach A,$(ALIAS_ES),$(eval $(COPY_ES_ALIAS)))

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