mirror of
https://github.com/pesde-pkg/scripts.git
synced 2024-12-12 07:00:35 +00:00
style: apply stylua formatter
This commit is contained in:
parent
e907258396
commit
ef8953fdcc
13 changed files with 625 additions and 519 deletions
|
@ -59,16 +59,21 @@ local function logPrefix(type: "error" | "info")
|
|||
elseif type == "info" then "green"
|
||||
else error(`Invalid type: {type}`)
|
||||
|
||||
return `main::{stdio.style("bold")}{stdio.color(statusColor)}{type}{stdio.color("reset")}`
|
||||
return `main::{stdio.style("bold")}{stdio.color(statusColor)}{type}{stdio.color(
|
||||
"reset"
|
||||
)}`
|
||||
end
|
||||
|
||||
local INFO_PREFIX = `[ {logPrefix("info")}]`
|
||||
local _ERROR_PREFIX = `[{logPrefix("error")}]`
|
||||
|
||||
local function installDeps(): number
|
||||
local PESDE_INFO_PREFIX = string.gsub(`[{logPrefix("info")}]`, "main", "pesde")
|
||||
local PESDE_ERROR_PREFIX = string.gsub(`[{logPrefix("error")}]`, "main", "pesde")
|
||||
local SPINNER_STATES = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
||||
local PESDE_INFO_PREFIX =
|
||||
string.gsub(`[{logPrefix("info")}]`, "main", "pesde")
|
||||
local PESDE_ERROR_PREFIX =
|
||||
string.gsub(`[{logPrefix("error")}]`, "main", "pesde")
|
||||
local SPINNER_STATES =
|
||||
{ "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
||||
|
||||
stdio.write(`{PESDE_INFO_PREFIX} Installing dependencies with pesde`)
|
||||
|
||||
|
@ -108,11 +113,15 @@ local function installDeps(): number
|
|||
)
|
||||
|
||||
if not child.ok then
|
||||
stdio.ewrite(`{PESDE_ERROR_PREFIX} Failed to install dependencies with pesde, error:\n`)
|
||||
stdio.ewrite(
|
||||
`{PESDE_ERROR_PREFIX} Failed to install dependencies with pesde, error:\n`
|
||||
)
|
||||
stdio.ewrite(child.stderr)
|
||||
end
|
||||
|
||||
stdio.write(`{PESDE_INFO_PREFIX} Installed dependencies with pesde successfully\n`)
|
||||
stdio.write(
|
||||
`{PESDE_INFO_PREFIX} Installed dependencies with pesde successfully\n`
|
||||
)
|
||||
|
||||
return child.code
|
||||
end
|
||||
|
@ -172,23 +181,43 @@ for tool, generators in lib.generators do
|
|||
|
||||
-- Format the scripts for the tool
|
||||
local syncConfigGeneratorScript, sourcemapGeneratorScript =
|
||||
string.format(SCRIPTS.syncConfigGenerator, toolChoice), string.format(SCRIPTS.sourcemapGenerator, toolChoice)
|
||||
string.format(SCRIPTS.syncConfigGenerator, toolChoice),
|
||||
string.format(SCRIPTS.sourcemapGenerator, toolChoice)
|
||||
|
||||
-- Finally, write all the generated files
|
||||
pathfs.writeFile(toolScriptsDir:join("pesde.toml"), serde.encode("toml", toolManifest, true))
|
||||
pathfs.writeFile(toolScriptsDir:join("roblox_sync_config_generator.luau"), syncConfigGeneratorScript)
|
||||
pathfs.writeFile(toolScriptsDir:join("sourcemap_generator.luau"), sourcemapGeneratorScript)
|
||||
pathfs.writeFile(
|
||||
toolScriptsDir:join("pesde.toml"),
|
||||
serde.encode("toml", toolManifest, true)
|
||||
)
|
||||
pathfs.writeFile(
|
||||
toolScriptsDir:join("roblox_sync_config_generator.luau"),
|
||||
syncConfigGeneratorScript
|
||||
)
|
||||
pathfs.writeFile(
|
||||
toolScriptsDir:join("sourcemap_generator.luau"),
|
||||
sourcemapGeneratorScript
|
||||
)
|
||||
pathfs.writeFile(
|
||||
toolScriptsDir:join("README.md"),
|
||||
string.format(README_TMPL, toolChoice, capitalisedToolChoice, capitalisedToolChoice)
|
||||
string.format(
|
||||
README_TMPL,
|
||||
toolChoice,
|
||||
capitalisedToolChoice,
|
||||
capitalisedToolChoice
|
||||
)
|
||||
)
|
||||
pathfs.copy(
|
||||
pathfs.cwd:join("LICENSE"),
|
||||
toolScriptsDir:join("LICENSE"),
|
||||
true
|
||||
)
|
||||
pathfs.copy(pathfs.cwd:join("LICENSE"), toolScriptsDir:join("LICENSE"), true)
|
||||
|
||||
stdio.write(
|
||||
`{INFO_PREFIX} Generated script project for tool {toolChoice} ({stdio.style("dim")}{string.format(
|
||||
"%.2fms",
|
||||
(os.clock() - startTime) * 1000
|
||||
)}{stdio.style("reset")})\n`
|
||||
`{INFO_PREFIX} Generated script project for tool {toolChoice} ({stdio.style(
|
||||
"dim"
|
||||
)}{string.format("%.2fms", (os.clock() - startTime) * 1000)}{stdio.style(
|
||||
"reset"
|
||||
)})\n`
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,4 +4,10 @@ local process = require("@lune/process")
|
|||
|
||||
local CommandBuilder = require("./lib/exec")
|
||||
|
||||
process.exit(CommandBuilder.new("stylua"):withArg("."):withArgs(process.args):withStdioStrategy("forward"):exec().code)
|
||||
process.exit(
|
||||
CommandBuilder.new("stylua")
|
||||
:withArg(".")
|
||||
:withArgs(process.args)
|
||||
:withStdioStrategy("forward")
|
||||
:exec().code
|
||||
)
|
||||
|
|
|
@ -5,7 +5,10 @@ local stdio = require("@lune/stdio")
|
|||
|
||||
local CommandBuilder = {}
|
||||
|
||||
export type CommandBuilder = typeof(setmetatable({} :: CommandBuilderFields, { __index = CommandBuilder }))
|
||||
export type CommandBuilder = typeof(setmetatable(
|
||||
{} :: CommandBuilderFields,
|
||||
{ __index = CommandBuilder }
|
||||
))
|
||||
type CommandBuilderFields = {
|
||||
program: string,
|
||||
args: { string },
|
||||
|
@ -34,12 +37,18 @@ function CommandBuilder.new(program: string)
|
|||
)
|
||||
end
|
||||
|
||||
function CommandBuilder.withArg(self: CommandBuilder, arg: string): CommandBuilder
|
||||
function CommandBuilder.withArg(
|
||||
self: CommandBuilder,
|
||||
arg: string
|
||||
): CommandBuilder
|
||||
table.insert(self.args, arg)
|
||||
return self
|
||||
end
|
||||
|
||||
function CommandBuilder.withArgs(self: CommandBuilder, args: { string }): CommandBuilder
|
||||
function CommandBuilder.withArgs(
|
||||
self: CommandBuilder,
|
||||
args: { string }
|
||||
): CommandBuilder
|
||||
for _, arg in args do
|
||||
self:withArg(arg)
|
||||
end
|
||||
|
@ -60,7 +69,9 @@ function CommandBuilder.withStdioStrategy(
|
|||
return self
|
||||
end
|
||||
|
||||
local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.SpawnOptionsStdioKind
|
||||
local function intoSpawnOptionsStdioKind(
|
||||
strategy: StdioStrategy
|
||||
): process.SpawnOptionsStdioKind
|
||||
if strategy == "pipe" then
|
||||
return "default"
|
||||
end
|
||||
|
@ -77,7 +88,11 @@ local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.Spawn
|
|||
end
|
||||
|
||||
function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult
|
||||
print("$", stdio.style("dim") .. self.program, table.concat(self.args, " ") .. stdio.style("reset"))
|
||||
print(
|
||||
"$",
|
||||
stdio.style("dim") .. self.program,
|
||||
table.concat(self.args, " ") .. stdio.style("reset")
|
||||
)
|
||||
|
||||
local function translateIoStrategyMappings(mappings: IoStrategyMapping)
|
||||
local translatedMappings: process.SpawnOptionsStdio = {}
|
||||
|
@ -90,11 +105,16 @@ function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult
|
|||
|
||||
local child = process.spawn(self.program, self.args, {
|
||||
shell = true,
|
||||
stdio = translateIoStrategyMappings(self.stdioStrategy or DEFAULT_STDIO_STRATEGY),
|
||||
stdio = translateIoStrategyMappings(
|
||||
self.stdioStrategy or DEFAULT_STDIO_STRATEGY
|
||||
),
|
||||
})
|
||||
|
||||
if not child.ok then
|
||||
print(`\n{stdio.color("red")}[luau-lsp]{stdio.color("reset")} Exited with code`, child.code)
|
||||
print(
|
||||
`\n{stdio.color("red")}[luau-lsp]{stdio.color("reset")} Exited with code`,
|
||||
child.code
|
||||
)
|
||||
end
|
||||
|
||||
return child
|
||||
|
|
|
@ -22,14 +22,21 @@ export type SPDXLicense =
|
|||
| "EPL-2.0"
|
||||
| "AGPL-3.0"
|
||||
|
||||
export type DependencySpecifier = ((
|
||||
{ name: string, version: string, index: string? }
|
||||
| { workspace: string, version: string }
|
||||
) & {
|
||||
export type DependencySpecifier = (({
|
||||
name: string,
|
||||
version: string,
|
||||
index: string?,
|
||||
} | { workspace: string, version: string }) & {
|
||||
target: string?,
|
||||
})
|
||||
| { wally: string, version: string, index: string? }
|
||||
| { repo: string, rev: string, path: string? }
|
||||
}) | {
|
||||
wally: string,
|
||||
version: string,
|
||||
index: string?,
|
||||
} | {
|
||||
repo: string,
|
||||
rev: string,
|
||||
path: string?,
|
||||
}
|
||||
|
||||
export type PackageTarget = {
|
||||
environment: "roblox" | "roblox_server",
|
||||
|
|
|
@ -72,7 +72,9 @@ for _, test in discoverTests("src") do
|
|||
constructors.suite = frktest.test.skip.suite
|
||||
end
|
||||
|
||||
require(`../../{test}`)(setmetatable(constructors, { __index = frktest.test }))
|
||||
require(`../../{test}`)(
|
||||
setmetatable(constructors, { __index = frktest.test })
|
||||
)
|
||||
end
|
||||
|
||||
reporter.init()
|
||||
|
|
|
@ -7,18 +7,28 @@ local watch = require("../lib/channel")
|
|||
|
||||
local STYLE = table.freeze({
|
||||
suite = function(name: string)
|
||||
return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style("reset")} {name}`
|
||||
return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style(
|
||||
"reset"
|
||||
)} {name}`
|
||||
end,
|
||||
|
||||
report = function(name: string, state: "success" | "error" | "skip", elapsed: number)
|
||||
report = function(
|
||||
name: string,
|
||||
state: "success" | "error" | "skip",
|
||||
elapsed: number
|
||||
)
|
||||
local state_color: stdio.Color = if state == "success"
|
||||
then "green"
|
||||
elseif state == "error" then "red"
|
||||
elseif state == "skip" then "yellow"
|
||||
else error("Invalid test state")
|
||||
return ` {stdio.style("bold")}{stdio.color(state_color)}{if state == "skip" then "SKIP" else "TEST"}{stdio.style(
|
||||
"reset"
|
||||
)} {name} [{stdio.style("dim")}{string.format("%.2fms", elapsed)}{stdio.style("reset")}]`
|
||||
return ` {stdio.style("bold")}{stdio.color(state_color)}{if state
|
||||
== "skip"
|
||||
then "SKIP"
|
||||
else "TEST"}{stdio.style("reset")} {name} [{stdio.style("dim")}{string.format(
|
||||
"%.2fms",
|
||||
elapsed
|
||||
)}{stdio.style("reset")}]`
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
@ -16,10 +16,14 @@ local PATH_ACTION_MAP: { [string]: (dir: string) -> number? } = {
|
|||
end,
|
||||
|
||||
["init.lua"] = function()
|
||||
return stdio.write(serde.encode("json", { filePaths = { "init.lua" } }, false))
|
||||
return stdio.write(
|
||||
serde.encode("json", { filePaths = { "init.lua" } }, false)
|
||||
)
|
||||
end,
|
||||
["init.luau"] = function()
|
||||
return stdio.write(serde.encode("json", { filePaths = { "init.luau" } }, false))
|
||||
return stdio.write(
|
||||
serde.encode("json", { filePaths = { "init.luau" } }, false)
|
||||
)
|
||||
end,
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,24 @@ local BUILTIN_PATCHES: {
|
|||
[string]: { [string]: (...any) -> ...any? },
|
||||
} = {
|
||||
["@lune/process"] = {
|
||||
spawn = function(program: string, params: { string }, options: process.SpawnOptions): process.SpawnResult
|
||||
spawn = function(
|
||||
program: string,
|
||||
params: { string },
|
||||
options: process.SpawnOptions
|
||||
): process.SpawnResult
|
||||
local patchedOptions: process.SpawnOptions = options or {}
|
||||
patchedOptions.stdio = "default"
|
||||
|
||||
local result = process.spawn(program, params, patchedOptions)
|
||||
|
||||
-- First we make sure the command exited properly
|
||||
assert(result.ok, `Expected \`rojo\` command to not error, got:\n{string.rep(" ", 6)}{result.stderr}`)
|
||||
assert(
|
||||
result.ok,
|
||||
`Expected \`rojo\` command to not error, got:\n{string.rep(
|
||||
" ",
|
||||
6
|
||||
)}{result.stderr}`
|
||||
)
|
||||
|
||||
-- We also make sure that the output JSON was valid
|
||||
serde.decode("json", result.stdout)
|
||||
|
@ -54,7 +64,9 @@ local function requireWithPatches(path: string)
|
|||
end
|
||||
|
||||
return function(test: typeof(frktest.test))
|
||||
test.suite("Generates Rojo sourcemaps for test projects successfully", function()
|
||||
test.suite(
|
||||
"Generates Rojo sourcemaps for test projects successfully",
|
||||
function()
|
||||
for _, file in fs.readDir(TEST_PROJECTS_DIR) do
|
||||
if table.find(TEST_PROJECT_EXCLUDES, file) then
|
||||
-- It does not make sense to test sourcemap generation for some of the test projects
|
||||
|
@ -65,23 +77,30 @@ return function(test: typeof(frktest.test))
|
|||
test.case(file, function()
|
||||
-- If a file starts with `bad_` but not `bad_meta_`, we should expect a failure
|
||||
-- Also, sorry about this shitty regex, regex-rs does not support look-around :(
|
||||
local isBadMeta = regex.new("^bad_[^m]|^bad_m[^e]|^bad_me[^t]|^bad_met[^a]")
|
||||
local expect = if isBadMeta:isMatch(file) then check.should_error else check.should_not_error
|
||||
local isBadMeta = regex.new(
|
||||
"^bad_[^m]|^bad_m[^e]|^bad_me[^t]|^bad_met[^a]"
|
||||
)
|
||||
local expect = if isBadMeta:isMatch(file)
|
||||
then check.should_error
|
||||
else check.should_not_error
|
||||
|
||||
expect(function()
|
||||
-- We override the require which applies some patches to some builtins, mainly preventing
|
||||
-- command stdout forwarding and `stdio.write` outputs to stdout in order to not fill
|
||||
-- test ouput with large amounts of JSON data
|
||||
local sourcemap: (string) -> boolean =
|
||||
luau.load(fs.readFile("./src/generators/rojo/sourcemap.luau"), {
|
||||
local sourcemap: (string) -> boolean = luau.load(
|
||||
fs.readFile("./src/generators/rojo/sourcemap.luau"),
|
||||
{
|
||||
environment = {
|
||||
require = requireWithPatches,
|
||||
},
|
||||
})()
|
||||
}
|
||||
)()
|
||||
|
||||
return check.is_true(sourcemap(testProject))
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
|
|
@ -65,7 +65,8 @@ return function(
|
|||
}
|
||||
): (boolean, string?)
|
||||
packageDirectory = packageDirectory or process.cwd
|
||||
local syncConfigPath = `{packageDirectory}{PLATFORM_SEP}default.project.json`
|
||||
local syncConfigPath =
|
||||
`{packageDirectory}{PLATFORM_SEP}default.project.json`
|
||||
if fs.isFile(syncConfigPath) and not options.force then
|
||||
return true, nil
|
||||
end
|
||||
|
@ -104,7 +105,8 @@ return function(
|
|||
|
||||
-- Finally, we serialize the config to a JSON string and optionally write it
|
||||
-- to the sync config path
|
||||
local serializedConfig = serde.encode("json", { tree = syncConfigTree }, true)
|
||||
local serializedConfig =
|
||||
serde.encode("json", { tree = syncConfigTree }, true)
|
||||
if options.writeToFile then
|
||||
fs.writeFile(syncConfigPath, serializedConfig)
|
||||
end
|
||||
|
|
|
@ -17,13 +17,20 @@ return function(test: typeof(frktest.test))
|
|||
for _, file in fs.readDir(dir) do
|
||||
local fullPath = `{dir}/{file}`
|
||||
test.case(`{file}`, function()
|
||||
local ok, config = syncConfig(fullPath, fs.readDir(fullPath), { writeToFile = false, force = true })
|
||||
local ok, config = syncConfig(
|
||||
fullPath,
|
||||
fs.readDir(fullPath),
|
||||
{ writeToFile = false, force = true }
|
||||
)
|
||||
check.is_true(ok)
|
||||
|
||||
-- Make sure that the generated config and the real configs are similar
|
||||
local generatedConfig, realConfig =
|
||||
serde.decode("json", config),
|
||||
serde.decode("json", fs.readFile(`{fullPath}/default.project.json`))
|
||||
serde.decode(
|
||||
"json",
|
||||
fs.readFile(`{fullPath}/default.project.json`)
|
||||
)
|
||||
|
||||
check.table.contains(realConfig, generatedConfig)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue