-
Notifications
You must be signed in to change notification settings - Fork 110
/
Makefile
executable file
·136 lines (113 loc) · 6.09 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
MAKE = "make"
INSTALL = "install"
TAR = "tar"
GREP = "grep"
NODE = "node"
NPM = "npm"
NODEJQ = "node_modules/node-jq/bin/jq"
SQLITE = "sqlite3"
CONF = "src/config.json"
PHP = "php"
CURL = "curl"
DESTDIR = $(shell $(CURDIR)/$(NODEJQ) -r '.dest // "" | select(. != "") // "dist"' $(CURDIR)/$(CONF))
SITEDOMAIN = $(shell $(CURDIR)/$(NODEJQ) -r ".DOMAIN" $(CURDIR)/$(CONF))
FILESDOMAIN = $(shell $(CURDIR)/$(NODEJQ) -r ".FILE_DOMAIN" $(CURDIR)/$(CONF))
MAXSIZE = $(shell $(CURDIR)/$(NODEJQ) -r ".max_upload_size" $(CURDIR)/$(CONF))
CONTACT_EMAIL = $(shell $(CURDIR)/$(NODEJQ) -r ".infoContact" $(CURDIR)/$(CONF))
PKG_VERSION = $(shell $(CURDIR)/$(NODEJQ) -r ".version" $(CURDIR)/package.json)
EXPIRE_TIME = $(shell $(CURDIR)/$(NODEJQ) -r ".expireTime" $(CURDIR)/$(CONF))
TMPDIR = $(shell mktemp -d)
DOCKER_IMAGE = "$(shell basename $(CURDIR) | tr [:upper:] [:lower:])"
DOCKER_TAG = "$(DOCKER_TAG)"
CONTAINER_NAME = "$(CONTAINER_NAME)"
pageList = $(shell $(CURDIR)/$(NODEJQ) -r ".pages[]" $(CURDIR)/$(CONF))
noExt = $(shell echo $(i) | cut -d '.' -f1)
all: check-var builddirs npm_dependencies ejs minify copy-img copy-php copy-benchmarks
check-var:
ifeq ($(CURDIR),)
$(error One or more required variables are not set. Something went wrong.)
endif
ifeq ($(DESTDIR),)
$(error One or more required variables are not set. Something went wrong.)
endif
ifeq ($(TMPDIR),)
$(error One or more required variables are not set. Something went wrong.)
endif
ejs: check-var
$(foreach i,$(pageList), \
"node_modules/ejs/bin/cli.js" -f $(CURDIR)/$(CONF) $(CURDIR)/src/templates/$(i) -o $(CURDIR)/build/html/unmin/$(noExt).html;)
sed -i '/uguu.min.js/d' $(CURDIR)/build/html/unmin/faq.html
sed -i '/uguu.min.js/d' $(CURDIR)/build/html/unmin/api.html
minify: check-var
"node_modules/@node-minify/cli/dist/cli.mjs" --compressor uglify-es --input $(CURDIR)/src/static/js/uguu.js --output $(CURDIR)/build/js/uguu.min.js
"node_modules/@node-minify/cli/dist/cli.mjs" --compressor cssnano --input $(CURDIR)/src/static/css/uguu.css --output $(CURDIR)/build/css/uguu.min.css
"node_modules/@node-minify/cli/dist/cli.mjs" --compressor html-minifier --input $(CURDIR)/build/html/unmin/faq.html --output $(CURDIR)/build/html/min/faq.html
"node_modules/@node-minify/cli/dist/cli.mjs" --compressor html-minifier --input $(CURDIR)/build/html/unmin/api.html --output $(CURDIR)/build/html/min/api.html
"node_modules/@node-minify/cli/dist/cli.mjs" --compressor html-minifier --input $(CURDIR)/build/html/unmin/index.html --output $(CURDIR)/build/html/min/index.html
installdirs: check-var
mkdir -p $(DESTDIR)/ $(DESTDIR)/img
mkdir -p $(DESTDIR)/ $(DESTDIR)/img/grills
copy-img: check-var
mkdir -p $(CURDIR)/build/img/grills
mkdir -p $(CURDIR)/build/img
cp -v $(CURDIR)/src/static/img/*.avif $(CURDIR)/build/img/
cp -v $(CURDIR)/src/static/img/grills/*.avif $(CURDIR)/build/img/grills/
"node_modules/imagemin-cli/cli.js" $(CURDIR)/src/static/img/*.png -o=$(CURDIR)/build/img/
"node_modules/imagemin-cli/cli.js" $(CURDIR)/src/static/img/grills/*.png --plugin=pngquant -o=$(CURDIR)/build/img/grills/
copy-php: check-var
cp -v $(CURDIR)/src/static/php/*.php $(CURDIR)/build/php/
cp -v $(CURDIR)/src/Classes/*.php $(CURDIR)/build/php/Classes/
copy-benchmarks: check-var
cp -v $(CURDIR)/src/Benchmarks/*.php $(CURDIR)/build/php/Benchmarks/
cp -v $(CURDIR)/src/Benchmarks/file.jpg $(CURDIR)/build/php/Benchmarks/
cp -v $(CURDIR)/src/Benchmarks/runBenchmark.sh $(CURDIR)/build/php/Benchmarks/
install: check-var installdirs
rm -rf $(DESTDIR)/*
cp -rv $(CURDIR)/build/* $(DESTDIR)/
cp $(CURDIR)/src/*.json $(DESTDIR)/
mv $(DESTDIR)/html/min/* $(DESTDIR)/public/
mv $(DESTDIR)/js/* $(DESTDIR)/public/
mv $(DESTDIR)/css/* $(DESTDIR)/public/
mv $(DESTDIR)/php/* $(DESTDIR)/
rm -rf $(DESTDIR)/html
rm -rf $(DESTDIR)/css
rm -rf $(DESTDIR)/js
rm -rf $(DESTDIR)/php
mv $(DESTDIR)/img $(DESTDIR)/public/
mv $(DESTDIR)/upload.php $(DESTDIR)/public/
cd $(DESTDIR)/ && $(CURL) -o composer-setup.php https://raw.githubusercontent.com/composer/getcomposer.org/main/web/installer
cd $(DESTDIR)/ && $(PHP) composer-setup.php --quiet
cd $(DESTDIR)/ && rm composer-setup.php
cd $(DESTDIR)/ && php composer.phar update && php composer.phar install && php composer.phar dump-autoload
bash ./compress.sh "$(DESTDIR)/public/"
dist: check-var
DESTDIR=$(TMPDIR)/uguu-$(PKGVERSION)
export DESTDIR
install
$(TAR) cJf uguu-$(PKG_VERSION).tar.xz $(DESTDIR)
rm -rf $(TMPDIR)
clean: check-var
rm -rvf $(CURDIR)/node_modules
rm -rvf $(CURDIR)/build
uninstall: check-var
rm -rvf $(DESTDIR)/
npm_dependencies:
$(NPM) install
build-container-no-cache:
tar --exclude='uguuForDocker.tar.gz' --exclude='vendor' --exclude='node_modules' --exclude='build' --exclude='dist' --exclude='.git' -czf uguuForDocker.tar.gz src docker Makefile package.json package-lock.json
mv uguuForDocker.tar.gz docker/
docker build -f docker/Dockerfile --build-arg DOMAIN=$(SITEDOMAIN) --build-arg FILE_DOMAIN=$(FILESDOMAIN) --build-arg CONTACT_EMAIL=$(CONTACT_EMAIL) --build-arg MAX_SIZE=$(MAXSIZE) --build-arg EXPIRE_TIME=$(EXPIRE_TIME) --no-cache -t uguu:$(PKG_VERSION) .
build-container:
tar --exclude='uguuForDocker.tar.gz' --exclude='vendor' --exclude='node_modules' --exclude='build' --exclude='dist' --exclude='.git' -czf uguuForDocker.tar.gz src docker Makefile package.json package-lock.json
mv uguuForDocker.tar.gz docker/
docker build -f docker/Dockerfile --build-arg DOMAIN=$(SITEDOMAIN) --build-arg FILE_DOMAIN=$(FILESDOMAIN) --build-arg CONTACT_EMAIL=$(CONTACT_EMAIL) --build-arg MAX_SIZE=$(MAXSIZE) --build-arg EXPIRE_TIME=$(EXPIRE_TIME) -t uguu:$(PKG_VERSION) .
run-container:
docker run --name uguu -d -p 80:80 -p 443:443 uguu:$(PKG_VERSION)
purge-containers:
if docker images | grep uguu; then \
docker rm -f uguu && docker rmi uguu:$(PKG_VERSION) || true;\
fi;
remove-container:
docker rm -f uguu
builddirs: check-var
mkdir -p $(CURDIR)/build $(CURDIR)/build/img $(CURDIR)/build/html $(CURDIR)/build/html/min $(CURDIR)/build/html/unmin $(CURDIR)/build/js $(CURDIR)/build/css $(CURDIR)/build/php $(CURDIR)/build/php/Classes $(CURDIR)/build/php/Benchmarks $(CURDIR)/build/php/Benchmarks/tmp $(CURDIR)/build/public