wip support symlinks/recursion dirs + tests
This commit is contained in:
parent
3ea550e2b4
commit
2b287e4a7e
19 changed files with 104 additions and 64 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ experienceB
|
||||||
result
|
result
|
||||||
src/v
|
src/v
|
||||||
janusweb*
|
janusweb*
|
||||||
|
myverse
|
||||||
|
|
|
||||||
2
run.sh
2
run.sh
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
source ./.env
|
source ./.env
|
||||||
rebuild
|
rebuild
|
||||||
result/bin/xrforge.com server
|
result/bin/xrforge.com "$@"
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ app --
|
||||||
|
|
||||||
app.on('init', function()
|
app.on('init', function()
|
||||||
if assert(unix.fork()) == 0 then
|
if assert(unix.fork()) == 0 then
|
||||||
app.plugin.diskscan.scan()
|
app.plugin.diskscan.scan(app.opts.plugin_diskscan_dir)
|
||||||
print_r(app.cache)
|
print_r(app.cache)
|
||||||
--os.execute("ls ; sleep 5")
|
--os.execute("ls ; sleep 5")
|
||||||
print("ok")
|
print("ok")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ return function(app)
|
||||||
name = "XRForge",
|
name = "XRForge",
|
||||||
baseurl="/",
|
baseurl="/",
|
||||||
title="Your XR Forge",
|
title="Your XR Forge",
|
||||||
subtitle="Portable XR experiences for Phone, VRheadset & desktop.",
|
subtitle="Local-first XR experiences for Phone, VRheadset & desktop.",
|
||||||
admin_title = "XRForge Admin",
|
admin_title = "XRForge Admin",
|
||||||
admin_subtitle = "Manage your XR experiences here",
|
admin_subtitle = "Manage your XR experiences here",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,13 @@ return function(app,argv)
|
||||||
io.write( app.bin .. " " .. k .. "\t\t # " .. v.info .. "\n")
|
io.write( app.bin .. " " .. k .. "\t\t # " .. v.info .. "\n")
|
||||||
end)
|
end)
|
||||||
io.write("\nexample: " .. app.bin .. " title='My XRForge experiences'\n\n")
|
io.write("\nexample: " .. app.bin .. " title='My XRForge experiences'\n\n")
|
||||||
io.write("Flags: (overrides xrforge.lua configfile)\n\n")
|
io.write("example content: unzip result/bin/xrforge.com myverse/*\n\n")
|
||||||
|
io.write("Flags:\n\n")
|
||||||
foreach( app.opts, function(k,v)
|
foreach( app.opts, function(k,v)
|
||||||
if not k:match("/") and not k:match("^help") and not k:match("updated") then
|
if not k:match("/") and not k:match("^help") and not k:match("updated") then
|
||||||
io.write( " " .. k .. "='" .. v .. "'\n")
|
io.write( " " .. k .. "='" .. v .. "'\n")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
io.write("\n> NOTE: flags override flags in xrforge.lua configfile]\n")
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
6
src/myverse/janusxr/helloworld/janusxr.xml
Normal file
6
src/myverse/janusxr/helloworld/janusxr.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<title>world 1 title</title>
|
||||||
|
<fireboxroom>
|
||||||
|
<room use_local_asset="room-plane">
|
||||||
|
|
||||||
|
</room>
|
||||||
|
</fireboxroom>
|
||||||
BIN
src/myverse/janusxr/janusxr.png
Normal file
BIN
src/myverse/janusxr/janusxr.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 147 KiB |
1
src/myverse/janusxr/tronverse
Symbolic link
1
src/myverse/janusxr/tronverse
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
../tronverse
|
||||||
1
src/myverse/tronverse/janusxr
Symbolic link
1
src/myverse/tronverse/janusxr
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
../janusxr
|
||||||
BIN
src/myverse/tronverse/tron/tron.glb
Normal file
BIN
src/myverse/tronverse/tron/tron.glb
Normal file
Binary file not shown.
BIN
src/myverse/tronverse/tron/tron.mp3
Normal file
BIN
src/myverse/tronverse/tron/tron.mp3
Normal file
Binary file not shown.
BIN
src/myverse/tronverse/tron/tron.png
Normal file
BIN
src/myverse/tronverse/tron/tron.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 308 KiB |
BIN
src/myverse/tronverse/tronverse.png
Normal file
BIN
src/myverse/tronverse/tronverse.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
|
|
@ -9,24 +9,24 @@ return {
|
||||||
key='app.opts.plugin_diskscan_dir',
|
key='app.opts.plugin_diskscan_dir',
|
||||||
title='Directory',
|
title='Directory',
|
||||||
info="Directory to scan for experiences (use '.' for current) ",
|
info="Directory to scan for experiences (use '.' for current) ",
|
||||||
default=".",
|
default="./myverse",
|
||||||
values=''
|
values=''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
shouldHideFile = function(name)
|
shouldHideFile = function(name)
|
||||||
return name == ".."
|
return name == ".." -- parent
|
||||||
or name == "util" -- repository
|
or name == "util" -- repository
|
||||||
or name == ".git" -- files
|
or name:match("^%.") -- hidden
|
||||||
or name == "src" --
|
or name == "src" -- repository
|
||||||
or name == "result" --
|
or name == "result" -- repository
|
||||||
end,
|
end,
|
||||||
|
|
||||||
scan = function()
|
scan = function(scandir,parent,seen)
|
||||||
|
seen = seen or {}
|
||||||
local me = app.plugin.diskscan
|
local me = app.plugin.diskscan
|
||||||
local folder = app.opts.plugin_diskscan_dir
|
|
||||||
-- scan dirs
|
-- scan dirs
|
||||||
local dref, derr= dir.foreach( folder, function(path,stat,state,name,kind,ino,off,attr,fullpath)
|
local dref, derr = dir.foreach( scandir, function(path,stat,state,name,kind,ino,off,attr,fullpath)
|
||||||
if (kind == unix.DT_DIR or kind == unix.DT_LNK) and not me.shouldHideFile(name) then
|
|
||||||
local experience = {
|
local experience = {
|
||||||
path = fullpath,
|
path = fullpath,
|
||||||
name = name,
|
name = name,
|
||||||
|
|
@ -34,20 +34,26 @@ return {
|
||||||
tag = {},
|
tag = {},
|
||||||
file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
|
file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
|
||||||
}
|
}
|
||||||
app.pub("scan_experience", nil, experience)
|
|
||||||
print("ℹ️ ".. fullpath)
|
|
||||||
|
|
||||||
-- scan files
|
-- found directory
|
||||||
local fref, ferr = dir.foreach(fullpath, function(path,stat,state,name,kind,ino,off,attr, fullpath)
|
if not seen[ino] and (kind == unix.DT_DIR or kind == unix.DT_LNK)
|
||||||
if kind ~= unix.DT_DIR and not me.shouldHideFile(name) then
|
and not me.shouldHideFile(name) then
|
||||||
experience.file = {stat=stat,state=state,kind=kind,ino=ino,off=off,attr=attr,fullpath=fullpath,name=name,path=path}
|
seen[ino] = true -- prevent recursion with symlinks
|
||||||
|
print("✅ ".. fullpath)
|
||||||
|
app.pub("scan_experience", nil, experience)
|
||||||
|
table.insert( app.cache.items, experience)
|
||||||
|
me.scan(fullpath, dir,seen)
|
||||||
|
end
|
||||||
|
|
||||||
|
---- found file
|
||||||
|
if not seen[ino] and (kind ~= unix.DT_DIR and kind ~= unix.DT_LNK)
|
||||||
|
and not me.shouldHideFile(name) then
|
||||||
|
seen[ino] = true -- prevent recursion with symlinks
|
||||||
|
print("ℹ️ ".. fullpath)
|
||||||
app.pub("scan_experience_file", nil, experience)
|
app.pub("scan_experience_file", nil, experience)
|
||||||
local size = attr:size()
|
local size = attr:size()
|
||||||
trace("ℹ️ ".. fullpath)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
if not ferr then fref:close() end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
if not derr then dref:close() end
|
if not derr then dref:close() end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,15 @@ local pattern_fireboxroom = "[Ff][Ii][Rr][Ee][Bb][Oo][Xx][Rr][Oo][Oo][Mm][ ]?.*>
|
||||||
local pattern_title = "<[Tt][Ii][Tt][Ll][Ee]>(.*)<"
|
local pattern_title = "<[Tt][Ii][Tt][Ll][Ee]>(.*)<"
|
||||||
|
|
||||||
app.on('scan_experience', function(exp)
|
app.on('scan_experience', function(exp)
|
||||||
|
print("dir: "..exp.file.fullpath)
|
||||||
--print_r(exp)
|
--print_r(exp)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
app.on('scan_experience_file', function(exp)
|
app.on('scan_experience_file', function(exp)
|
||||||
local size = exp.file.attr:size()
|
local size = exp.file.attr:size()
|
||||||
if exp.file.name:match(".glb") and not util.contains(exp.tag,"xrfragment") then
|
if size < 1000 then -- skip large binary files
|
||||||
print("✅ └─ plugin/janusxr: generating janusxr.xml")
|
|
||||||
table.insert(exp.tag, "janusxr")
|
|
||||||
app.pub("scan_experience_janusxr", nil, {exp=exp, item=item}) -- be nice to other plugins
|
|
||||||
table.insert( app.cache.items, exp)
|
|
||||||
elseif size < 1000 then -- skip large binary files
|
|
||||||
local data = util.readfile( exp.file.fullpath)
|
local data = util.readfile( exp.file.fullpath)
|
||||||
|
if data then
|
||||||
if data:match(pattern_fireboxroom) then
|
if data:match(pattern_fireboxroom) then
|
||||||
table.insert(exp.tag, "janusxr")
|
table.insert(exp.tag, "janusxr")
|
||||||
local title = data:match(pattern_title)
|
local title = data:match(pattern_title)
|
||||||
|
|
@ -26,6 +23,9 @@ app.on('scan_experience_file', function(exp)
|
||||||
table.insert( app.cache.items, exp)
|
table.insert( app.cache.items, exp)
|
||||||
print("✅ └─ plugin/janusxr: " .. exp.file.name)
|
print("✅ └─ plugin/janusxr: " .. exp.file.name)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- symlink to directory
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
||||||
14
src/test/env/demofiles.sh
vendored
Executable file
14
src/test/env/demofiles.sh
vendored
Executable file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cleanup(){
|
||||||
|
rm -rf world{1,2,3,4} 2>/dev/null || true
|
||||||
|
}
|
||||||
|
|
||||||
|
create(){
|
||||||
|
mkdir world1 ;
|
||||||
|
mkdir world2 ;
|
||||||
|
ln -s /tmp world3 ;
|
||||||
|
ln -fs nonexisting world4 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
"$@"
|
||||||
|
|
@ -2,22 +2,7 @@ local lust = require 'test/lust'
|
||||||
local describe, it, expect = lust.describe, lust.it, lust.expect
|
local describe, it, expect = lust.describe, lust.it, lust.expect
|
||||||
-- usage: https://github.com/bjornbytes/lust
|
-- usage: https://github.com/bjornbytes/lust
|
||||||
|
|
||||||
describe('my project', function()
|
require('test/plugin_diskscan')(lust)
|
||||||
lust.before(function()
|
|
||||||
-- This gets run before every test.
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe('ℹ️ app vars', function() -- Can be nested
|
|
||||||
it('bindir', function()
|
|
||||||
print(app.bindir)
|
|
||||||
expect(app.bindir).to.fail('xrforge.com') -- Pass
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('feature2', function()
|
|
||||||
expect(nil).to.exist() -- Fail
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
if lust.errors == 0 then
|
if lust.errors == 0 then
|
||||||
print("✅ all tests passed")
|
print("✅ all tests passed")
|
||||||
|
|
|
||||||
24
src/test/plugin_diskscan.lua
Executable file
24
src/test/plugin_diskscan.lua
Executable file
|
|
@ -0,0 +1,24 @@
|
||||||
|
return function(lust)
|
||||||
|
|
||||||
|
|
||||||
|
local describe, it, expect = lust.describe, lust.it, lust.expect
|
||||||
|
|
||||||
|
describe('src/plugin/diskscan.lua', function()
|
||||||
|
|
||||||
|
lust.before(function() os.execute('test/env/demofiles.sh create') end)
|
||||||
|
lust.after(function() os.execute('test/env/demofiles.sh cleanup') end)
|
||||||
|
|
||||||
|
describe('ℹ️ app vars', function() -- Can be nested
|
||||||
|
it('bindir', function()
|
||||||
|
print(app.bindir)
|
||||||
|
expect(app.bindir).to.fail('xrforge.com') -- Pass
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('feature2', function()
|
||||||
|
expect(nil).to.exist() -- Fail
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -35,12 +35,12 @@ build(){
|
||||||
download redbean
|
download redbean
|
||||||
download janusweb
|
download janusweb
|
||||||
cd src
|
cd src
|
||||||
zip -r ../result/bin/xrforge.com * .lua .init.lua .args
|
zip -yr ../result/bin/xrforge.com * .lua .init.lua .args
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuild(){
|
rebuild(){
|
||||||
cd src
|
cd src
|
||||||
zip -r ../result/bin/xrforge.com .lua page plugin cmd css .init.lua .args
|
zip -yr ../result/bin/xrforge.com .lua page plugin cmd css .init.lua .args test myverse
|
||||||
}
|
}
|
||||||
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue