Skip to content
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

Get extension theme #3

Merged
merged 35 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
41bfdf9
Get extension manifest
vocksel Jan 9, 2024
480d7a7
Work on theme fetching
vocksel Jan 9, 2024
0114889
Setup a Lune web server
vocksel Jan 9, 2024
72c75fe
Associate .luau with Lua language
vocksel Jan 9, 2024
aff0031
Fetch theme colors for extension
vocksel Jan 9, 2024
c839eb7
Setup serve command
vocksel Jan 9, 2024
4de5eb4
Initialize Lune
vocksel Jan 9, 2024
1f22ef6
Add recommended extensions
vocksel Jan 9, 2024
4769600
Fix selene warning for string requires
vocksel Jan 9, 2024
9ebdbb0
Get themed returned in Studio
vocksel Jan 9, 2024
dcab45d
Move plugin source from `src` to `plugin`
vocksel Jan 9, 2024
799f16f
Rename extension
vocksel Jan 9, 2024
d61b7f6
Map theme colors to studio colors
vocksel Jan 10, 2024
91315c8
Add WIP function for setting colors
vocksel Jan 10, 2024
9a857cf
WIP Dockerfile
vocksel Jan 10, 2024
441e2e8
Poll for the server
vocksel Jan 10, 2024
83472ca
Use server URL from constant
vocksel Jan 10, 2024
cb14c7a
Rename variable for consistency with other paths
vocksel Jan 10, 2024
cb28130
Make sure routes can never crash the server
vocksel Jan 10, 2024
604a596
Setup Foreman auth
vocksel Jan 10, 2024
24ca274
Exit early on healthcheck failure
vocksel Jan 10, 2024
a0e7bc8
Offload extension fetching to server
vocksel Jan 10, 2024
797e4ec
Update theme fetching
vocksel Jan 10, 2024
29ed942
Add a fixme for later
vocksel Jan 10, 2024
9511e0e
Create file for fetchExtension
vocksel Jan 10, 2024
7463bf6
Unused variable
vocksel Jan 10, 2024
555a548
Pass query to /extensions
vocksel Jan 10, 2024
0fe2b32
Apply theme colors
vocksel Jan 10, 2024
168b91a
Run server with Docker
vocksel Jan 11, 2024
cc50131
Improve error handling
vocksel Jan 11, 2024
b2b7cc5
Add a small logging library
vocksel Jan 11, 2024
0e758bf
Fix error with `global` token scope
vocksel Jan 11, 2024
c4e540f
Fix log level not persisting
vocksel Jan 11, 2024
93183bd
Move `plugin` back to `src` for now
vocksel Jan 11, 2024
1ac182e
Remove some unused code
vocksel Jan 11, 2024
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Build artifacts
build
extensions

# Local environment variables
.env

# Rojo
/*.rbxl*
/*.rbxm*
Expand Down
24 changes: 18 additions & 6 deletions .justfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
#!/usr/bin/env just --justfile

set dotenv-load

project_name := "rbxtheme"
plugins_dir := if os_family() == "unix" {
"$HOME/Documents/Roblox/Plugins"
} else {
"$LOCALAPPDATA/Roblox/Plugins"
}
plugin_filename := project_name + ".rbxm"
plugin_path := plugins_dir / plugin_filename
plugin_source := "src"
plugin_output := plugins_dir / plugin_filename
tmpdir := `mktemp -d`

default:
@just --list

clean:
rm -rf {{plugin_path}}
rm -rf {{ plugin_output }}

lint:
selene src/
stylua --check src/
selene {{ plugin_source }}
stylua --check {{ plugin_source }}

_build target watch:
./bin/build.py --target {{target}} --output {{ plugin_path }} {{ if watch == "true" { "--watch" } else { "" } }}
mkdir -p {{ parent_directory(plugin_output) }}
./bin/build.py --target {{target}} --output {{ plugin_output }} {{ if watch == "true" { "--watch" } else { "" } }}

init:
foreman install
lune --setup
just wally-install

wally-install:
wally install
Expand All @@ -41,9 +50,12 @@ test: clean
rojo build tests.project.json -o {{tmpdir / "tests.rbxl"}}
run-in-roblox --place {{tmpdir / "tests.rbxl"}} --script tests/init.server.lua

serve:
docker compose up

analyze:
curl -s -o "{{tmpdir}}/globalTypes.d.lua" -O https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/master/scripts/globalTypes.d.lua

rojo sourcemap tests.project.json -o "{{tmpdir}}/sourcemap.json"

luau-lsp analyze --sourcemap="{{tmpdir}}/sourcemap.json" --defs="{{tmpdir}}/globalTypes.d.lua" --defs=testez.d.lua --ignore=**/_Index/** src/
luau-lsp analyze --sourcemap="{{tmpdir}}/sourcemap.json" --defs="{{tmpdir}}/globalTypes.d.lua" --defs=testez.d.lua --ignore=**/_Index/** {{ plugin_source }}
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"JohnnyMorganz.luau-lsp",
"EditorConfig.EditorConfig",
"JohnnyMorganz.stylua",
"Kampfkarren.selene-vscode",
"skellock.just"
]
}
11 changes: 9 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
"luau-lsp.sourcemap.rojoProjectFile": "tests.project.json",
"luau-lsp.types.definitionFiles": [
"testez.d.lua"
]
}
],
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.7.11/"
},
"files.associations": {
"*.luau": "lua"
}
}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1

FROM ubuntu:24.04

LABEL description="Image for running the Lune server"

EXPOSE 8080

ARG LUNE_VERSION

RUN apt-get update
RUN apt-get install -y \
build-essential \
curl \
unzip

COPY ./server /server
WORKDIR /server

# HACK: Need to install a forked Lune that binds servers to 0.0.0.0
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN apt-get install -y git gcc
RUN git clone --single-branch --branch docker-server-binding https://github.com/ghostnaps/lune
RUN cargo build --release --manifest-path lune/Cargo.toml
CMD [ "./lune/target/release/lune", "server.luau" ]

# RUN curl -LJO https://github.com/lune-org/lune/releases/download/v${LUNE_VERSION}/lune-${LUNE_VERSION}-linux-aarch64.zip
# RUN unzip *.zip

# CMD [ "./lune", "server.luau" ]
2 changes: 1 addition & 1 deletion default.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
},
"$path": "src"
}
}
}
7 changes: 2 additions & 5 deletions dev.project.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"name": "rbxtheme",
"tree": {
"Packages": {
"$path": "Packages"
},
"$path": "src"
"$path": "default.project.json"
}
}
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
services:
lune-server:
container_name: lune-server
build:
dockerfile: Dockerfile
args:
- LUNE_VERSION=0.7.11
ports:
- "8080:8080"
1 change: 1 addition & 0 deletions foreman.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tools]
luau-lsp = { source = "JohnnyMorganz/luau-lsp", version = "1.x" }
lune = { source = "lune-org/lune", version = "0.7.11" }
rojo = { source = "rojo-rbx/rojo", version = "7.2.1" }
run-in-roblox = { source = "rojo-rbx/run-in-roblox", version = "0.3.0" }
selene = { source = "kampfkarren/selene", version = "0.25.0" }
Expand Down
7 changes: 7 additions & 0 deletions selene-requires.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
base: roblox
name: selene_defs
globals:
# override Roblox require style with string requires
require:
args:
- type: string
2 changes: 1 addition & 1 deletion selene.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
std = "roblox+testez"
std = "selene-requires+testez"

[lints]
global_usage = "allow"
10 changes: 10 additions & 0 deletions server/fetch.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local net = require("@lune/net")
local logging = require("./logging")

local function fetch(payload)
local method = if payload.method then payload.method else "GET"
logging.debug(`{method} {payload.url}`)
return net.request(payload)
end

return fetch
49 changes: 49 additions & 0 deletions server/fetchExtension.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local process = require("@lune/process")
local fs = require("@lune/fs")
local fetch = require("./fetch")

local EXTENSIONS_DIR = "extensions"

local function createExtensionDownloadUrl(
publisherName: string,
extensionName: string,
extensionVersion: string
): string
return `https://{publisherName}.gallery.vsassets.io/_apis/public/gallery/publisher/{publisherName}/extension/`
.. `{extensionName}/{extensionVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`
end

local function fetchExtension(publisherName: string, extensionName: string, extensionVersion: string): string?
if not fs.isDir(EXTENSIONS_DIR) then
fs.writeDir(EXTENSIONS_DIR)
end

local extensionPath = `{EXTENSIONS_DIR}/{publisherName}-{extensionName}-{extensionVersion}`

if fs.isDir(extensionPath) then
return extensionPath
else
local res = fetch({
method = "GET",
url = createExtensionDownloadUrl(publisherName, extensionName, extensionVersion),
})

if res.ok then
local zipPath = `{extensionPath}.zip`

fs.writeFile(zipPath, res.body)

res = process.spawn("unzip", { zipPath, "-d", extensionPath })

fs.removeFile(zipPath)

if res.ok then
return extensionPath
end
end

return nil
end
end

return fetchExtension
56 changes: 56 additions & 0 deletions server/logging.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local process = require("@lune/process")
local stdio = require("@lune/stdio")

type LogLevel = "info" | "warning" | "error" | "debug"

local LOG_LEVEL: string? = if process.env.LOG_LEVEL then process.env.LOG_LEVEL:lower() else "info"

local LOG_LEVEL_ORDER = {
"info",
"warning",
"debug",
"error",
}

local function canLog(logLevelToCheck: LogLevel): boolean
local maxPriority = table.find(LOG_LEVEL_ORDER, LOG_LEVEL)
local priorityToCheck = table.find(LOG_LEVEL_ORDER, logLevelToCheck)

if maxPriority and priorityToCheck then
return priorityToCheck <= maxPriority
else
return false
end
end

local logging = {}

function logging.info(...)
if canLog("info") then
print(`[info]`, ...)
end
end

function logging.warn(...)
if canLog("warning") then
stdio.write(stdio.color("yellow"))
print(`[warn]`, ...)
stdio.write(stdio.color("reset"))
end
end

function logging.err(...)
if canLog("error") then
stdio.write(stdio.color("red"))
print(`[err]`, ...)
stdio.write(stdio.color("reset"))
end
end

function logging.debug(...)
if canLog("debug") then
print(`[debug]`, ...)
end
end

return logging
Loading