-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
178 lines (132 loc) · 3.19 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
.PHONY: re all install build test test-watch clean clean-stuff dev debug help
### ENVIRONMENT VARIABLES ###
# BASIC
APP_TITLE?=elm-boilerplate
ELM_STUFF=elm-stuff
ELM_PACKAGE=elm-package.json
MAIN=Main.elm
BUNDLE=elm.js
# CACHE
ELM_STUFF_ARTIFACTS=$(ELM_STUFF)/build-artifacts
TESTS_ELM_STUFF_ARTIFACTS=$(TESTS_FOLDER)/$(ELM_STUFF_ARTIFACTS)
# INSTALL
ELMINSTALL=elm package install -y
# BUILD
ELMMAKE=elm make
# DEV
PORT?=8000
ELMLIVE=elm live --open --pushstate --port=$(PORT)
ELMREACTOR=elm reactor --port=$(PORT) --address=0.0.0.0
# TESTS
TESTS_FOLDER=tests
TESTS_ELM_STUFF=$(TESTS_FOLDER)/$(ELM_STUFF)
ELMTEST=elm test
# MISC
CD=cd
ECHO=echo
RIMRAF=rm -rf
# GIT
GIT=git
GIT_INITIAL_MESSAGE="Init $(APP_TITLE)"
GIT_FOLDER=.git
GITIGNORE=.gitignore
define GITIGNORE_CONTENT
$(ELM_STUFF)
$(BUNDLE)
endef
export GITIGNORE_CONTENT
# Main.elm
define MAIN_CONTENT
module Main exposing (..)
import Html exposing (..)
main =
h1 [] [ text "$(APP_TITLE)" ]
endef
export MAIN_CONTENT
# index.html
INDEX_HTML=index.html
define INDEX_HTML_CONTENT
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>$(APP_TITLE)</title>
<script type="text/javascript" src="/$(BUNDLE)"></script>
<link rel="stylesheet" href="/$(STYLES_CSS)">
</head>
<body>
</body>
<script type="text/javascript">
var app = Elm.Main.fullscreen();
</script>
</html>
endef
export INDEX_HTML_CONTENT
# STYLES
STYLES_CSS=style.css
define STYLES_CSS_CONTENT
endef
export STYLES_CSS_CONTENT
# help
define HELP_CONTENT
Usage:
make dev : start elm live (you can use PORT environment variable)
make debug : start elm reactor (you can use PORT environment variable)
make test : start tests
make test-watch : start tests in watch mode
make clean : remove artifacts
make build : build artifacts
make re : recompile artifacts
make help : display this help
endef
export HELP_CONTENT
### BASIC COMMANDS
# install
all: install
$(ELM_PACKAGE) $(ELM_STUFF):
$(ELMINSTALL)
# build
$(ELM_STUFF_ARTIFACTS):
@$(ELMMAKE)
$(TESTS_ELM_STUFF_ARTIFACTS):
@$(CD) $(TESTS_FOLDER) && $(ELMMAKE)
# tests
$(TESTS_FOLDER):
$(ELMTEST) init
$(TESTS_ELM_STUFF):
@$(CD) $(TESTS_FOLDER) && $(ELMINSTALL)
# git
$(GIT_FOLDER):
$(GIT) init && $(GIT) add . && $(GIT) commit -m $(GIT_INITIAL_MESSAGE)
install: $(GITIGNORE) \
$(ELM_PACKAGE) $(TESTS_FOLDER) \
$(MAIN) $(INDEX_HTML) $(STYLES_CSS) \
$(TESTS_ELM_STUFF) $(ELM_STUFF) \
$(ELM_STUFF_ARTIFACTS) $(TESTS_ELM_STUFF_ARTIFACTS) \
$(GIT_FOLDER)
dev: all
@$(ELMLIVE) $(MAIN) --output=$(BUNDLE)
debug: all
@$(ELMREACTOR)
build: $(ELM_STUFF_ARTIFACTS) $(TESTS_ELM_STUFF_ARTIFACTS)
clean:
@$(RIMRAF) $(BUNDLE) $(ELM_STUFF_ARTIFACTS) $(TESTS_ELM_STUFF_ARTIFACTS) && $(ECHO) Cleaned!
clean-stuff:
@$(RIMRAF) $(ELM_STUFF) $(TESTS_ELM_STUFF)
test: all
$(ELMTEST)
test-watch: all
$(ELMTEST) --watch
re: clean all
help:
@$(ECHO) "$$HELP_CONTENT"
### INIT PROJECT ###
LOG=$(ECHO) Created
$(GITIGNORE):
@$(ECHO) "$$GITIGNORE_CONTENT" > $(GITIGNORE) && $(LOG) $(GITIGNORE)
$(MAIN):
@$(ECHO) "$$MAIN_CONTENT" > $(MAIN) && $(LOG) $(MAIN)
$(INDEX_HTML):
@$(ECHO) "$$INDEX_HTML_CONTENT" > $(INDEX_HTML) && $(LOG) $(INDEX_HTML)
$(STYLES_CSS):
@$(ECHO) "$$STYLES_CSS_CONTENT" > $(STYLES_CSS) && $(LOG) $(STYLES_CSS)