chore(lune): set repo for generated manifest correctly

Also applies the stylua formatter to the file.
This commit is contained in:
Erica Marigold 2024-12-08 11:38:22 +00:00
parent 22552c0f80
commit e3889bffb1
Signed by: DevComp
GPG key ID: 429EF1C337871656

View file

@ -1,164 +1,164 @@
--> Generates sync config and sourcemap scripts for supported tools --> Generates sync config and sourcemap scripts for supported tools
local process = require("@lune/process") local process = require("@lune/process")
local serde = require("@lune/serde") local serde = require("@lune/serde")
local stdio = require("@lune/stdio") local stdio = require("@lune/stdio")
local task = require("@lune/task") local task = require("@lune/task")
local lib = require("../src") local lib = require("../src")
local manifest = require("./lib/manifest") local manifest = require("./lib/manifest")
local pathfs = require("../lune_packages/pathfs") local pathfs = require("../lune_packages/pathfs")
type ToolChoice = "rojo" type ToolChoice = "rojo"
type ManifestExt = { type ManifestExt = {
scripts: { scripts: {
[ToolChoice]: { [ToolChoice]: {
version: string, version: string,
tool_dependencies: { { [string]: manifest.DependencySpecifier } }, tool_dependencies: { { [string]: manifest.DependencySpecifier } },
}, },
}, },
} }
local SCRIPTS_DIR = pathfs.getAbsolutePathOf(pathfs.Path.from(".pesde")) local SCRIPTS_DIR = pathfs.getAbsolutePathOf(pathfs.Path.from(".pesde"))
local MANIFEST = manifest(nil, (nil :: any) :: { meta: ManifestExt }) local MANIFEST = manifest(nil, (nil :: any) :: { meta: ManifestExt })
local SCRIPTS = { local SCRIPTS = {
syncConfigGenerator = [[local process = require("@lune/process") syncConfigGenerator = [[local process = require("@lune/process")
local args = table.clone(process.args) local args = table.clone(process.args)
local ok, _ = local ok, _ =
require("./lune_packages/core").generators.%s.syncConfig(table.remove(args, 1), args, { writeToFile = true }) require("./lune_packages/core").generators.%s.syncConfig(table.remove(args, 1), args, { writeToFile = true })
process.exit(tonumber(ok))]], process.exit(tonumber(ok))]],
sourcemapGenerator = [[local process = require("@lune/process") sourcemapGenerator = [[local process = require("@lune/process")
return process.exit( return process.exit(
tonumber(require("./lune_packages/core").generators.%s.sourcemap(process.args[1])) tonumber(require("./lune_packages/core").generators.%s.sourcemap(process.args[1]))
)]], )]],
} }
local function logPrefix(type: "error" | "info") local function logPrefix(type: "error" | "info")
local statusColor: stdio.Color = if type == "error" local statusColor: stdio.Color = if type == "error"
then "red" then "red"
elseif type == "info" then "green" elseif type == "info" then "green"
else error(`Invalid type: {type}`) else error(`Invalid type: {type}`)
return `pesde::{stdio.style("bold")}{stdio.color(statusColor)}{type}{stdio.color("reset")}` return `pesde::{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 STDOUT_LINE_PREFIX = `[pesde::{logPrefix("info")}]` local STDOUT_LINE_PREFIX = `[pesde::{logPrefix("info")}]`
local PESDE_ERROR_PREFIX = `[pesde::{logPrefix("error")}]` local PESDE_ERROR_PREFIX = `[pesde::{logPrefix("error")}]`
local SPINNER_STATES = { '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏' } local SPINNER_STATES = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
stdio.write(`{STDOUT_LINE_PREFIX} Installing dependencies with pesde`) stdio.write(`{STDOUT_LINE_PREFIX} Installing dependencies with pesde`)
-- Spawn our thread to display the spinner -- Spawn our thread to display the spinner
local spinnerThread = task.spawn(function() local spinnerThread = task.spawn(function()
-- Hide the cursor -- Hide the cursor
stdio.write("\x1b[?25l") stdio.write("\x1b[?25l")
-- Display the spinner -- Display the spinner
while true do while true do
for _, state in SPINNER_STATES do for _, state in SPINNER_STATES do
stdio.write(` {state}`) stdio.write(` {state}`)
stdio.write( stdio.write(
-- Moves the cursor back 1 spot and clears everything after -- Moves the cursor back 1 spot and clears everything after
"\x1b[2D\x1b[0K" "\x1b[2D\x1b[0K"
) )
end end
end end
end) end)
-- `process_spawn` is an async rust function, so tokio spawns a hardware -- `process_spawn` is an async rust function, so tokio spawns a hardware
-- thread and mlua will yield the current thread, allowing for `spinnerThread` -- thread and mlua will yield the current thread, allowing for `spinnerThread`
-- to continue executing -- to continue executing
local child = process.spawn("pesde", { "install" }, { local child = process.spawn("pesde", { "install" }, {
stdio = "default", stdio = "default",
}) })
-- If we reach this point, that means mlua resumed the current thread and -- If we reach this point, that means mlua resumed the current thread and
-- `process_spawn` returned or errored. We can now close `spinnerThread` and -- `process_spawn` returned or errored. We can now close `spinnerThread` and
-- clean up -- clean up
task.cancel(spinnerThread) task.cancel(spinnerThread)
stdio.write( stdio.write(
-- Clear the current line, move cursor back to its beginning and -- Clear the current line, move cursor back to its beginning and
-- show it -- show it
"\x1b[2K\x1b[1G\x1b[?25h" "\x1b[2K\x1b[1G\x1b[?25h"
) )
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(`{STDOUT_LINE_PREFIX} Installed dependencies with pesde successfully\n`) stdio.write(`{STDOUT_LINE_PREFIX} Installed dependencies with pesde successfully\n`)
return child.code return child.code
end end
for tool, generators in lib.generators do for tool, generators in lib.generators do
local startTime = os.clock() local startTime = os.clock()
-- For each tool, we generate a respective manifests and scripts -- For each tool, we generate a respective manifests and scripts
local toolChoice = tool :: ToolChoice local toolChoice = tool :: ToolChoice
local toolScriptsDir = SCRIPTS_DIR:join(toolChoice) local toolScriptsDir = SCRIPTS_DIR:join(toolChoice)
local toolMeta = MANIFEST.meta.scripts[toolChoice] local toolMeta = MANIFEST.meta.scripts[toolChoice]
if not pathfs.isDir(toolScriptsDir) then if not pathfs.isDir(toolScriptsDir) then
pathfs.writeDir(toolScriptsDir) pathfs.writeDir(toolScriptsDir)
end end
-- Define the manifest for the tool -- Define the manifest for the tool
local toolManifest: manifest.PesdeManifest = { local toolManifest: manifest.PesdeManifest = {
name = `pesde/scripts_{toolChoice}`, name = `pesde/scripts_{toolChoice}`,
version = toolMeta.version, version = toolMeta.version,
description = `Scripts for {toolChoice}-based Roblox projects`, description = `Scripts for {toolChoice}-based Roblox projects`,
authors = { authors = {
"dai <contact@daimond113.com> (https://www.daimond113.com/)", "dai <contact@daimond113.com> (https://www.daimond113.com/)",
"Erica Marigold <hi@devcomp.xyz>", "Erica Marigold <hi@devcomp.xyz>",
}, },
repository = `https://github.com/pesde-pkg/scripts/tree/master/.pesde/{toolChoice}`, repository = "https://github.com/pesde-pkg/scripts",
license = "MIT", license = "MIT",
target = { target = {
environment = "lune", environment = "lune",
scripts = { scripts = {
roblox_sync_config_generator = "roblox_sync_config_generator.luau", roblox_sync_config_generator = "roblox_sync_config_generator.luau",
sourcemap_generator = "sourcemap_generator.luau", sourcemap_generator = "sourcemap_generator.luau",
}, },
}, },
peer_dependencies = toolMeta.tool_dependencies, peer_dependencies = toolMeta.tool_dependencies,
dependencies = { dependencies = {
core = { workspace = "pesde/scripts_core", version = "^" }, core = { workspace = "pesde/scripts_core", version = "^" },
}, },
indices = { indices = {
default = "https://github.com/pesde-pkg/index", default = "https://github.com/pesde-pkg/index",
}, },
} }
-- 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(toolScriptsDir:join("pesde.toml"), serde.encode("toml", toolManifest, true))
pathfs.writeFile(toolScriptsDir:join("roblox_sync_config_generator.luau"), syncConfigGeneratorScript) pathfs.writeFile(toolScriptsDir:join("roblox_sync_config_generator.luau"), syncConfigGeneratorScript)
pathfs.writeFile(toolScriptsDir:join("sourcemap_generator.luau"), sourcemapGeneratorScript) pathfs.writeFile(toolScriptsDir:join("sourcemap_generator.luau"), sourcemapGeneratorScript)
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("dim")}{string.format(
"%.2fs", "%.2fs",
os.clock() - startTime os.clock() - startTime
)}{stdio.style("reset")}]\n` )}{stdio.style("reset")}]\n`
) )
-- Now we install the dependencies for the newly created projects -- Now we install the dependencies for the newly created projects
process.exit(installDeps()) process.exit(installDeps())
end end