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