Skip to content

Instantly share code, notes, and snippets.

@zarkzork
Created September 12, 2018 07:07
Show Gist options
  • Save zarkzork/3837bbd3422c50b03d8342159d0377c3 to your computer and use it in GitHub Desktop.
Save zarkzork/3837bbd3422c50b03d8342159d0377c3 to your computer and use it in GitHub Desktop.
js_of_ocaml Makefile
SECURE_CONFIG_FILE=.env
SECURE_ENV_VARIABLES=${shell cat $(SECURE_CONFIG_FILE)}
BUILD_DIR=_build
TEST_BUILD_DIR=_build_test
COMPILE_INCLUDE_DIR_FLAGS=-I source/std -I source/actions -I source/storages -I source/services -I source/types
COMPILE_INCLUDE_TEST_DIR_FLAGS=-I test/examples -I test/types -I test/storages -I test/actions -I test/services -I test/std
dist/handler.js: node_modules source/*.ml $(wildcard source/*.mli) source/std/*.ml source/std/*.mli source/actions/*.ml source/actions/*.mli
ocamlbuild -no-links -use-ocamlfind -X $(TEST_BUILD_DIR) $(COMPILE_INCLUDE_DIR_FLAGS) -no-sanitize -no-hygiene source/main.byte
js_of_ocaml $(BUILD_DIR)/source/main.byte
cp $(BUILD_DIR)/source/main.js dist/handler.js
node_modules: package.json
npm install
compile_tests: node_modules source/*.ml $(wildcard source/*.mli) source/std/*.ml source/std/*.mli source/actions/*.ml source/actions/*.mli
ocamlbuild -tags "debug","traverse" -r -cflag "-g" -build-dir $(TEST_BUILD_DIR) -X $(BUILD_DIR) -package js_of_ocaml -use-ocamlfind -no-sanitize -no-hygiene -I 'source/' ${COMPILE_INCLUDE_DIR_FLAGS} -I 'test/' ${COMPILE_INCLUDE_TEST_DIR_FLAGS} test.byte
js_of_ocaml --source-map $(TEST_BUILD_DIR)/test/test.byte -o $(TEST_BUILD_DIR)/test/test.js
clear_tests:
rm -rf $(TEST_BUILD_DIR) || true
migrate:
${SECURE_ENV_VARIABLES} npm run-script migrate
.PHONY: run_tests
run_tests: compile_tests
${SECURE_ENV_VARIABLES} ./node_modules/.bin/mocha -t 5000 $(TEST_BUILD_DIR)/test/test.js
.PHONY: deploy
deploy: dist/handler.js
serverless deploy
.PHONY: test
test:
serverless invoke -f hello -p event.json
.PHONY: debug_tests
debug_tests: clear_tests compile_tests
${SECURE_ENV_VARIABLES} ./node_modules/.bin/mocha debug -t 5000 $(TEST_BUILD_DIR)/test/test.js
.PHONY: debug_break_tests
debug_break_tests: clear_tests compile_tests
${SECURE_ENV_VARIABLES} node-debug --debug-brk ./node_modules/.bin/mocha -- --require source-map-support/register -t 5000 $(TEST_BUILD_DIR)/test/test.js
.PHONY: test_local
test_local: dist/handler.js
${SECURE_ENV_VARIABLES} node test.js
.PHONY: clear_tests migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment