1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | sinclude .env
|
7 | export $(shell [ -f .env ] && sed 's/=.*//' .env)
|
8 |
|
9 |
|
10 | export PATH := ./node_modules/.bin:$(PATH)
|
11 |
|
12 |
|
13 | SHELL := /bin/bash
|
14 |
|
15 |
|
16 | GLOB = git ls-files -z $1 | tr '\0' '\n' | xargs -I {} find {} ! -type l
|
17 | NPM_INSTALL = npm prune --production=false && npm install
|
18 | BOWER_INSTALL = bower prune && bower install --config.registry.search=http://registry.origami.ft.com --config.registry.search=https://bower.herokuapp.com
|
19 | JSON_GET_VALUE = grep $1 | head -n 1 | sed 's/[," ]//g' | cut -d : -f 2
|
20 | IS_GIT_IGNORED = grep -q $(if $1, $1, $@) .gitignore
|
21 | VERSION = v1.4.11
|
22 | APP_NAME = $(shell cat package.json 2>/dev/null | $(call JSON_GET_VALUE,name))
|
23 | DONE = echo ✓ $@ done
|
24 | CONFIG_VARS = curl -fsL https://ft-next-config-vars.herokuapp.com/$1/$(call APP_NAME)$(if $2,.$2,) -H "Authorization: `heroku config:get APIKEY --app ft-next-config-vars`"
|
25 |
|
26 | #
|
27 | # META TASKS
|
28 | #
|
29 |
|
30 | .PHONY: test
|
31 |
|
32 | #
|
33 | # COMMON TASKS
|
34 | #
|
35 |
|
36 | # clean
|
37 | clea%:
|
38 | # HACK: Can't use -e option here because it's not supported by our Jenkins
|
39 | @git clean -fxd
|
40 | @$(DONE)
|
41 |
|
42 | # install
|
43 | instal%: node_modules bower_components _install_scss_lint .editorconfig .eslintrc.js .scss-lint.yml .env webpack.config.js heroku-cli
|
44 | @$(MAKE) $(foreach f, $(shell find functions/* -type d -maxdepth 0 2>/dev/null), $f/node_modules $f/bower_components)
|
45 | @$(DONE)
|
46 |
|
47 | # deploy
|
48 | deplo%: _deploy_apex
|
49 | @$(DONE)
|
50 |
|
51 | # verify
|
52 | verif%: _verify_lintspaces _verify_eslint _verify_scss_lint
|
53 | @$(DONE)
|
54 |
|
55 | # assets (includes assets-production)
|
56 | asset%:
|
57 | @if [ -e webpack.config.js ]; then webpack $(if $(findstring assets-production,$@),--bail,--dev); fi
|
58 |
|
59 | # build (includes build-production)
|
60 | buil%: public/__about.json
|
61 | @if [ -e webpack.config.js ]; then $(MAKE) $(subst build,assets,$@); fi
|
62 | @if [ -e Procfile ] && [ "$(findstring build-production,$@)" == "build-production" ]; then haikro build; fi
|
63 | @$(DONE)
|
64 |
|
65 | # watch
|
66 | watc%:
|
67 | @if [ -e webpack.config.js ]; then webpack --watch --dev; fi
|
68 | @$(DONE)
|
69 |
|
70 | #
|
71 | # SUB-TASKS
|
72 | #
|
73 |
|
74 | # INSTALL SUB-TASKS
|
75 |
|
76 | # Regular npm install
|
77 | node_modules: package.json
|
78 | @if [ -e package.json ]; then $(NPM_INSTALL) && $(DONE); fi
|
79 |
|
80 | # Regular bower install
|
81 | bower_components: bower.json
|
82 | @if [ -e bower.json ]; then $(BOWER_INSTALL) && $(DONE); fi
|
83 |
|
84 | # These tasks have been intentionally left blank
|
85 | package.json:
|
86 | bower.json:
|
87 |
|
88 | # node_modules for Lambda functions
|
89 | functions/%/node_modules:
|
90 | @cd $(dir $@) && if [ -e package.json ]; then $(NPM_INSTALL) && $(DONE); fi
|
91 |
|
92 | # bower_components for Lambda functions
|
93 | functions/%/bower_components:
|
94 | @cd $(dir $@) && if [ -e bower.json ]; then $(BOWER_INSTALL) && $(DONE); fi
|
95 |
|
96 | _install_scss_lint:
|
97 | @if [ ! -x "$(shell which scss-lint)" ] && [ "$(shell $(call GLOB,'*.scss'))" != "" ]; then gem install scss-lint -v 0.35.0 && $(DONE); fi
|
98 |
|
99 | # Manage various dot/config files if they're in the .gitignore
|
100 | .editorconfig .eslintrc.js .scss-lint.yml webpack.config.js: n.Makefile
|
101 | @if $(call IS_GIT_IGNORED); then curl -sL https://raw.githubusercontent.com/Financial-Times/n-makefile/$(VERSION)/config/$@ > $@ && $(DONE); fi
|
102 |
|
103 | ENV_MSG_CANT_GET = "Cannot get config vars for this service. Check you are added to the ft-next-config-vars service on Heroku with operate permissions. Do that here - https://docs.google.com/spreadsheets/d/1mbJQYJOgXAH2KfgKUM1Vgxq8FUIrahumb39wzsgStu0 (or ask someone to do it for you). Check that your package.json's name property is correct. Check that your project has config-vars set up in models/development.js."
|
104 | .env:
|
105 | @if $(call IS_GIT_IGNORED,*.env*) && [ -e package.json ] && [ -z $(CIRCLECI) ]; then ($(call CONFIG_VARS,development,env) > .env && perl -pi -e 's/="(.*)"/=\1/' .env && $(DONE)) || (echo $(ENV_MSG_CANT_GET) && rm .env && exit 1); fi
|
106 |
|
107 | MSG_HEROKU_CLI = "Please make sure the Heroku CLI toolbelt is installed - see https://toolbelt.heroku.com/. And make sure you are authenticated by running ‘heroku login’. If this is not an app, delete Procfile."
|
108 | heroku-cli:
|
109 | @if [ -e Procfile ]; then heroku auth:whoami &>/dev/null || (echo $(MSG_HEROKU_CLI) && exit 1); fi
|
110 |
|
111 |
|
112 | # VERIFY SUB-TASKS
|
113 |
|
114 | _verify_eslint:
|
115 | @if [ -e .eslintrc.js ]; then $(call GLOB,'*.js') | xargs eslint && $(DONE); fi
|
116 |
|
117 | _verify_lintspaces:
|
118 | @if [ -e .editorconfig ] && [ -e package.json ]; then $(call GLOB) | xargs lintspaces -e .editorconfig -i js-comments -i html-comments && $(DONE); fi
|
119 |
|
120 | _verify_scss_lint:
|
121 | # HACK: Use backticks rather than xargs because xargs swallow exit codes (everything becomes 1 and stoopidly scss-lint exits with 1 if warnings, 2 if errors)
|
122 | @if [ -e .scss-lint.yml ]; then { scss-lint -c ./.scss-lint.yml `$(call GLOB,'*.scss')`; if [ $$? -ne 0 -a $$? -ne 1 ]; then exit 1; fi; $(DONE); } fi
|
123 |
|
124 | # DEPLOY SUB-TASKS
|
125 |
|
126 | APEX_PROD_ENV_FILE = .env.prod.json
|
127 | _deploy_apex:
|
128 | @if [ -e project.json ]; then $(call CONFIG_VARS,production) > $(APEX_PROD_ENV_FILE) && apex deploy --env-file $(APEX_PROD_ENV_FILE); fi
|
129 | @if [ -e $(APEX_PROD_ENV_FILE) ]; then rm $(APEX_PROD_ENV_FILE) && $(DONE); fi
|
130 |
|
131 | npm-publis%:
|
132 | npm-prepublish --verbose
|
133 | npm publish --access public
|
134 |
|
135 | # BUILD SUB-TASKS
|
136 |
|
137 | # Only apply to Heroku apps for now
|
138 | public/__about.json:
|
139 | @if [ -e Procfile ]; then mkdir -p public && echo '{"description":"$(call APP_NAME)","support":"next.team@ft.com","supportStatus":"active","appVersion":"$(shell git rev-parse HEAD | xargs echo -n)","buildCompletionTime":"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")"}' > $@ && $(DONE); fi
|
140 |
|
141 | # UPDATE TASK
|
142 | update-tools:
|
143 | $(eval LATEST = $(shell curl -fs https://api.github.com/repos/Financial-Times/n-makefile/tags | $(call JSON_GET_VALUE,name)))
|
144 | $(if $(filter $(LATEST), $(VERSION)), $(error Cannot update n-makefile, as it is already up to date!))
|
145 | @curl -sL https://raw.githubusercontent.com/Financial-Times/n-makefile/$(LATEST)/Makefile > n.Makefile
|
146 | @sed -i "" "s/^VERSION = master/VERSION = $(LATEST)/" n.Makefile
|
147 | @read -p "Updated tools from $(VERSION) to $(LATEST). Do you want to commit and push? [y/N] " Y;\
|
148 | if [ $$Y == "y" ]; then git add n.Makefile && git commit -m "Updated tools to $(LATEST)" && git push origin HEAD; fi
|
149 | @$(DONE)
|
150 |
|
151 | # Wrapper for make deploy which prevents it running when build is a nightly
|
152 | deploy-by-day:
|
153 | ifeq ($(FT_NIGHTLY_BUILD),)
|
154 | $(MAKE) deploy
|
155 | else
|
156 | echo "Nightly build - exiting before deploy"
|
157 | endif
|
158 |
|
\ | No newline at end of file |