Initial push
Some checks are pending
CI / Analyze (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Styling (push) Waiting to run

This commit is contained in:
marked 2024-11-11 19:35:24 +01:00
parent 5a9167e2f5
commit 8ee75b96ed
51 changed files with 4437 additions and 2 deletions

39
.lune/util/spawn.luau Normal file
View file

@ -0,0 +1,39 @@
--!strict
local process = require("@lune/process")
local task = require("@lune/task")
--- Start a process with the given command and options
--- ```luau
--- spawn.start("lune run test")
--- ```
--- @param cmd string
--- @param options process.SpawnOptions?
--- @return process.SpawnResult
local function start_process(cmd: string, options: process.SpawnOptions?): process.SpawnResult
local arguments = string.split(cmd, " ")
local command = arguments[1]
table.remove(arguments, 1)
local opts: process.SpawnOptions = options ~= nil and options or {}
opts.stdio = opts.stdio ~= nil and opts.stdio or "forward"
return process.spawn(command, arguments, opts)
end
--- `task.spawn` a process with the given command and options
--- ```luau
--- spawn.spawn("lune run test") -- process now runs in the background!
--- ```
--- @param cmd string
--- @param options process.SpawnOptions?
--- @return process.SpawnResult
local function spawn_process(cmd: string, options: process.SpawnOptions?)
task.spawn(start_process, cmd, options)
end
local spawn = {
start = start_process,
spawn = spawn_process,
}
return spawn

46
.lune/util/watch.luau Normal file
View file

@ -0,0 +1,46 @@
--!strict
local fs = require("@lune/fs")
local task = require("@lune/task")
local function watch(path: string, on_change: (path: string, contents: string) -> (), run_initially: boolean?)
local initial_metadata = fs.metadata(path)
if not initial_metadata.exists then
return
end
if run_initially then
local initial_contents = fs.readFile(path)
local initial_success, why = pcall(on_change :: any, path, initial_contents) -- :: any because otherwise it shits itself and the type doesn't give (boolean, string)??
if not initial_success then
warn(`There was an error while trying to start the watcher thread:\n{why}`)
return
end
end
local last_modification = initial_metadata.modifiedAt
while true do
local metadata = fs.metadata(path)
if not metadata.exists then
continue
end
if metadata.modifiedAt == last_modification then
continue
end
last_modification = metadata.modifiedAt
local contents = fs.readFile(path)
local success, err = pcall(on_change :: any, path, contents)
if not success then
warn(err)
end
task.wait(1)
end
end
return watch