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