mirror of
https://github.com/pesde-pkg/tooling.git
synced 2024-12-12 07:10:36 +00:00
chore(lune): include lune dev scripts
* Adds dev lune scripts to execute tooling in dev env, also a nice way to dogfood the project. * Disables all lints in luaurc temporarily, since luau-lsp analysis displays lint errors even for ignored files for some reason. * Fixes a few `TypeError`s.
This commit is contained in:
parent
7b03d8cd4b
commit
9dd820d804
9 changed files with 189 additions and 7 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,2 @@
|
|||
lune_packages/
|
||||
luau_packages/
|
||||
**/*_packages/
|
||||
core/pesde.lock
|
||||
|
|
5
.luaurc
5
.luaurc
|
@ -1,3 +1,6 @@
|
|||
{
|
||||
"languageMode": "strict"
|
||||
"languageMode": "strict",
|
||||
"lint": {
|
||||
"*": false
|
||||
}
|
||||
}
|
129
.lune/exec.luau
Normal file
129
.lune/exec.luau
Normal file
|
@ -0,0 +1,129 @@
|
|||
--> lib: Builder pattern class to spawn child processes
|
||||
|
||||
local stdio = require("@lune/stdio")
|
||||
local process = require("@lune/process")
|
||||
|
||||
local Option = require("../lune_packages/option")
|
||||
type Option<T> = Option.Option<T>
|
||||
|
||||
local CommandBuilder = {}
|
||||
|
||||
export type CommandBuilder = typeof(setmetatable({} :: CommandBuilderFields, { __index = CommandBuilder }))
|
||||
type CommandBuilderFields = {
|
||||
program: string,
|
||||
args: { string },
|
||||
env: { [string]: string },
|
||||
stdioStrategy: Option<IoStrategyMapping>,
|
||||
}
|
||||
export type StdioStrategy = "pipe" | "forward" | "none"
|
||||
export type IoStrategyMapping = {
|
||||
stdout: Option<StdioStrategy>,
|
||||
stderr: Option<StdioStrategy>,
|
||||
}
|
||||
|
||||
-- FIXME: remove unknown usage
|
||||
local DEFAULT_STDIO_STRATEGY: IoStrategyMapping = {
|
||||
stdout = Option.Some("pipe" :: StdioStrategy) :: Option<unknown>,
|
||||
stderr = Option.Some("pipe" :: StdioStrategy) :: Option<unknown>,
|
||||
}
|
||||
function CommandBuilder.new(program: string)
|
||||
return setmetatable(
|
||||
{
|
||||
program = program,
|
||||
args = {},
|
||||
env = {},
|
||||
stdioStrategy = Option.None :: Option<IoStrategyMapping>,
|
||||
} :: CommandBuilderFields,
|
||||
{
|
||||
__index = CommandBuilder,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
function CommandBuilder.withArg(self: CommandBuilder, arg: string): CommandBuilder
|
||||
table.insert(self.args, arg)
|
||||
return self
|
||||
end
|
||||
|
||||
function CommandBuilder.withArgs(self: CommandBuilder, args: { string }): CommandBuilder
|
||||
for _, arg in args do
|
||||
self:withArg(arg)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function CommandBuilder.withEnvVar(self: CommandBuilder, var: string, value: string): CommandBuilder
|
||||
self.env[var] = value
|
||||
return self
|
||||
end
|
||||
|
||||
function CommandBuilder.withEnv(self: CommandBuilder, env: { [string]: string }): CommandBuilder
|
||||
for var, value in env do
|
||||
self:withEnvVar(var, value)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function CommandBuilder.withStdioStrategy(
|
||||
self: CommandBuilder,
|
||||
strategy: StdioStrategy | IoStrategyMapping
|
||||
): CommandBuilder
|
||||
-- FIXME: remove unknown usage
|
||||
self.stdioStrategy = Option.Some(if typeof(strategy) == "string"
|
||||
then {
|
||||
stdout = Option.Some(strategy) :: Option<unknown>,
|
||||
stderr = Option.Some(strategy) :: Option<unknown>,
|
||||
}
|
||||
else strategy) :: Option<IoStrategyMapping>
|
||||
return self
|
||||
end
|
||||
|
||||
local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.SpawnOptionsStdioKind
|
||||
if strategy == "pipe" then
|
||||
return "default"
|
||||
end
|
||||
|
||||
if strategy == "forward" then
|
||||
return "forward"
|
||||
end
|
||||
|
||||
if strategy == "none" then
|
||||
return "none"
|
||||
end
|
||||
|
||||
error(`Non-strategy provided: {strategy}`)
|
||||
end
|
||||
|
||||
function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult
|
||||
print(
|
||||
stdio.style("bold") .. "$",
|
||||
stdio.style("dim") .. self.program,
|
||||
table.concat(self.args, " ") .. stdio.style("reset")
|
||||
)
|
||||
local child = process.spawn(self.program, self.args, {
|
||||
shell = if process.os == "windows" then "cmd.exe" else "bash",
|
||||
stdio = self
|
||||
.stdioStrategy
|
||||
-- FIXME: remove unknown usage
|
||||
:orOpt(Option.Some(DEFAULT_STDIO_STRATEGY) :: Option<unknown>)
|
||||
:map(function(mappings: IoStrategyMapping)
|
||||
local translatedMappings: process.SpawnOptionsStdio = {}
|
||||
for field, value in mappings do
|
||||
translatedMappings[field] = intoSpawnOptionsStdioKind((value :: Option<StdioStrategy>):unwrap())
|
||||
end
|
||||
|
||||
return translatedMappings
|
||||
end)
|
||||
:unwrap(),
|
||||
})
|
||||
|
||||
if not child.ok then
|
||||
print(`\n{stdio.color("red")}[luau-lsp]{stdio.color("reset")} Exited with code`, child.code)
|
||||
end
|
||||
|
||||
return child
|
||||
end
|
||||
|
||||
return CommandBuilder
|
14
.lune/fmt.luau
Normal file
14
.lune/fmt.luau
Normal file
|
@ -0,0 +1,14 @@
|
|||
--> Run stylua to check for formatting errors
|
||||
|
||||
local process = require("@lune/process")
|
||||
|
||||
local CommandBuilder = require("./exec")
|
||||
|
||||
process.exit(
|
||||
CommandBuilder.new("pesde")
|
||||
:withArgs({ "run", "./bins/stylua" })
|
||||
:withArg("--")
|
||||
:withArgs(process.args)
|
||||
:withStdioStrategy("forward")
|
||||
:exec().code
|
||||
)
|
17
.lune/typecheck.luau
Normal file
17
.lune/typecheck.luau
Normal file
|
@ -0,0 +1,17 @@
|
|||
--> Run luau-lsp analysis to check for type errors
|
||||
|
||||
local process = require("@lune/process")
|
||||
|
||||
local CommandBuilder = require("./exec")
|
||||
|
||||
local PLATFORM_SEP = if process.os == "windows" then ";" else ":"
|
||||
|
||||
process.exit(
|
||||
CommandBuilder.new("luau-lsp")
|
||||
:withArg("analyze")
|
||||
:withArgs({ "--settings", ".vscode/settings.json" })
|
||||
:withArgs({ "--ignore", "'**/*_packages/**'" })
|
||||
:withArg(".")
|
||||
:withStdioStrategy("forward")
|
||||
:exec().code
|
||||
)
|
18
pesde.lock
18
pesde.lock
|
@ -7,3 +7,21 @@ lune = "bins/stylua"
|
|||
|
||||
[workspace."pesde/toolchainlib"]
|
||||
lune = "toolchainlib"
|
||||
|
||||
[graph."lukadev_0/option"."1.2.0 lune"]
|
||||
direct = ["option", { name = "lukadev_0/option", version = "^1.2.0" }, "standard"]
|
||||
resolved_ty = "standard"
|
||||
|
||||
[graph."lukadev_0/option"."1.2.0 lune".target]
|
||||
environment = "lune"
|
||||
lib = "lib/init.luau"
|
||||
|
||||
[graph."lukadev_0/option"."1.2.0 lune".pkg_ref]
|
||||
ref_ty = "pesde"
|
||||
name = "lukadev_0/option"
|
||||
version = "1.2.0"
|
||||
index_url = "https://github.com/daimond113/pesde-index"
|
||||
|
||||
[graph."lukadev_0/option"."1.2.0 lune".pkg_ref.target]
|
||||
environment = "lune"
|
||||
lib = "lib/init.luau"
|
||||
|
|
|
@ -7,5 +7,8 @@ workspace_members = ["toolchainlib", "bins/*"]
|
|||
[target]
|
||||
environment = "lune"
|
||||
|
||||
[dependencies]
|
||||
option = { name = "lukadev_0/option", version = "^1.2.0" }
|
||||
|
||||
[indices]
|
||||
default = "https://github.com/daimond113/pesde-index"
|
||||
|
|
|
@ -37,7 +37,7 @@ function Github.new(repo: string, config: Option<Config>)
|
|||
["Authorization"] = configOrDefault.authToken:mapOr("", function(token)
|
||||
return `Bearer {token}`
|
||||
end),
|
||||
},
|
||||
} :: net.HttpHeaderMap,
|
||||
} :: net.FetchParams,
|
||||
config = config,
|
||||
retries = configOrDefault.retries:unwrapOr(DEFAULT_MAX_RETRIES),
|
||||
|
|
|
@ -87,7 +87,6 @@ end
|
|||
|
||||
function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||
local toolAlias = toolAliasOrDefault(tool)
|
||||
|
||||
local client = Github.new(
|
||||
tool.repo,
|
||||
Option.Some({
|
||||
|
@ -134,7 +133,7 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
|||
|
||||
local binaryPath: pathfs.Path
|
||||
if matchingAsset == nil then
|
||||
warn("No matching asset found, downloading all assets")
|
||||
stdio.ewrite("No matching asset found, testing all binaries")
|
||||
for _, asset in assets do
|
||||
local decompressedPath = downloadAndDecompress(asset)
|
||||
|
||||
|
@ -165,7 +164,7 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
|||
|
||||
pathfs.move(binaryPath, installPath)
|
||||
|
||||
-- In order to eliminate fs read overhead on startup and to disallow
|
||||
-- IDEA: In order to eliminate fs read overhead on startup and to disallow
|
||||
-- the use of the tool binary when outside a package where it is installed,
|
||||
-- we can improve this by following what rokit does, where we symlink
|
||||
-- the tool's path to this script, and check the file that we are being
|
||||
|
|
Loading…
Reference in a new issue