2023-11-09 11:27:04 +01:00
|
|
|
#!/bin/sh
|
2023-03-09 19:58:08 +01:00
|
|
|
set -e
|
|
|
|
try(){ set +e; "$@" 2>/dev/null; set -e; }
|
2023-11-09 11:24:30 +01:00
|
|
|
trace(){ set -x; "$@"; set +x; }
|
2023-03-09 19:58:08 +01:00
|
|
|
|
|
|
|
install(){
|
|
|
|
which haxe || {
|
2023-03-09 21:55:03 +01:00
|
|
|
echo -e "installing haxe..if this fails:\n\n"
|
2023-03-09 19:58:08 +01:00
|
|
|
echo " 1. install haxe from haxe.org"
|
|
|
|
echo "[2.] download neko for cpp output"
|
|
|
|
echo "[3.] install mono openjdk14 for csharp + java output"
|
2023-03-09 21:55:03 +01:00
|
|
|
which apt-get && {
|
2023-03-09 21:56:16 +01:00
|
|
|
sudo apt-get update -y
|
2023-03-09 22:00:32 +01:00
|
|
|
sudo apt-get install neko haxe -y
|
2023-03-09 21:55:03 +01:00
|
|
|
}
|
2023-03-09 19:58:08 +01:00
|
|
|
}
|
2023-03-09 22:11:56 +01:00
|
|
|
mkdir ~/.haxe
|
|
|
|
haxelib setup ~/.haxe
|
2023-03-09 19:58:08 +01:00
|
|
|
haxelib install hxcpp
|
|
|
|
haxelib install hxjava
|
|
|
|
haxelib install hxcs
|
|
|
|
haxelib install hscript
|
2023-08-04 09:11:26 +02:00
|
|
|
which javac && haxelib install hxjava 4.2.0
|
|
|
|
which mono && haxelib install hxcs 4.2.0
|
2023-03-09 19:58:08 +01:00
|
|
|
}
|
|
|
|
|
2023-03-17 16:06:24 +01:00
|
|
|
tests(){
|
2023-03-30 19:51:32 +02:00
|
|
|
{
|
2023-05-23 17:56:31 +02:00
|
|
|
which node && node test/generated/test.js src/spec/*.json | awk '{ print "js: "$0 } END{ print "\n"}'
|
2023-11-10 18:22:47 +01:00
|
|
|
which python3 && python3 test/generated/test.py src/spec/*.json | awk '{ print "py: "$0 } END{ print "\n"}'
|
2023-03-30 21:32:36 +02:00
|
|
|
} | awk '$2 ~ /src/ { $2=sprintf("%-30s",$2); print $0; next; } 1' | tee /tmp/log.txt
|
2023-03-30 20:08:17 +02:00
|
|
|
grep error /tmp/log.txt && exit 1 || exit 0
|
2023-03-09 19:58:08 +01:00
|
|
|
}
|
|
|
|
|
2023-03-30 15:44:29 +02:00
|
|
|
doc(){
|
2023-06-27 12:15:10 +02:00
|
|
|
set -x
|
|
|
|
awk -f doc/generate.awk src/xrfragment/URI.hx
|
|
|
|
read -p "press enter after copy/pasting into wiki" a
|
|
|
|
awk -f doc/generate.awk src/xrfragment/Parser.hx
|
|
|
|
read -p "press enter after copy/pasting into wiki" a
|
|
|
|
awk -f doc/generate.awk src/xrfragment/Query.hx
|
|
|
|
read -p "press enter after copy/pasting into wiki" a
|
2023-03-30 15:44:29 +02:00
|
|
|
}
|
|
|
|
|
2023-04-21 17:36:03 +02:00
|
|
|
server(){
|
2023-08-04 09:11:26 +02:00
|
|
|
dir=$(pwd)
|
|
|
|
cd /tmp
|
|
|
|
test -f redbean.com || wget https://redbean.dev/redbean-2.2.com -O redbean.com && chmod 755 redbean.com
|
|
|
|
test -f cert.pem || openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
|
2023-08-08 12:40:38 +02:00
|
|
|
./redbean.com -c 0 -C cert.pem -K key.pem -D $dir
|
2023-04-21 17:36:03 +02:00
|
|
|
}
|
|
|
|
|
2023-04-20 22:30:04 +02:00
|
|
|
build(){
|
2023-05-04 16:26:22 +02:00
|
|
|
|
2023-11-09 11:24:30 +01:00
|
|
|
parser(){
|
|
|
|
try rm dist/*
|
2023-11-16 14:50:57 +01:00
|
|
|
haxe build.hxml || exit 1
|
2023-11-09 11:24:30 +01:00
|
|
|
sed -i 's|.*nonlocal .*||g' dist/xrfragment.py
|
|
|
|
ls -lah dist/*
|
|
|
|
echo -e "[OK] parser build\n"
|
2023-11-09 12:15:09 +01:00
|
|
|
return $ok
|
2023-11-09 11:24:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
js(){
|
|
|
|
# add js module
|
2023-11-09 11:55:26 +01:00
|
|
|
cat dist/xrfragment.js >> dist/xrfragment.module.js
|
2023-11-09 11:24:30 +01:00
|
|
|
echo "export default xrfragment;" >> dist/xrfragment.module.js
|
2023-12-06 15:20:58 +01:00
|
|
|
|
2023-11-09 11:24:30 +01:00
|
|
|
# add THREE
|
|
|
|
cat dist/xrfragment.js \
|
|
|
|
src/3rd/js/*.js \
|
|
|
|
src/3rd/js/three/*.js \
|
|
|
|
src/3rd/js/three/xrmacro/env.js \
|
|
|
|
src/3rd/js/three/xrf/*.js \
|
2023-11-09 11:27:04 +01:00
|
|
|
src/3rd/js/three/util/*.js \
|
2023-11-09 11:24:30 +01:00
|
|
|
src/3rd/js/three/xrf/dynamic/*.js \
|
|
|
|
src/3rd/js/three/xrf/src/*.js > dist/xrfragment.three.js
|
2023-12-06 15:20:58 +01:00
|
|
|
|
2023-11-09 11:24:30 +01:00
|
|
|
# add THREE module
|
|
|
|
cat dist/xrfragment.three.js > dist/xrfragment.three.module.js
|
|
|
|
echo "export default xrf;" >> dist/xrfragment.three.module.js
|
2023-12-06 15:20:58 +01:00
|
|
|
|
2023-12-06 21:39:04 +01:00
|
|
|
# convert ESM to normal browser js
|
|
|
|
sed 's/export //g' example/assets/js/utils.js > dist/utils.js
|
|
|
|
|
2023-11-09 11:24:30 +01:00
|
|
|
# add AFRAME
|
|
|
|
cat dist/xrfragment.three.js \
|
2023-12-06 15:20:58 +01:00
|
|
|
dist/utils.js \
|
|
|
|
src/3rd/js/aframe/*.js \
|
|
|
|
example/assets/js/qr.js > dist/xrfragment.aframe.js
|
|
|
|
|
|
|
|
# fat all-in-one standalone xrf release
|
|
|
|
test -f /tmp/xrf-aframe.js || {
|
|
|
|
wget "https://aframe.io/releases/1.5.0/aframe.min.js" -O /tmp/xrf-aframe.js
|
|
|
|
wget "https://cdn.jsdelivr.net/npm/aframe-blink-controls/dist/aframe-blink-controls.min.js" -O /tmp/xrf-blink.js
|
2023-12-12 18:09:30 +01:00
|
|
|
#for i in /tmp/xrf-*.js; do echo -e "\n" >> $i; done # add extra linebreak to prevent bundle issues
|
2023-12-06 15:20:58 +01:00
|
|
|
}
|
2023-12-06 21:39:04 +01:00
|
|
|
cat /tmp/xrf-*.js dist/xrfragment.aframe.js > dist/xrfragment.aframe.all.js
|
2023-12-06 15:20:58 +01:00
|
|
|
|
2023-11-09 11:55:26 +01:00
|
|
|
# add license headers
|
2023-12-06 21:39:04 +01:00
|
|
|
for file in dist/xrfragment.{aframe,module,three,three.module,aframe.all}.js; do
|
2023-11-09 12:15:09 +01:00
|
|
|
awk 'BEGIN{
|
|
|
|
print "/*"
|
2023-12-06 21:39:04 +01:00
|
|
|
print " * '"$(git tag)"' generated at '"$(date)"'"
|
2023-11-09 12:15:09 +01:00
|
|
|
print " * https://xrfragment.org"
|
|
|
|
print " * SPDX-License-Identifier: MPL-2.0"
|
|
|
|
print " */"
|
|
|
|
system("cat '$file'")
|
|
|
|
}' > /tmp/tmp.js
|
|
|
|
mv /tmp/tmp.js $file
|
|
|
|
done
|
2023-12-06 15:20:58 +01:00
|
|
|
|
|
|
|
|
2023-11-09 12:15:09 +01:00
|
|
|
ls -la dist | grep js
|
|
|
|
return $ok
|
2023-11-09 11:24:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test -z $1 && { parser && js; }
|
|
|
|
test -z $1 || "$@"
|
2023-04-20 22:30:04 +02:00
|
|
|
}
|
|
|
|
|
2023-12-06 15:20:58 +01:00
|
|
|
repos(){
|
|
|
|
release_dir(){
|
|
|
|
slug=xrfragment-$1-helloworld
|
|
|
|
test -d ../$slug || git clone git@github.com:coderofsalvation/$slug.git ../$slug
|
|
|
|
pushd $(pwd)
|
|
|
|
cp example/assets/index.glb ../$2/index.glb
|
|
|
|
cat example/$1/sandbox/index.html | \
|
|
|
|
sed 's|href=".*/assets|href="https://xrfragment.org/example/assets|g' | \
|
|
|
|
sed 's|"\./.*/dist|"https://xrfragment.org/dist|g' | \
|
|
|
|
sed 's|"\./.*/assets|"https://xrfragment.org/example/assets|g' \
|
|
|
|
> ../$2/index.html
|
|
|
|
test -z $COMMIT || {
|
|
|
|
set -x; cd ../$slug ; set +x
|
|
|
|
git add index.html
|
|
|
|
git commit -m "update index.html to commit $(git log | awk '{ print $1; exit 0; }') from xrfragment-repo"
|
|
|
|
git push origin main
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
echo " "
|
|
|
|
}
|
|
|
|
|
2023-12-08 13:35:19 +01:00
|
|
|
release_dir aframe xrfragment-aframe-helloworld
|
|
|
|
release_dir three xrfragment-three-helloworld
|
|
|
|
release_dir aframe xrfragment-helloworld
|
2023-12-06 15:20:58 +01:00
|
|
|
|
|
|
|
# remove aframe reference
|
|
|
|
sed -i 's|<script src="https:\/\/aframe.*||g' ../xrfragment-helloworld/index.html
|
|
|
|
sed -i 's|<script src=".*blink-controls.*||g' ../xrfragment-helloworld/index.html
|
2023-12-08 13:35:19 +01:00
|
|
|
sed -i 's|aframe\.js|aframe.all.js|g' ../xrfragment-helloworld/index.html
|
2023-12-06 15:20:58 +01:00
|
|
|
}
|
|
|
|
|
2023-04-20 22:30:04 +02:00
|
|
|
test -z $1 && build
|
2023-03-09 19:58:08 +01:00
|
|
|
test -z $1 || "$@"
|