Makefile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. DOCKER_COMPOSE_FLAGS ?= -f docker-compose.yml
  2. BUILD_NUMBER ?= local
  3. BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
  4. PROJECT_NAME = web
  5. MODULE_DIRS := $(shell find modules -mindepth 1 -maxdepth 1 -type d -not -name '.git' )
  6. MODULE_MAKEFILES := $(MODULE_DIRS:=/Makefile)
  7. COFFEE := node_modules/.bin/coffee $(COFFEE_OPTIONS)
  8. BABEL := node_modules/.bin/babel
  9. GRUNT := node_modules/.bin/grunt
  10. APP_COFFEE_FILES := $(shell find app/coffee -name '*.coffee')
  11. FRONT_END_SRC_FILES := $(shell find public/src -name '*.js')
  12. TEST_COFFEE_FILES := $(shell find test/*/coffee -name '*.coffee')
  13. TEST_SRC_FILES := $(shell find test/*/src -name '*.js')
  14. MODULE_MAIN_SRC_FILES := $(shell find modules -type f -wholename '*main/index.js')
  15. MODULE_IDE_SRC_FILES := $(shell find modules -type f -wholename '*ide/index.js')
  16. COFFEE_FILES := app.coffee $(APP_COFFEE_FILES) $(FRONT_END_COFFEE_FILES) $(TEST_COFFEE_FILES)
  17. SRC_FILES := $(FRONT_END_SRC_FILES) $(TEST_SRC_FILES)
  18. JS_FILES := $(subst coffee,js,$(COFFEE_FILES))
  19. OUTPUT_SRC_FILES := $(subst src,js,$(SRC_FILES))
  20. LESS_FILES := $(shell find public/stylesheets -name '*.less')
  21. CSS_FILES := public/stylesheets/style.css public/stylesheets/ol-style.css public/stylesheets/ol-light-style.css
  22. # The automatic variable $(@D) is the target directory name
  23. app.js: app.coffee
  24. $(COFFEE) --compile -o $(@D) $<
  25. app/js/%.js: app/coffee/%.coffee
  26. @mkdir -p $(@D)
  27. $(COFFEE) --compile -o $(@D) $<
  28. public/js/%.js: public/src/%.js
  29. @mkdir -p $(@D)
  30. $(BABEL) $< --out-file $@
  31. test/unit/js/%.js: test/unit/coffee/%.coffee
  32. @mkdir -p $(@D)
  33. $(COFFEE) --compile -o $(@D) $<
  34. test/acceptance/js/%.js: test/acceptance/coffee/%.coffee
  35. @mkdir -p $(@D)
  36. $(COFFEE) --compile -o $(@D) $<
  37. test/unit_frontend/js/%.js: test/unit_frontend/src/%.js
  38. @mkdir -p $(@D)
  39. $(BABEL) $< --out-file $@
  40. test/smoke/js/%.js: test/smoke/coffee/%.coffee
  41. @mkdir -p $(@D)
  42. $(COFFEE) --compile -o $(@D) $<
  43. public/js/ide.js: public/src/ide.js $(MODULE_IDE_SRC_FILES)
  44. @echo Compiling and injecting module includes into public/js/ide.js
  45. @INCLUDES=""; \
  46. for dir in modules/*; \
  47. do \
  48. MODULE=`echo $$dir | cut -d/ -f2`; \
  49. if [ -e $$dir/public/src/ide/index.js ]; then \
  50. INCLUDES="\"ide/$$MODULE/index\",$$INCLUDES"; \
  51. fi \
  52. done; \
  53. INCLUDES=$${INCLUDES%?}; \
  54. $(BABEL) $< | \
  55. sed -e s=\'__IDE_CLIENTSIDE_INCLUDES__\'=$$INCLUDES= \
  56. > $@
  57. public/js/main.js: public/src/main.js $(MODULE_MAIN_SRC_FILES)
  58. @echo Compiling and injecting module includes into public/js/main.js
  59. @INCLUDES=""; \
  60. for dir in modules/*; \
  61. do \
  62. MODULE=`echo $$dir | cut -d/ -f2`; \
  63. if [ -e $$dir/public/src/main/index.js ]; then \
  64. INCLUDES="\"main/$$MODULE/index\",$$INCLUDES"; \
  65. fi \
  66. done; \
  67. INCLUDES=$${INCLUDES%?}; \
  68. $(BABEL) $< | \
  69. sed -e s=\'__MAIN_CLIENTSIDE_INCLUDES__\'=$$INCLUDES= \
  70. > $@
  71. $(CSS_FILES): $(LESS_FILES)
  72. $(GRUNT) compile:css
  73. minify: $(CSS_FILES) $(JS_FILES) $(OUTPUT_SRC_FILES)
  74. $(GRUNT) compile:minify
  75. $(MAKE) minify_es
  76. minify_es:
  77. npm -q run webpack:production
  78. css: $(CSS_FILES)
  79. compile: $(JS_FILES) $(OUTPUT_SRC_FILES) css public/js/main.js public/js/ide.js
  80. @$(MAKE) compile_modules
  81. compile_full:
  82. $(COFFEE) -c -p app.coffee > app.js
  83. $(COFFEE) -o app/js -c app/coffee
  84. $(BABEL) public/src --out-dir public/js
  85. $(COFFEE) -o test/acceptance/js -c test/acceptance/coffee
  86. $(COFFEE) -o test/smoke/js -c test/smoke/coffee
  87. $(COFFEE) -o test/unit/js -c test/unit/coffee
  88. $(BABEL) test/unit_frontend/src --out-dir test/unit_frontend/js
  89. rm -f public/js/ide.js public/js/main.js # We need to generate ide.js, main.js manually later
  90. $(MAKE) $(CSS_FILES)
  91. $(MAKE) compile_modules_full
  92. $(MAKE) compile # ide.js, main.js, share.js, and anything missed
  93. compile_modules: $(MODULE_MAKEFILES)
  94. @set -e; \
  95. for dir in $(MODULE_DIRS); \
  96. do \
  97. if [ -e $$dir/Makefile ]; then \
  98. (cd $$dir && $(MAKE) compile); \
  99. fi; \
  100. if [ ! -e $$dir/Makefile ]; then \
  101. echo "No makefile found in $$dir"; \
  102. fi; \
  103. done
  104. compile_modules_full: $(MODULE_MAKEFILES)
  105. @set -e; \
  106. for dir in $(MODULE_DIRS); \
  107. do \
  108. if [ -e $$dir/Makefile ]; then \
  109. echo "Compiling $$dir in full"; \
  110. (cd $$dir && $(MAKE) compile_full); \
  111. fi; \
  112. if [ ! -e $$dir/Makefile ]; then \
  113. echo "No makefile found in $$dir"; \
  114. fi; \
  115. done
  116. $(MODULE_MAKEFILES): Makefile.module
  117. @set -e; \
  118. for makefile in $(MODULE_MAKEFILES); \
  119. do \
  120. cp Makefile.module $$makefile; \
  121. done
  122. clean: clean_app clean_frontend clean_css clean_tests clean_modules
  123. clean_app:
  124. rm -f app.js app.js.map
  125. rm -rf app/js
  126. clean_frontend:
  127. rm -rf public/js/{analytics,directives,es,filters,ide,main,modules,services,utils}
  128. rm -f public/js/*.{js,map}
  129. clean_tests:
  130. rm -rf test/unit/js
  131. rm -rf test/unit_frontend/js
  132. rm -rf test/acceptance/js
  133. clean_modules:
  134. for dir in modules/*; \
  135. do \
  136. rm -f $$dir/index.js; \
  137. rm -rf $$dir/app/js; \
  138. rm -rf $$dir/test/unit/js; \
  139. rm -rf $$dir/test/acceptance/js; \
  140. done
  141. clean_css:
  142. rm -f public/stylesheets/*.css*
  143. clean_ci:
  144. docker-compose down -v -t 0
  145. test: test_unit test_frontend test_acceptance
  146. test_unit:
  147. npm -q run test:unit -- ${MOCHA_ARGS}
  148. test_unit_app:
  149. npm -q run test:unit:app -- ${MOCHA_ARGS}
  150. test_frontend: test_clean # stop service
  151. $(MAKE) compile
  152. docker-compose ${DOCKER_COMPOSE_FLAGS} up --exit-code-from test_frontend --abort-on-container-exit test_frontend
  153. test_acceptance: test_acceptance_app test_acceptance_modules
  154. test_acceptance_app:
  155. @set -e; \
  156. $(MAKE) test_acceptance_app_start_service; \
  157. $(MAKE) test_acceptance_app_run; \
  158. $(MAKE) test_acceptance_app_stop_service;
  159. test_acceptance_app_start_service: test_clean # stop service and clear dbs
  160. $(MAKE) compile
  161. docker-compose ${DOCKER_COMPOSE_FLAGS} up -d test_acceptance
  162. test_acceptance_app_stop_service:
  163. docker-compose ${DOCKER_COMPOSE_FLAGS} stop -t 0 test_acceptance redis mongo
  164. test_acceptance_app_run:
  165. @docker-compose ${DOCKER_COMPOSE_FLAGS} exec -T test_acceptance npm -q run test:acceptance -- ${MOCHA_ARGS}; \
  166. result=$$?; \
  167. if [ $$result -eq 137 ]; then \
  168. docker-compose logs --tail=50 test_acceptance; \
  169. echo "\nOh dear, it looks like the web process crashed! Some logs are above, but to see them all, run:\n\n\tdocker-compose logs test_acceptance\n"; \
  170. fi; \
  171. exit $$result
  172. test_acceptance_modules:
  173. @set -e; \
  174. for dir in $(MODULE_DIRS); \
  175. do \
  176. if [ -e $$dir/test/acceptance ]; then \
  177. $(MAKE) test_acceptance_module MODULE=$$dir; \
  178. fi; \
  179. done
  180. test_acceptance_module: $(MODULE_MAKEFILES)
  181. @if [ -e $(MODULE)/test/acceptance ]; then \
  182. cd $(MODULE) && $(MAKE) test_acceptance; \
  183. fi
  184. test_clean:
  185. docker-compose ${DOCKER_COMPOSE_FLAGS} down -v -t 0
  186. ci:
  187. MOCHA_ARGS="--reporter tap" \
  188. $(MAKE) test
  189. format:
  190. npm -q run format
  191. lint:
  192. npm -q run lint
  193. .PHONY:
  194. all add install update test test_unit test_frontend test_acceptance \
  195. test_acceptance_start_service test_acceptance_stop_service \
  196. test_acceptance_run ci ci_clean compile clean css