Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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
  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 -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
  27. app.js: app.coffee
  28. $(COFFEE) --compile --print $< > $@
  29. app/js/%.js: app/coffee/%.coffee
  30. @mkdir -p $(dir $@)
  31. $(COFFEE) --compile --print $< > $@
  32. public/js/%.js: public/coffee/%.coffee
  33. @mkdir -p $(dir $@)
  34. $(COFFEE) --output $(dir $@) --map --compile $<
  35. test/unit/js/%.js: test/unit/coffee/%.coffee
  36. @mkdir -p $(dir $@)
  37. $(COFFEE) --compile --print $< > $@
  38. test/acceptance/js/%.js: test/acceptance/coffee/%.coffee
  39. @mkdir -p $(dir $@)
  40. $(COFFEE) --compile --print $< > $@
  41. test/unit_frontend/js/%.js: test/unit_frontend/coffee/%.coffee
  42. @mkdir -p $(dir $@)
  43. $(COFFEE) --compile --print $< > $@
  44. test/smoke/js/%.js: test/smoke/coffee/%.coffee
  45. @mkdir -p $(dir $@)
  46. $(COFFEE) --compile --print $< > $@
  47. public/js/libs/sharejs.js: $(SHAREJS_COFFEE_FILES)
  48. @echo "Compiling public/js/libs/sharejs.js"
  49. @echo 'define(["ace/ace"], function() {' > public/js/libs/sharejs.js
  50. @cat $(SHAREJS_COFFEE_FILES) | $(COFFEE) --stdio --print >> public/js/libs/sharejs.js
  51. @echo "" >> public/js/libs/sharejs.js
  52. @echo "return window.sharejs; });" >> public/js/libs/sharejs.js
  53. public/js/ide.js: public/coffee/ide.coffee $(MODULE_IDE_COFFEE_FILES)
  54. @echo Compiling and injecting module includes into public/js/ide.js
  55. @INCLUDES=""; \
  56. for dir in modules/*; \
  57. do \
  58. MODULE=`echo $$dir | cut -d/ -f2`; \
  59. if [ -e $$dir/public/coffee/ide/index.coffee ]; then \
  60. INCLUDES="\"ide/$$MODULE/index\",$$INCLUDES"; \
  61. fi \
  62. done; \
  63. INCLUDES=$${INCLUDES%?}; \
  64. $(COFFEE) --compile --print $< | \
  65. sed -e s=\"__IDE_CLIENTSIDE_INCLUDES__\"=$$INCLUDES= \
  66. > $@
  67. public/js/main.js: public/coffee/main.coffee $(MODULE_MAIN_COFFEE_FILES)
  68. @echo Compiling and injecting module includes into public/js/main.js
  69. @INCLUDES=""; \
  70. for dir in modules/*; \
  71. do \
  72. MODULE=`echo $$dir | cut -d/ -f2`; \
  73. if [ -e $$dir/public/coffee/main/index.coffee ]; then \
  74. INCLUDES="\"main/$$MODULE/index\",$$INCLUDES"; \
  75. fi \
  76. done; \
  77. INCLUDES=$${INCLUDES%?}; \
  78. $(COFFEE) --compile --print $< | \
  79. sed -e s=\"__MAIN_CLIENTSIDE_INCLUDES__\"=$$INCLUDES= \
  80. > $@
  81. $(CSS_FILES): $(LESS_FILES)
  82. $(GRUNT) compile:css
  83. minify: $(CSS_FILES) $(JS_FILES)
  84. $(GRUNT) compile:minify
  85. css: $(CSS_FILES)
  86. compile: $(JS_FILES) css public/js/libs/sharejs.js public/js/main.js public/js/ide.js
  87. @$(MAKE) compile_modules
  88. compile_full:
  89. $(COFFEE) -c -p app.coffee > app.js
  90. $(COFFEE) -o app/js -c app/coffee
  91. $(COFFEE) -o public/js -c public/coffee
  92. $(COFFEE) -o test/acceptance/js -c test/acceptance/coffee
  93. $(COFFEE) -o test/smoke/js -c test/smoke/coffee
  94. $(COFFEE) -o test/unit/js -c test/unit/coffee
  95. $(COFFEE) -o test/unit_frontend/js -c test/unit_frontend/coffee
  96. rm -f public/js/ide.js public/js/main.js # We need to generate ide.js, main.js manually later
  97. $(MAKE) $(CSS_FILES)
  98. $(MAKE) compile_modules_full
  99. $(MAKE) compile # ide.js, main.js, share.js, and anything missed
  100. compile_modules: $(MODULE_MAKEFILES)
  101. @set -e; \
  102. for dir in $(MODULE_DIRS); \
  103. do \
  104. if [ -e $$dir/Makefile ]; then \
  105. (cd $$dir && $(MAKE) compile); \
  106. fi; \
  107. if [ ! -e $$dir/Makefile ]; then \
  108. echo "No makefile found in $$dir"; \
  109. fi; \
  110. done
  111. compile_modules_full: $(MODULE_MAKEFILES)
  112. @set -e; \
  113. for dir in $(MODULE_DIRS); \
  114. do \
  115. if [ -e $$dir/Makefile ]; then \
  116. echo "Compiling $$dir in full"; \
  117. (cd $$dir && $(MAKE) compile_full); \
  118. fi; \
  119. if [ ! -e $$dir/Makefile ]; then \
  120. echo "No makefile found in $$dir"; \
  121. fi; \
  122. done
  123. $(MODULE_MAKEFILES): Makefile.module
  124. @set -e; \
  125. for makefile in $(MODULE_MAKEFILES); \
  126. do \
  127. cp Makefile.module $$makefile; \
  128. done
  129. clean: clean_app clean_frontend clean_css clean_tests clean_modules
  130. clean_app:
  131. rm -f app.js
  132. rm -rf app/js
  133. clean_frontend:
  134. rm -rf public/js/{analytics,directives,filters,ide,main,modules,services,utils}
  135. rm -f public/js/*.js
  136. rm -f public/js/libs/sharejs.js
  137. clean_tests:
  138. rm -rf test/unit/js
  139. rm -rf test/acceptance/js
  140. clean_modules:
  141. for dir in modules/*; \
  142. do \
  143. rm -f $$dir/index.js; \
  144. rm -rf $$dir/app/js; \
  145. rm -rf $$dir/test/unit/js; \
  146. rm -rf $$dir/test/acceptance/js; \
  147. done
  148. clean_css:
  149. rm -f public/stylesheets/*.css*
  150. clean_ci:
  151. docker-compose down
  152. test: test_unit test_frontend test_acceptance
  153. test_unit:
  154. npm -q run test:unit -- ${MOCHA_ARGS}
  155. test_frontend:
  156. npm -q run test:frontend -- ${MOCHA_ARGS}
  157. test_acceptance: test_acceptance_app test_acceptance_modules
  158. test_acceptance_app: test_acceptance_app_start_service test_acceptance_app_run
  159. $(MAKE) test_acceptance_app_stop_service
  160. test_acceptance_app_start_service: test_clean # stop service and clear dbs
  161. $(MAKE) compile
  162. docker-compose ${DOCKER_COMPOSE_FLAGS} up -d test_acceptance
  163. test_acceptance_app_stop_service:
  164. docker-compose ${DOCKER_COMPOSE_FLAGS} stop test_acceptance redis mongo
  165. test_acceptance_app_run:
  166. docker-compose ${DOCKER_COMPOSE_FLAGS} exec -T test_acceptance npm -q run test:acceptance -- ${MOCHA_ARGS}
  167. test_acceptance_modules:
  168. @set -e; \
  169. for dir in $(MODULE_DIRS); \
  170. do \
  171. if [ -e $$dir/test/acceptance ]; then \
  172. $(MAKE) test_acceptance_module MODULE=$$dir; \
  173. fi; \
  174. done
  175. test_acceptance_module: $(MODULE_MAKEFILES)
  176. @if [ -e $(MODULE)/test/acceptance ]; then \
  177. cd $(MODULE) && $(MAKE) test_acceptance; \
  178. fi
  179. test_clean:
  180. docker-compose ${DOCKER_COMPOSE_FLAGS} down
  181. ci:
  182. MOCHA_ARGS="--reporter tap" \
  183. $(MAKE) test
  184. .PHONY:
  185. all add install update test test_unit test_frontend test_acceptance \
  186. test_acceptance_start_service test_acceptance_stop_service \
  187. test_acceptance_run ci ci_clean compile clean css