1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-04 16:06:16 +00:00
opus/sys/extensions/6.packages.lua
kepler155c@gmail.com 97c4b7a090 package manager wip
2018-10-21 04:46:40 -04:00

42 lines
931 B
Lua

_G.requireInjector(_ENV)
local Packages = require('packages')
local Util = require('util')
local shell = _ENV.shell
local fs = _G.fs
local appPaths = Util.split(shell.path(), '(.-):')
local luaPaths = Util.split(_G.LUA_PATH, '(.-):')
local function addPath(t, e)
local function hasEntry()
for _,v in ipairs(t) do
if v == e then
return true
end
end
end
if not hasEntry() then
table.insert(t, 1, e)
end
end
-- dependency graph
-- https://github.com/mpeterv/depgraph/blob/master/src/depgraph/init.lua
for name, package in pairs(Packages:installed()) do
if package.mount then
fs.mount(table.unpack(Util.matches(package.mount)))
end
addPath(appPaths, fs.combine('packages', name))
local apiPath = fs.combine(fs.combine('packages', name), 'apis')
if fs.exists(apiPath) then
addPath(luaPaths, apiPath)
end
end
shell.setPath(table.concat(appPaths, ':'))
_G.LUA_PATH = table.concat(luaPaths, ':')