aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: f64cbd682b227b5bad7b12d81678174515adcd13 (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
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'; } || 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