Makefile 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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_css_full:
  113. $(MAKE) css_full
  114. compile_modules: $(MODULE_MAKEFILES)
  115. @set -e; \
  116. for dir in $(MODULE_DIRS); \
  117. do \
  118. if [ -e $$dir/Makefile ]; then \
  119. (cd $$dir && $(MAKE) compile); \
  120. fi; \
  121. if [ ! -e $$dir/Makefile ]; then \
  122. echo "No makefile found in $$dir"; \
  123. fi; \
  124. done
  125. compile_modules_full: $(MODULE_MAKEFILES)
  126. @set -e; \
  127. for dir in $(MODULE_DIRS); \
  128. do \
  129. if [ -e $$dir/Makefile ]; then \
  130. echo "Compiling $$dir in full"; \
  131. (cd $$dir && $(MAKE) compile_full); \
  132. fi; \
  133. if [ ! -e $$dir/Makefile ]; then \
  134. echo "No makefile found in $$dir"; \
  135. fi; \
  136. done
  137. $(MODULE_MAKEFILES): Makefile.module
  138. @set -e; \
  139. for makefile in $(MODULE_MAKEFILES); \
  140. do \
  141. cp Makefile.module $$makefile; \
  142. done
  143. clean: clean_app clean_frontend clean_css clean_tests clean_modules
  144. clean_app:
  145. rm -f app.js app.js.map
  146. rm -rf app/js
  147. clean_frontend:
  148. rm -rf public/js/{analytics,directives,es,filters,ide,main,modules,services,utils}
  149. rm -f public/js/*.{js,map}
  150. clean_tests:
  151. rm -rf test/unit/js
  152. rm -rf test/unit_frontend/js
  153. rm -rf test/acceptance/js
  154. clean_modules:
  155. for dir in modules/*; \
  156. do \
  157. rm -f $$dir/index.js; \
  158. rm -rf $$dir/app/js; \
  159. rm -rf $$dir/test/unit/js; \
  160. rm -rf $$dir/test/acceptance/js; \
  161. done
  162. clean_css:
  163. rm -f public/stylesheets/*.css*
  164. clean_ci:
  165. docker-compose down -v -t 0
  166. test: test_unit test_frontend test_acceptance
  167. test_unit:
  168. npm -q run test:unit -- ${MOCHA_ARGS}
  169. test_unit_app:
  170. npm -q run test:unit:app -- ${MOCHA_ARGS}
  171. test_frontend: test_clean # stop service
  172. $(MAKE) compile
  173. docker-compose ${DOCKER_COMPOSE_FLAGS} up --exit-code-from test_frontend --abort-on-container-exit test_frontend
  174. test_acceptance: compile test_acceptance_app_run test_acceptance_modules_run
  175. test_acceptance_app: compile test_acceptance_app_run
  176. test_acceptance_module: compile test_acceptance_module_run
  177. test_acceptance_app_run: test_clean
  178. @set -e; \
  179. docker-compose ${DOCKER_COMPOSE_FLAGS} run --rm test_acceptance npm -q run test:acceptance:run_dir -- ${MOCHA_ARGS} test/acceptance/js
  180. test_acceptance_modules_run:
  181. @set -e; \
  182. for dir in $(MODULE_DIRS); \
  183. do \
  184. if [ -e $$dir/test/acceptance ]; then \
  185. $(MAKE) test_acceptance_module_run MODULE=$$dir; \
  186. fi; \
  187. done
  188. test_acceptance_module_run: $(MODULE_MAKEFILES) test_clean
  189. @if [ -e $(MODULE)/test/acceptance ]; then \
  190. cd $(MODULE) && $(MAKE) test_acceptance; \
  191. fi
  192. test_clean:
  193. docker-compose ${DOCKER_COMPOSE_FLAGS} down -v -t 0
  194. ci:
  195. MOCHA_ARGS="--reporter tap" \
  196. $(MAKE) test
  197. format:
  198. npm -q run format
  199. format_fix:
  200. npm -q run format:fix
  201. lint:
  202. npm -q run lint
  203. .PHONY:
  204. all add install update test test_unit test_frontend test_acceptance \
  205. test_acceptance_start_service test_acceptance_stop_service \
  206. test_acceptance_run ci ci_clean compile clean css