aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 088a9e13fa71d581f55d052f8a30467a4c2b8efa (plain)
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
all:
	make site
	make migration

site:
	mkdir --parents public/posts
	ln -sfT ../../public/posts generators/hugo/public
	cd generators/hugo && hugo

migration:
	sqlite3 database/sqlite.db < database/contactform.sql
	chmod g+w database/sqlite.db
	sed --in-place "s|'sql:;dbname=sql_database'|'sqlite:' . __DIR__ . '/database/sqlite.db'|" config.php

permissions:
	find . -type f -print0 | xargs -0 chmod 640
	find . -type d -print0 | xargs -0 chmod 770

export date := $(shell date -Iseconds)
export path := deploy-$(date)
export deployment := $(target)/$(path)
export prelaunch := $(target)/prelaunch
export public := $(target)/public

deploy:
	mkdir --parent '$(deployment)'
	rsync --archive --verbose \
    --exclude='.git/' \
    --exclude='.gitignore' \
    --exclude='$(target)/' \
    . '$(deployment)'
	ln --symbolic --force '$(path)/public' '$(prelaunch)'
	make minify
	make cache
	cd '$(deployment)' && make site
	make permissions
	cd '$(deployment)' && make migration
	mv --force --no-target-directory '$(prelaunch)' '$(public)'
	find '$(target)' -maxdepth 1 ! -path '$(target)' -type d -printf '%T@\t%p\n' \
    | sort --reverse --general-numeric-sort --field-separator $$'\t' \
    | cut --delimiter $$'\t' --fields 2- \
    | awk "NR>5" \
    | xargs rm -rf

cache:
	{ [ -e '$(public)' ] && \
		rsync --verbose --archive --include="*/" --include="*.min.*" --exclude="*" '$(public)/dist/' '$(prelaunch)/dist'; \
		rsync --verbose --archive '$(public)/../bootstrap/comments/comments/' '$(prelaunch)/../bootstrap/comments/comments'; \
		rsync --verbose --archive '$(public)/../database/sqlite.db' '$(prelaunch)/../database/sqlite.db'; \
	} || true

minify:
	minify $(prelaunch)/dist/app.css    > $(prelaunch)/dist/app.min.'$(date)'.css
	minify $(prelaunch)/dist/bar-ui.css > $(prelaunch)/dist/bar-ui-css.min.'$(date)'.css
	minify $(prelaunch)/dist/bar-ui.js  > $(prelaunch)/dist/bar-ui-js.min.'$(date)'.js
	find $(prelaunch) -type f -exec sed --in-place "s|$$(find $(prelaunch)/dist -name "app.min*"        | awk -F/ '{print $NF}')|" {} \;
	find $(prelaunch) -type f -exec sed --in-place "s|$$(find $(prelaunch)/dist -name "bar-ui-css.min*" | awk -F/ '{print $NF}')|" {} \;
	find $(prelaunch) -type f -exec sed --in-place "s|$$(find $(prelaunch)/dist -name "bar-ui-js.min*"  | awk -F/ '{print $NF}')|" {} \;

.PHONY: generators admin