Makefile 7.8 KB

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