UNPKG

5.38 kBPlain TextView Raw
1# Warning, don't edit this file, it's maintained on GitHub and updated by running `make update-tools`
2# Submit PR's here: https://www.github.com/Financial-Times/n-makefile
3
4
5# ./node_modules/.bin on the PATH
6export PATH := ./node_modules/.bin:$(PATH)
7
8# Use bash not sh
9SHELL := /bin/bash
10
11#
12# META TASKS
13#
14
15.PHONY: test
16
17#
18# COMMON TASKS
19#
20
21# clean
22clea%:
23# HACK: Can't use -e option here because it's not supported by our Jenkins
24 @git clean -fxd
25 @$(DONE)
26
27# install
28instal%: node_modules bower_components _install_scss_lint .editorconfig .eslintrc.js .scss-lint.yml .env webpack.config.js
29 @$(MAKE) $(foreach f, $(shell find functions/* -type d -maxdepth 0 2>/dev/null), $f/node_modules)
30 @$(DONE)
31
32# deploy
33deplo%: _deploy_apex
34 @$(DONE)
35
36# verify
37verif%: _verify_lintspaces _verify_eslint _verify_scss_lint
38 @$(DONE)
39
40# build (includes build-production)
41buil%: public/__about.json
42 @if [ -e webpack.config.js ]; then webpack $(if $(findstring build-production,$@),--bail,--dev); fi
43 @if [ -e Procfile ] && [ "$(findstring build-production,$@)" == "build-production" ]; then haikro build; fi
44 @$(DONE)
45
46# watch
47watc%:
48 @if [ -e webpack.config.js ]; then webpack --watch --dev; fi
49 @$(DONE)
50
51#
52# SUB-TASKS
53#
54
55# INSTALL SUB-TASKS
56
57# Regular npm install
58node_modules: package.json
59 @if [ -e package.json ]; then $(NPM_INSTALL) && $(DONE); fi
60
61# Regular bower install
62bower_components: bower.json
63 @if [ -e bower.json ]; then bower install --config.registry.search=http://registry.origami.ft.com --config.registry.search=https://bower.herokuapp.com && $(DONE); fi
64
65# These tasks have been intentionally left blank
66package.json:
67bower.json:
68
69# node_modules for Lambda functions
70functions/%/node_modules:
71 @cd $(dir $@) && if [ -e package.json ]; then $(NPM_INSTALL) && $(DONE); fi
72
73_install_scss_lint:
74 @if [ ! -x "$(shell which scss-lint)" ] && [ "$(shell $(call GLOB,'*.scss'))" != "" ]; then gem install scss-lint -v 0.35.0 && $(DONE); fi
75
76# Manage various dot/config files if they're in the .gitignore
77.editorconfig .eslintrc.js .scss-lint.yml webpack.config.js: n.Makefile
78 @if $(call IS_GIT_IGNORED); then curl -sL https://raw.githubusercontent.com/Financial-Times/n-makefile/$(VERSION)/config/$@ > $@ && $(DONE); fi
79
80.env:
81 @if $(call IS_GIT_IGNORED); then heroku auth:whoami &>/dev/null || (echo Please make sure the Heroku CLI is installed and authenticated by running ‘heroku auth:token’. See more https://toolbelt.heroku.com/. && exit 1); fi
82 @if $(call IS_GIT_IGNORED) && [ -e package.json ]; then ($(call CONFIG_VARS,development) > .env && $(DONE)) || (echo "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." && exit 1); fi
83
84# VERIFY SUB-TASKS
85
86_verify_eslint:
87 @if [ -e .eslintrc.js ]; then $(call GLOB,'*.js') | xargs eslint && $(DONE); fi
88
89_verify_lintspaces:
90 @if [ -e .editorconfig ] && [ -e package.json ]; then $(call GLOB) | xargs lintspaces -e .editorconfig -i js-comments,html-comments && $(DONE); fi
91
92_verify_scss_lint:
93# 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)
94 @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
95
96# DEPLOY SUB-TASKS
97
98_deploy_apex:
99 @if [ -e project.json ]; then $(call CONFIG_VARS,production) | sed 's/\(.*\)/-s \1/' | tr '\n' ' ' | xargs apex deploy && $(DONE); fi
100
101# BUILD SUB-TASKS
102
103# Only apply to Heroku apps for now
104public/__about.json:
105 @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
106
107# Some handy utilities
108GLOB = git ls-files -z $1 | tr '\0' '\n' | xargs -I {} find {} ! -type l
109NPM_INSTALL = npm prune --production=false && npm install
110JSON_GET_VALUE = grep $1 | head -n 1 | sed 's/[," ]//g' | cut -d : -f 2
111IS_GIT_IGNORED = grep -q $(if $1, $1, $@) .gitignore
112VERSION = v1.0.9
113APP_NAME = $(shell cat package.json 2>/dev/null | $(call JSON_GET_VALUE,name))
114DONE = echo ✓ $@ done
115CONFIG_VARS = curl -fsL https://ft-next-config-vars.herokuapp.com/$1/$(if $2,$2,$(call APP_NAME)).env -H "Authorization: `heroku config:get APIKEY --app ft-next-config-vars`"
116
117# UPDATE TASK
118
119update-tools:
120 $(eval LATEST = $(shell curl -fs https://api.github.com/repos/Financial-Times/n-makefile/tags | $(call JSON_GET_VALUE,name)))
121 $(if $(filter $(LATEST), $(VERSION)), $(error Cannot update n-makefile, as it is already up to date!))
122 @curl -sL https://raw.githubusercontent.com/Financial-Times/n-makefile/$(LATEST)/Makefile > n.Makefile
123 @sed -i "" "s/^VERSION = master/VERSION = $(LATEST)/" n.Makefile
124 @read -p "Updated tools from $(VERSION) to $(LATEST). Do you want to commit and push? [y/N] " Y;\
125 if [ $$Y == "y" ]; then git add n.Makefile && git commit -m "Updated tools to $(LATEST)" && git push origin HEAD; fi
126 @$(DONE)
127
\No newline at end of file