Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 -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. # 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. css: $(CSS_FILES)
  87. compile: $(JS_FILES) css public/js/libs/sharejs.js public/js/main.js public/js/ide.js
  88. @$(MAKE) compile_modules
  89. compile_full:
  90. $(COFFEE) -c -p app.coffee > app.js
  91. $(COFFEE) -o app/js -c app/coffee
  92. $(COFFEE) -o public/js -c public/coffee
  93. $(COFFEE) -o test/acceptance/js -c test/acceptance/coffee
  94. $(COFFEE) -o test/smoke/js -c test/smoke/coffee
  95. $(COFFEE) -o test/unit/js -c test/unit/coffee
  96. $(COFFEE) -o test/unit_frontend/js -c test/unit_frontend/coffee
  97. rm -f public/js/ide.js public/js/main.js # We need to generate ide.js, main.js manually later
  98. $(MAKE) $(CSS_FILES)
  99. $(MAKE) compile_modules_full
  100. $(MAKE) compile # ide.js, main.js, share.js, and anything missed
  101. compile_modules: $(MODULE_MAKEFILES)
  102. @set -e; \
  103. for dir in $(MODULE_DIRS); \
  104. do \
  105. if [ -e $$dir/Makefile ]; then \
  106. (cd $$dir && $(MAKE) compile); \
  107. fi; \
  108. if [ ! -e $$dir/Makefile ]; then \
  109. echo "No makefile found in $$dir"; \
  110. fi; \
  111. done
  112. compile_modules_full: $(MODULE_MAKEFILES)
  113. @set -e; \
  114. for dir in $(MODULE_DIRS); \
  115. do \
  116. if [ -e $$dir/Makefile ]; then \
  117. echo "Compiling $$dir in full"; \
  118. (cd $$dir && $(MAKE) compile_full); \
  119. fi; \
  120. if [ ! -e $$dir/Makefile ]; then \
  121. echo "No makefile found in $$dir"; \
  122. fi; \
  123. done
  124. $(MODULE_MAKEFILES): Makefile.module
  125. @set -e; \
  126. for makefile in $(MODULE_MAKEFILES); \
  127. do \
  128. cp Makefile.module $$makefile; \
  129. done
  130. clean: clean_app clean_frontend clean_css clean_tests clean_modules
  131. clean_app:
  132. rm -f app.js app.js.map
  133. rm -rf app/js
  134. clean_frontend:
  135. rm -rf public/js/{analytics,directives,filters,ide,main,modules,services,utils}
  136. rm -f public/js/*.{js,map}
  137. rm -f public/js/libs/sharejs.{js,map}
  138. clean_tests:
  139. rm -rf test/unit/js
  140. rm -rf test/unit_frontend/js
  141. rm -rf test/acceptance/js
  142. clean_modules:
  143. for dir in modules/*; \
  144. do \
  145. rm -f $$dir/index.js; \
  146. rm -rf $$dir/app/js; \
  147. rm -rf $$dir/test/unit/js; \
  148. rm -rf $$dir/test/acceptance/js; \
  149. done
  150. clean_css:
  151. rm -f public/stylesheets/*.css*
  152. clean_ci:
  153. docker-compose down
  154. test: test_unit test_frontend test_acceptance
  155. test_unit:
  156. npm -q run test:unit -- ${MOCHA_ARGS}
  157. test_frontend: test_clean # stop service
  158. $(MAKE) compile
  159. docker-compose ${DOCKER_COMPOSE_FLAGS} up test_frontend
  160. test_acceptance: test_acceptance_app test_acceptance_modules
  161. test_acceptance_app: test_acceptance_app_start_service test_acceptance_app_run
  162. $(MAKE) test_acceptance_app_stop_service
  163. test_acceptance_app_start_service: test_clean # stop service and clear dbs
  164. $(MAKE) compile
  165. docker-compose ${DOCKER_COMPOSE_FLAGS} up -d test_acceptance
  166. test_acceptance_app_stop_service:
  167. docker-compose ${DOCKER_COMPOSE_FLAGS} stop test_acceptance redis mongo
  168. test_acceptance_app_run:
  169. docker-compose ${DOCKER_COMPOSE_FLAGS} exec -T test_acceptance npm -q run test:acceptance -- ${MOCHA_ARGS}
  170. test_acceptance_modules:
  171. @set -e; \
  172. for dir in $(MODULE_DIRS); \
  173. do \
  174. if [ -e $$dir/test/acceptance ]; then \
  175. $(MAKE) test_acceptance_module MODULE=$$dir; \
  176. fi; \
  177. done
  178. test_acceptance_module: $(MODULE_MAKEFILES)
  179. @if [ -e $(MODULE)/test/acceptance ]; then \
  180. cd $(MODULE) && $(MAKE) test_acceptance; \
  181. fi
  182. test_clean:
  183. docker-compose ${DOCKER_COMPOSE_FLAGS} down
  184. ci:
  185. MOCHA_ARGS="--reporter tap" \
  186. $(MAKE) test
  187. lint:
  188. npm -q run lint
  189. .PHONY:
  190. all add install update test test_unit test_frontend test_acceptance \
  191. test_acceptance_start_service test_acceptance_stop_service \
  192. test_acceptance_run ci ci_clean compile clean css