Makefile 6.7 KB

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