Makefile 7.7 KB

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