Skip to content

feat!: Phoenix and Recrafted support through libcompat #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[submodule ".definitions/cc-tweaked"]
path = .definitions/cc-tweaked
url = https://gitlab.com/carsakiller/cc-tweaked-documentation
[submodule "vendor/libcompat"]
path = vendor/libcompat
url = https://github.com/unicornpkg/libcompat
[submodule "vendor/semver"]
path = vendor/semver.lua
url = https://github.com/kikito/semver.lua
31 changes: 31 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env just --justfile

set export

COMPUTER_ID := "1970301799" # 'upkg' in octal

default: lint

lint:
Expand All @@ -14,3 +18,30 @@ docs:

sync:
git pull --rebase; git push

# install lib and vendored dependencies to CraftOS-PC computer #1970301799
craftos-install:
#!/usr/bin/env sh
if [ $(uname) = "Darwin" ]; then
datadir="$HOME/Library/Application Support/CraftOS-PC"
else
datadir="$HOME/.craftos-pc"
fi

computerdir="$datadir/computer/$COMPUTER_ID"

mkdir -p "$computerdir/lib"

[ -L "$computerdir/lib/unicorn" ] && rm "$computerdir/lib/unicorn"
[ -L "$computerdir/lib/libcompat.lua" ] && rm "$computerdir/lib/libcompat.lua"
[ -L "$computerdir/lib/semver.lua" ] && rm "$computerdir/lib/semver.lua"
ln -s "$(pwd)/unicorn" "$computerdir/lib/unicorn"
ln -s "$(pwd)/vendor/libcompat/libcompat.lua" "$computerdir/lib/libcompat.lua"
ln -s "$(pwd)/vendor/semver/semver.lua" "$computerdir/lib/semver.lua"

# run computer #1970301799 in CraftOS-PC
craftos-run:
#!/usr/bin/env sh

craftos --id $COMPUTER_ID

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
The primary library and reference implementation for [unicornpkg](https://unicornpkg.madefor.cc).

Please see the documentation for more information.

## Dependencies
This library requires the [`semver.lua`](https://github.com/kikito/semver.lua) and [`libcompat`](https://github.com/unicornpkg/libcompat) libraries.
10 changes: 3 additions & 7 deletions unicorn/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- @module unicorn.core

package.path = "/lib/?.lua;/lib/?;/lib/?/init.lua;" .. package.path
local stdlib = require("libcompat")
local unicorn = {}
unicorn.core = {}
unicorn.util = require("unicorn.util")
Expand All @@ -10,15 +11,10 @@ local sha256 = _G.sha256 or require("sha256") -- Some servers provide access to

-- better handling of globals with Lua diagnostics
-- @diagnostic disable:undefined-global
local fs = fs
local textutils = textutils
local fs = stdlib.fs
local textutils = stdlib.textutils
-- @diagnostic enable:undefined-global

if _HOST:find("Recrafted") then -- Recrafted support
fs = require("fs")
textutils = require("textutils")
end

local function is_installed(package_name)
if fs.exists("/etc/unicorn/packages/installed/" .. package_name) then
return true
Expand Down
9 changes: 5 additions & 4 deletions unicorn/remote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- @module unicorn.remote

package.path = "/lib/?.lua;/lib/?;/lib/?/init.lua;" .. package.path
local stdlib = require("libcompat")
local unicorn = {}
unicorn.core = require("unicorn.core")
unicorn.util = require("unicorn.util")
Expand All @@ -12,12 +13,12 @@ function unicorn.remote.install(package_name)
while not downloaded do
-- TODO: Change the variable names into something more descriptive
-- TODO: Split this into smaller local functions
for _, v0 in pairs(fs.list("/etc/unicorn/remotes/")) do
if not fs.isDir("/etc/unicorn/remotes/" .. v0) then
local v1 = fs.open("/etc/unicorn/remotes/" .. v0, "r")
for _, v0 in pairs(stdlib.fs.list("/etc/unicorn/remotes/")) do
if not stdlib.fs.isDir("/etc/unicorn/remotes/" .. v0) then
local v1 = stdlib.fs.open("/etc/unicorn/remotes/" .. v0, "r")
local v2 = v1.readLine()
local v3 = v2:gsub("https://", "") -- have to remove the https:// prefix because fs.combine does weird stuff with it if it's left in
local v4 = fs.combine(v3, package_name .. ".lua")
local v4 = stdlib.fs.combine(v3, package_name .. ".lua")
local v5 = "https://" .. v4
local response, httpError = unicorn.util.smartHttp(v5)
if httpError then
Expand Down
7 changes: 4 additions & 3 deletions unicorn/util.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--- Utility functions for use with unicornpkg.
-- @module unicorn.util

package.path = "/lib/?.lua;/lib/?;/lib/?/init.lua;" .. package.path
local stdlib = require("libcompat")
local unicorn = {}
unicorn.util = {}

Expand All @@ -16,7 +17,7 @@ end
-- @param url string A valid HTTP or HTTPS URL.
function unicorn.util.smartHttp(url)
print("Connecting to " .. url .. "... ")
local response, httpError = http.get(url)
local response, httpError = stdlib.http.get(url)

if response then
print("HTTP success.")
Expand All @@ -34,7 +35,7 @@ end
-- @param path string The full path of the file to be written.
function unicorn.util.fileWrite(content, path)
if content then -- Checking to m @ake sure content is there, to prevent writing an empty file
local file1 = fs.open(path, "w")
local file1 = stdlib.fs.open(path, "w")
file1.write(content)
file1.flush()
else
Expand Down
3 changes: 3 additions & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `/vender`

This folder contains vendored dependencies for use in an offline developer environment.
1 change: 1 addition & 0 deletions vendor/libcompat
Submodule libcompat added at 1cc3a3
1 change: 1 addition & 0 deletions vendor/semver
Submodule semver added at af495a