-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
179 lines (131 loc) · 5.98 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
179
postcss := ./node_modules/postcss-cli/bin/postcss --config ./config/postcss.config.js
terser := ./node_modules/terser/bin/terser
apppath := ./progressinator
publicdist := ./public-dist
public := ./public
install:
brew install node fswatch yarn parallel mkcert nss pyenv pipenv pre-commit
brew cask install postgres
yarn install
pipenv install --dev
pre-commit install
build:
mkcert --install
mkcert progressinator.dev
mv ./progressinator.dev-key.pem ./config/certs/progressinator.dev-key.pem
mv ./progressinator.dev.pem ./config/certs/progressinator.dev.pem
make build-static
start-pgsql:
open /Applications/Postgres.app
start-server:
heroku local --port=8000 --procfile=Procfile.dev
watch-django-templates:
fswatch --verbose -0 --recursive $(apppath)/templates/* $(apppath)/templates/*/* $(apppath)/patterns/* $(apppath)/core/templates/* | xargs -0 -I {} cat .gunicorn.pid | xargs -n 1 -I [] kill -HUP []
start:
parallel --ungroup ::: "make start-server" "make watch-django-templates"
test:
pytest
copy-courses:
cp /db/learn-the-web/www/_site/courses/web-design-1/course.json ./config/courses/web-design-1.json
cp /db/learn-the-web/www/_site/courses/web-design-2/course.json ./config/courses/web-design-2.json
cp /db/learn-the-web/www/_site/courses/web-dev-1/course.json ./config/courses/web-dev-1.json
cp /db/learn-the-web/www/_site/courses/web-dev-2/course.json ./config/courses/web-dev-2.json
cp /db/learn-the-web/www/_site/courses/web-dev-3/course.json ./config/courses/web-dev-3.json
cp /db/learn-the-web/www/_site/courses/web-dev-4/course.json ./config/courses/web-dev-4.json
cp /db/learn-the-web/www/_site/courses/web-dev-5/course.json ./config/courses/web-dev-5.json
cp /db/learn-the-web/www/_site/courses/web-dev-6/course.json ./config/courses/web-dev-6.json
cp /db/learn-the-web/www/_site/courses/javascript/course.json ./config/courses/javascript.json
build-courses:
pipenv run python ./scripts/compile-courses.py
##################################################
# STATIC FILES
##################################################
build-css:
$(postcss) $(apppath)/css/main.css --output $(publicdist)/main.min.css
python ./scripts/sri_resource.py "$(publicdist)/main.min.css"
watch-build-main-css:
$(postcss) $(apppath)/css/main.css --output $(publicdist)/main.min.css --watch
watch-css-copy-dist:
fswatch --verbose -0 $(publicdist)/* | xargs -0 -n 1 -I {} cp {} $(public)/core/
watch-css-copy-dist-sri:
fswatch --verbose -0 $(publicdist)/main.min.css | xargs -0 -I {} python ./scripts/sri_resource.py "$(publicdist)/main.min.css"
watch-css:
parallel --ungroup ::: "make watch-build-main-css" "make watch-css-copy-dist" "make watch-css-copy-dist-sri"
build-js:
cat $(apppath)/js/*.js | $(terser) --compress --mangle --output $(publicdist)/main.min.js
python ./scripts/sri_resource.py "$(publicdist)/main.min.js"
watch-build-js-app:
cat $(apppath)/js/*.js | $(terser) --beautify --output $(publicdist)/main.min.js
cp $(publicdist)/main.min.js $(public)/core/
watch-js-app:
fswatch --verbose -0 $(apppath)/js/*.js | xargs -0 -I {} make watch-build-js-app
watch-js-app-sri:
fswatch --verbose -0 $(publicdist)/main.min.js | xargs -0 -I {} python ./scripts/sri_resource.py "$(publicdist)/main.min.js"
watch-js:
parallel --ungroup ::: "make watch-js-app" "make watch-js-app-sri"
build-django-collectstatic:
python manage.py collectstatic --noinput
build-all-sri:
find $(public)/core/*.css -exec python ./scripts/sri_resource.py {} \;
find $(public)/core/*.js -exec python ./scripts/sri_resource.py {} \;
build-static:
make build-css build-js build-django-collectstatic build-all-sri
##################################################
# POSTGRES & DJANGO DB
##################################################
migrate:
python manage.py makemigrations progress_core
python manage.py migrate
dbload:
python manage.py loaddata data/all.json
dbload-model:
python manage.py loaddata data/$(model).json
dbload-fixtures:
ls progressinator/core/fixtures/ | xargs -I {} python manage.py loaddata {}
dbdump:
python manage.py dumpdata --indent=2 -o data/all.json progress_core
dbdump-model:
python manage.py dumpdata --indent=2 -o data/$(model).json progress_core.$(model)
dbdump-fixture:
python manage.py dumpdata --indent=2 -o $(apppath)/core/fixtures/$(model).json progress_core.$(model)
django-super-user:
python manage.py createsuperuser
##################################################
# HEROKU
##################################################
heroku-setup:
# https://cookiecutter-django.readthedocs.io/en/latest/deployment-on-heroku.html
heroku create learn-the-web-progress
heroku git:remote -a learn-the-web-progress
heroku buildpacks:add heroku/python
heroku buildpacks:add heroku/nodejs
heroku addons:create --wait heroku-postgresql:hobby-dev
heroku pg:backups schedule --at '02:00 America/Toronto' DATABASE_URL
heroku config:set PYTHONHASHSEED=random
heroku config:set PYTHONIOENCODING=utf8
heroku config:set WEB_CONCURRENCY=4
heroku config:set DISABLE_COLLECTSTATIC=1
heroku config:set DJANGO_DEBUG=False
heroku config:set DJANGO_SETTINGS_MODULE=config.settings.prod
heroku config:set DJANGO_SECRET_KEY="$(openssl rand -base64 64)"
heroku config:set DJANGO_ALLOWED_HOST=progress.learntheweb.courses
# heroku config:set SENTRY_DSN=
git push heroku
heroku ps:resize web=hobby
heroku certs:auto:enable
heroku domains:add progress.learntheweb.courses
heroku-migrate:
heroku run python manage.py migrate
heroku-django-super-user:
heroku run python manage.py createsuperuser
heroku-db-push:
heroku pg:push postgres://localhost:5432/progressinator DATABASE_URL --app learn-the-web-progress
heroku-db-pull:
heroku pg:pull DATABASE_URL postgres://localhost:5432/progressinator --app learn-the-web-progress
heroku-rebuild:
git commit --allow-empty -m 'empty commit' && git push heroku master
##################################################
# FUN
##################################################
cloc:
cloc --exclude-dir=node_modules,public,public-dist,__pycache__,data --exclude-ext=lock,json .