build: remove php, replace with bash script

This commit is contained in:
mappu 2017-10-28 11:32:51 +13:00
parent 78ced31e9d
commit 0bafa59358
2 changed files with 23 additions and 22 deletions

View File

@ -17,7 +17,6 @@ all: $(BINNAME)-$(VERSION)-win32.7z $(BINNAME)-$(VERSION)-linux64.tar.xz $(BINNA
#./build.sh -v ${VERSION}
deps:
apt install php-cli p7zip
npm install -g less uglify-js less-plugin-clean-css html-minifier
go get github.com/googollee/go-socket.io
go get code.ivysaur.me/libnmdc
@ -36,9 +35,12 @@ bindata.go: client client/*
uglifyjs clientpack/dcwebui.js -o clientpack/dcwebui.min.js -c -m
lessc --clean-css clientpack/dcwebui.css clientpack/dcwebui.min.css
#php ./clientpack.php
./minipack clientpack/index.htm css dcwebui.css clientpack/dcwebui.min.css
./minipack clientpack/index.htm js dcwebui.js clientpack/dcwebui.min.js
./minipack clientpack/index.htm js socket.io-1.7.2.js clientpack/socket.io-1.7.2.js
cat clientpack/index.htm \
| ./minipack style dcwebui.css clientpack/dcwebui.min.css \
| ./minipack script dcwebui.js clientpack/dcwebui.min.js \
| ./minipack script socket.io-1.7.2.js clientpack/socket.io-1.7.2.js \
> clientpack/index.packed.htm
mv clientpack/index.packed.htm clientpack/index.htm
html-minifier --collapse-whitespace -o clientpack/index.min.htm clientpack/index.htm
mv clientpack/index.min.htm clientpack/index.htm
rm ./clientpack/*.js

View File

@ -1,23 +1,22 @@
#!/usr/bin/php
<?php
#!/bin/bash
// Embed content into HTML file
function embed($filename, $mode, $find, $sourcefile) {
$html_content = file_get_contents($filename);
$modes = [
'js' => ['script', 'script'],
'css' => ['link', 'style'],
];
set -eu
$html_content = preg_replace_callback(
'~<'. $modes[$mode][0] .'[^>]+'.$find.'[^>]*>~',
function() use ($modes, $mode, $sourcefile) {
return '<'. $modes[$mode][1] . '>'.file_get_contents($sourcefile).'</'. $modes[$mode][1] .'>';
},
$html_content
);
embed() {
local tag="$1"
local find="$2"
local sourcefile="$3"
while IFS= read -r line ; do
if [[ "${line}" =~ "${find}" ]] ; then
echo -n "<${tag}>"
cat "${sourcefile}"
echo -n "</${tag}>"
else
echo "${line}"
fi
done
file_put_contents($filename, $html_content);
}
embed($_SERVER['argv'][1], $_SERVER['argv'][2], $_SERVER['argv'][3], $_SERVER['argv'][4]);
embed "$@"