Makefile 7.5 KB

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