refactor: restructure to use script package system

General restructuring
=====================
* Restructures to workspace with script packages for each tool choice.
* Include build script to generate package for every supported tool
  choice in library into the `.pesde/` directory.
* Remove testing .lune scripts for Rojo.

Manifest changes
================
* Exclude `.spec.luau` test files for library package.
* Include .pesde directory for library package.
* Add pathfs dev-dependency.
* Include metadata for build script package codegen.
* Use new git URL for index repo.
* Setup workspace including top level itself & tool choice script packages.

These changes require an unstable version of pesde: 2b2d280fe0.
This commit is contained in:
Erica Marigold 2024-12-08 11:09:53 +00:00
parent e203656294
commit 22552c0f80
Signed by: DevComp
GPG key ID: 429EF1C337871656
10 changed files with 291 additions and 52 deletions

7
.gitignore vendored
View file

@ -1,2 +1,7 @@
# Pesde packages
*_packages/
pesde.lock
pesde.lock
# Generated scripts
.pesde/*
!.pesde/.gitkeep

164
.lune/build.luau Normal file
View file

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

71
.lune/lib/manifest.luau Normal file
View file

@ -0,0 +1,71 @@
local fs = require("@lune/fs")
local serde = require("@lune/serde")
export type SPDXLicense =
"MIT"
| "Apache-2.0"
| "BSD-2-Clause"
| "BSD-3-Clause"
| "GPL-2.0"
| "GPL-3.0"
| "LGPL-2.1"
| "LGPL-3.0"
| "MPL-2.0"
| "ISC"
| "Unlicense"
| "WTFPL"
| "Zlib"
| "CC0-1.0"
| "CC-BY-4.0"
| "CC-BY-SA-4.0"
| "BSL-1.0"
| "EPL-2.0"
| "AGPL-3.0"
export type DependencySpecifier = ((
{ name: string, version: string, index: string? }
| { workspace: string, version: string }
| { repo: string, rev: string, path: string? }
) & {
target: string?,
}) | { wally: string, version: string, index: string? }
export type PackageTarget = {
environment: "luau" | "lune" | "roblox" | "roblox_server",
lib: string,
} | ({ environment: "luau" | "lune" } & ({
bin: string,
} | {
scripts: { [string]: string },
}))
export type PesdeManifest<T = {}> = {
name: string,
version: string,
description: string?,
license: SPDXLicense?,
authors: { string }?,
repository: string?,
private: boolean?,
includes: { string }?,
pesde_version: string?,
workspace_members: { string }?,
target: PackageTarget,
build_files: { string }?,
scripts: { [string]: string }?,
indices: { [string]: string },
wally_indices: { [string]: string }?,
overrides: { [string]: DependencySpecifier }?,
patches: { [string]: { [string]: string } }?,
place: { [string]: string }?,
dependencies: { [string]: DependencySpecifier }?,
peer_dependencies: { [string]: DependencySpecifier }?,
dev_dependencies: { [string]: DependencySpecifier }?,
} & T
return function<T>(path: string?, _phantom: T): PesdeManifest<T>
local manifestContents = fs.readFile(path or "pesde.toml")
local decoded = serde.decode("toml", manifestContents)
return decoded :: PesdeManifest<T>
end

View file

@ -1,19 +0,0 @@
--> Generates a Rojo sync config from a list of input files
local function enter(fn: (args: { string }) -> number?): never
local process = require("@lune/process")
local stdio = require("@lune/stdio")
local startTime = os.clock()
local exitCode = fn(table.clone(process.args))
stdio.write(`done in {stdio.style("dim")}{string.format("%.2fs", os.clock() - startTime)}{stdio.style("reset")}!\n`)
return process.exit(exitCode)
end
return enter(function(args: { string }): number?
local ok, _ = require("../src").generators.rojo.syncConfig(table.remove(args, 1), args, { writeToFile = true })
return tonumber(ok)
end)

View file

@ -1,21 +0,0 @@
--> Generates a Rojo sourcemap for a provided project directory
local function enter(fn: (args: { string }) -> number?): never
local process = require("@lune/process")
local stdio = require("@lune/stdio")
local startTime = os.clock()
local exitCode = fn(table.clone(process.args))
stdio.ewrite(
`\ndone in {stdio.style("dim")}{string.format("%.2fs", os.clock() - startTime)}{stdio.style("reset")}!\n`
)
return process.exit(exitCode)
end
return enter(function(args: { string }): number?
return tonumber(require("../src").generators.rojo.sourcemap(
args[1]
))
end)

0
.pesde/.gitkeep Normal file
View file

View file

@ -2,5 +2,6 @@
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.8.9/"
}
},
"stylua.targetReleaseVersion": "latest"
}

View file

@ -1,7 +1,13 @@
name = "pesde/scripts"
name = "pesde/scripts_core"
version = "0.1.0"
target = "lune"
[workspace."pesde/scripts_core"]
lune = ""
[workspace."pesde/scripts_rojo"]
lune = ".pesde/rojo"
[graph."itsfrank/frktest"."0.0.2 lune"]
direct = ["frktest", { name = "itsfrank/frktest", version = "^0.0.2" }, "dev"]
resolved_ty = "dev"
@ -19,3 +25,21 @@ index_url = "https://github.com/daimond113/pesde-index"
[graph."itsfrank/frktest"."0.0.2 lune".pkg_ref.target]
environment = "lune"
lib = "src/_pesde_init.luau"
[graph."jiwonz/pathfs"."0.1.0 lune"]
direct = ["pathfs", { name = "jiwonz/pathfs", version = "^0.1.0" }, "dev"]
resolved_ty = "dev"
[graph."jiwonz/pathfs"."0.1.0 lune".target]
environment = "lune"
lib = "init.luau"
[graph."jiwonz/pathfs"."0.1.0 lune".pkg_ref]
ref_ty = "pesde"
name = "jiwonz/pathfs"
version = "0.1.0"
index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/pathfs"."0.1.0 lune".pkg_ref.target]
environment = "lune"
lib = "init.luau"

View file

@ -1,21 +1,35 @@
name = "pesde/scripts"
name = "pesde/scripts_core"
version = "0.1.0"
pesde_version = "0.5.0-rc.14"
description = "Scripts and other utilities for use with pesde"
authors = ["dai <contact@daimond113.com> (https://www.daimond113.com/)", "Erica Marigold <hi@devcomp.xyz>"]
authors = [
"dai <contact@daimond113.com> (https://www.daimond113.com/)",
"Erica Marigold <hi@devcomp.xyz>",
]
repository = "https://github.com/pesde-pkg/scripts"
license = "MIT"
includes = ["src/**/*.luau", "pesde.toml", "README.md", "LICENSE.md"]
includes = [
"src/**/*.luau",
"!src/**/*.spec.luau",
".pesde",
"pesde.toml",
"README.md",
"LICENSE.md",
]
[meta]
scripts_root = ".lune"
workspace_members = [".", ".pesde/rojo"]
[meta.scripts.rojo]
version = "0.1.0"
tool_dependencies = { rojo = { name = "pesde/rojo", version = "^7.4.4" } }
[target]
environment = "lune"
lib = "src/init.luau"
[indices]
default = "https://github.com/daimond113/pesde-index"
[dev_dependencies]
frktest = { name = "itsfrank/frktest", version = "^0.0.2" }
pathfs = { name = "jiwonz/pathfs", version = "^0.1.0" }
[indices]
default = "https://github.com/pesde-pkg/index"

View file

@ -5,4 +5,4 @@ return {
syncConfig = require("./generators/rojo/sync_config"),
},
},
}
}