diff --git a/.gitmodules b/.gitmodules index 8a11803..346e51a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Justfile b/Justfile index efd7e76..3aca981 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,9 @@ #!/usr/bin/env just --justfile +set export + +COMPUTER_ID := "1970301799" # 'upkg' in octal + default: lint lint: @@ -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 + diff --git a/README.md b/README.md index b234c49..affe9cb 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/unicorn/core.lua b/unicorn/core.lua index dc7a831..984bf5a 100644 --- a/unicorn/core.lua +++ b/unicorn/core.lua @@ -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") @@ -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 diff --git a/unicorn/remote.lua b/unicorn/remote.lua index dc744ab..a766949 100644 --- a/unicorn/remote.lua +++ b/unicorn/remote.lua @@ -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") @@ -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 diff --git a/unicorn/util.lua b/unicorn/util.lua index 2cd5107..a4a6ee2 100644 --- a/unicorn/util.lua +++ b/unicorn/util.lua @@ -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 = {} @@ -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.") @@ -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 diff --git a/vendor/README.md b/vendor/README.md new file mode 100644 index 0000000..547a2a1 --- /dev/null +++ b/vendor/README.md @@ -0,0 +1,3 @@ +# `/vender` + +This folder contains vendored dependencies for use in an offline developer environment. diff --git a/vendor/libcompat b/vendor/libcompat new file mode 160000 index 0000000..1cc3a32 --- /dev/null +++ b/vendor/libcompat @@ -0,0 +1 @@ +Subproject commit 1cc3a325e694d49200307d6e992b017e16a582b1 diff --git a/vendor/semver b/vendor/semver new file mode 160000 index 0000000..af495ad --- /dev/null +++ b/vendor/semver @@ -0,0 +1 @@ +Subproject commit af495adc857d51fd1507a112be18523828a1da0d