-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
34 lines (28 loc) · 863 Bytes
/
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
scripts := $(wildcard src/*.ts)
outputs := $(patsubst src/%.ts,dist/%.js,$(scripts))
basenames := $(patsubst src/%.ts,%,$(scripts))
.PHONY: compile
compile: $(outputs)
dist/%.js: src/%.ts
tsc --outDir dist --strict --target esnext $<
@# quick workaround to remove all export declaration in complied JS
@sed -i '' -e 's/^export //' dist/*.js
.PHONY: test
test:
npm test
.PHONY: deploy
deploy:
ifndef CF_AUTH_EMAIL
$(error CF_AUTH_EMAIL is not set)
endif
ifndef CF_AUTH_KEY
$(error CF_AUTH_KEY is not set)
endif
@$(foreach s,$(basenames),$(call upload,$(s)))
clean:
rm -rf dist/*
define upload
echo 'Uploading "$(1)"'
curl -XPUT "https://api.cloudflare.com/client/v4/user/workers/scripts/$(1)" -H 'X-Auth-Email:$(CF_AUTH_EMAIL)' -H 'X-Auth-Key:$(CF_AUTH_KEY)' -H 'Content-Type: application/javascript' --data-binary "@dist/$(1).js";
echo;
endef