-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
117 lines (89 loc) · 3.52 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
##############################################################################
########################### Configuration options ############################
##############################################################################
# Working directory
WD = $(shell pwd)
# Elm sources and its entry point, Main.elm
SRCS = $(wildcard src/*.elm)
MAIN = src/Main.elm
# Custom HTML
SRC_INDEX = custom_index.html
# Assets relative directories
ASSETS_DIR = assets/
JS_DIR = $(ASSETS_DIR)js/
FA_DIR = $(ASSETS_DIR)fa/
# HTML and JS relative paths
INDEX = index.html
JS = $(JS_DIR)elm.js
# Output directories
DIST_DIR = $(WD)/dist/
DEBUG_DIR = $(DIST_DIR)debug/
PROD_DIR = $(DIST_DIR)prod/
# Debug outputs
DEBUG_JS = $(DEBUG_DIR)$(JS)
DEBUG_INDEX = $(DEBUG_DIR)$(INDEX)
# Prod outputs
PROD_JS = $(PROD_DIR)$(JS)
PROD_INDEX = $(PROD_DIR)$(INDEX)
# Doc options: directory, index file, white-list of files to generate their
# documentation (leave it empty if you want all files in SRCS) and a license
# name for the elm-doc --fake-license option
DOC_DIR = doc/
DOC_INDEX = $(DOC_DIR)index.html
DOC_FILES = src/Route.elm
DOC_FAKE_LICENSE = 'AGPL-3.0'
# Elm binary, elm make options and elm-live options
ELM_BIN = ~/.node_modules/bin/elm
ELM_MAKE_OPTS = --debug --output=$(DEBUG_JS)
ELM_LIVE_OPTS = --open --pushstate --dir=$(DEBUG_DIR)
# Remote machine SSH credentials and remote directory where the web is served
REMOTE = alejandro@rpi
REMOTE_DIR = /home/alejandro/web
##############################################################################
######################### Generation of actual files #########################
##############################################################################
$(DEBUG_DIR):
mkdir -p $(DEBUG_DIR)$(JS_DIR)
ln -s $(WD)/assets/fa/ $(DEBUG_DIR)$(ASSETS_DIR)
$(PROD_DIR):
mkdir -p $(PROD_DIR)$(JS_DIR)
ln -s $(WD)/assets/fa/ $(PROD_DIR)$(ASSETS_DIR)
# Generate a debug index file
$(DEBUG_INDEX) : $(DEBUG_DIR) $(SRC_INDEX)
cp $(SRC_INDEX) $(DEBUG_INDEX)
# Compile a debug elm.js file from all the sources
$(DEBUG_JS) : $(DEBUG_DIR) $(SRCS)
elm make $(MAIN) $(ELM_MAKE_OPTS)
$(PROD_INDEX): $(PROD_DIR) $(SRC_INDEX)
cp $(SRC_INDEX) $(PROD_INDEX)
# Compile a production-ready, optimizied and minified elm.js
$(PROD_JS) : $(PROD_DIR) $(SRCS)
./optimize.sh $(MAIN)
# Generate the documentation from all the sources
$(DOC_INDEX) : $(SRCS)
elm-doc . --output $(DOC_DIR) \
--fake-license $(DOC_FAKE_LICENSE) \
--elm-path $(ELM_BIN) \
$(DOC_FILES)
##############################################################################
############################### PHONY targets ################################
##############################################################################
.PHONY: live debug prod deploy doc clean dist
.DEFAULT_GOAL := live
# Use elm-live to compile all the sources, watch their changes and recompile
# when a change is done, launching a server listening in localhost:8000
live : $(SRCS) $(DEBUG_JS) $(DEBUG_INDEX)
elm-live $(MAIN) $(ELM_LIVE_OPTS) -- $(ELM_MAKE_OPTS)
# Compile all the sources into a debug elm.js file
debug : $(DEBUG_JS) $(DEBUG_INDEX)
# Compile all the sources into a production-ready, minified elm.js file
prod : $(PROD_JS) $(PROD_INDEX)
# Deploy the production-compiled project into the remote directory
deploy : $(PROD_JS) $(PROD_INDEX)
ssh $(REMOTE) "cp -r $(REMOTE_DIR) $(REMOTE_DIR).backup"
scp -r $(PROD_DIR)/* $(REMOTE):$(REMOTE_DIR)
# Generate all the documentation
doc : $(DOC_INDEX)
# Remove the whole dist/ directory
clean:
rm -rf $(DIST_DIR)