style: apply stylua formatter

This commit is contained in:
Erica Marigold 2024-12-02 16:57:31 +00:00
parent e019e5a8ed
commit 51994dfd13
Signed by: DevComp
GPG key ID: 429EF1C337871656
3 changed files with 109 additions and 97 deletions

View file

@ -12,32 +12,36 @@ local PLATFORM_SEP = if process.os == "windows" then "\\" else "/"
--- * The current process lacks permissions to a file --- * The current process lacks permissions to a file
--- * Any I/O error occurs --- * Any I/O error occurs
return function(packageDirectory: string?): boolean return function(packageDirectory: string?): boolean
packageDirectory = packageDirectory or process.cwd packageDirectory = packageDirectory or process.cwd
-- A mapping of things to do depending on the file present
local PATH_ACTION_MAP: { [string]: (dir: string) -> number? } = {
["default.project.json"] = function(dir)
return process.spawn("rojo", { "sourcemap", dir }, {
cwd = process.cwd,
env = process.env,
stdio = "forward",
}).code
end,
["init.lua"] = stdio.write(serde.encode("json", { filePaths = { "init.lua" } }, false)), -- A mapping of things to do depending on the file present
["init.luau"] = stdio.write(serde.encode("json", { filePaths = { "init.luau" } }, false)), local PATH_ACTION_MAP: { [string]: (dir: string) -> number? } = {
} ["default.project.json"] = function(dir)
return process.spawn("rojo", { "sourcemap", dir }, {
cwd = process.cwd,
env = process.env,
stdio = "forward",
}).code
end,
-- We go through the action mappings in order of priority and check for the ["init.lua"] = stdio.write(
-- file predicates, if present, we execute the action and report our status serde.encode("json", { filePaths = { "init.lua" } }, false)
for path, action in PATH_ACTION_MAP do ),
if fs.isFile(`{packageDirectory}{PLATFORM_SEP}{path}`) then ["init.luau"] = stdio.write(
local status = action() serde.encode("json", { filePaths = { "init.luau" } }, false)
return if status ~= nil then status == 0 else true ),
end }
end
-- If we reached so far, that must mean none of the file predicates matched, -- We go through the action mappings in order of priority and check for the
-- so we return a `false` signifying an error -- file predicates, if present, we execute the action and report our status
return false for path, action in PATH_ACTION_MAP do
if fs.isFile(`{packageDirectory}{PLATFORM_SEP}{path}`) then
local status = action()
return if status ~= nil then status == 0 else true
end
end
-- If we reached so far, that must mean none of the file predicates matched,
-- so we return a `false` signifying an error
return false
end end

View file

@ -3,102 +3,110 @@ local process = require("@lune/process")
local serde = require("@lune/serde") local serde = require("@lune/serde")
export type TreeProperties = { export type TreeProperties = {
Name: never?, Name: never?,
Parent: never?, Parent: never?,
} }
export type TreeBase = { export type TreeBase = {
["$className"]: string?, ["$className"]: string?,
["$ignoreUnknownInstances"]: boolean?, ["$ignoreUnknownInstances"]: boolean?,
["$path"]: string | { optional: string }?, ["$path"]: string | { optional: string }?,
["$properties"]: TreeProperties?, ["$properties"]: TreeProperties?,
} }
export type TreeNormal = TreeBase & { export type TreeNormal = TreeBase & {
[string]: TreeNormal, [string]: TreeNormal,
} & ({ ["$className"]: string } | { ["$path"]: string | { optional: string } }) } & ({ ["$className"]: string } | {
["$path"]: string | { optional: string },
})
export type TreeService = TreeBase & { export type TreeService = TreeBase & {
[string]: TreeNormal, [string]: TreeNormal,
} }
export type DataModelTree = TreeBase & { export type DataModelTree = TreeBase & {
StarterPlayer: (TreeBase & { StarterPlayer: (TreeBase & {
StarterPlayerScripts: TreeService?, StarterPlayerScripts: TreeService?,
StarterCharacterScripts: TreeService?, StarterCharacterScripts: TreeService?,
[string]: TreeNormal, [string]: TreeNormal,
})?, })?,
[string]: TreeService, [string]: TreeService,
} }
export type Tree = (DataModelTree & { export type Tree = (DataModelTree & {
["$className"]: "DataModel", ["$className"]: "DataModel",
}) | TreeNormal }) | TreeNormal
export type SyncConfig = { export type SyncConfig = {
name: string, name: string,
servePort: number?, servePort: number?,
servePlaceIds: { number }?, servePlaceIds: { number }?,
placeId: number?, placeId: number?,
gameId: number?, gameId: number?,
serveAddress: string?, serveAddress: string?,
globIgnorePaths: { string }?, globIgnorePaths: { string }?,
tree: Tree, tree: Tree,
} }
local PLATFORM_SEP = if process.os == "windows" then "\\" else "/" local PLATFORM_SEP = if process.os == "windows" then "\\" else "/"
--- Generates a Rojo sync configuration file (`default.project.json`) from a list of --- Generates a Rojo sync configuration file (`default.project.json`) from a list of
--- input files to be included. --- input files to be included.
--- ## Errors --- ## Errors
--- * The current process lacks permissions to a file --- * The current process lacks permissions to a file
--- * Any I/O error occurs --- * Any I/O error occurs
return function(packageDirectory: string?, files: { string }, writeToFile: boolean?): (boolean, string?) return function(
packageDirectory = packageDirectory or process.cwd packageDirectory: string?,
local syncConfigPath = `{packageDirectory}{PLATFORM_SEP}default.project.json` files: { string },
if fs.isFile(syncConfigPath) then writeToFile: boolean?
return true, nil ): (boolean, string?)
end packageDirectory = packageDirectory or process.cwd
local syncConfigPath =
`{packageDirectory}{PLATFORM_SEP}default.project.json`
if fs.isFile(syncConfigPath) then
return true, nil
end
local syncConfigTree = {} :: Tree local syncConfigTree = {} :: Tree
for _, file in files do for _, file in files do
-- Remove the `.lua` or `.luau` file extension from the file name -- Remove the `.lua` or `.luau` file extension from the file name
local name = string.gsub(file, ".luau?$", "") local name = string.gsub(file, ".luau?$", "")
if name == "init" then if name == "init" then
syncConfigTree["$path"] = name syncConfigTree["$path"] = name
continue continue
end end
syncConfigTree[name] = { syncConfigTree[name] = {
["$path"] = file, ["$path"] = file,
} }
end end
-- If there isn't a top level path, we mark the entire thing as a Folder -- If there isn't a top level path, we mark the entire thing as a Folder
if not syncConfigTree["$path"] then if not syncConfigTree["$path"] then
syncConfigTree["$className"] = "Folder" syncConfigTree["$className"] = "Folder"
end end
-- If the config tree does not include pesde's downloaded roblox dependencies -- If the config tree does not include pesde's downloaded roblox dependencies
-- directory, we add it as an optional one for the future, once dependencies -- directory, we add it as an optional one for the future, once dependencies
-- are installed -- are installed
if not syncConfigTree["roblox_packages"] then if not syncConfigTree["roblox_packages"] then
syncConfigTree["roblox_packages"] = { syncConfigTree["roblox_packages"] = {
["$path"] = { ["$path"] = {
optional = "roblox_packages", optional = "roblox_packages",
}, },
} }
end end
-- 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 =
if writeToFile then serde.encode("json", { tree = syncConfigTree }, true)
fs.writeFile(syncConfigPath, serializedConfig) if writeToFile then
end fs.writeFile(syncConfigPath, serializedConfig)
end
return true, serializedConfig return true, serializedConfig
end end

View file

@ -1,8 +1,8 @@
return { return {
generators = { generators = {
rojo = { rojo = {
sourcemap = require("./generators/rojo/sourcemap"), sourcemap = require("./generators/rojo/sourcemap"),
syncConfig = require("./generators/rojo/sync_config"), syncConfig = require("./generators/rojo/sync_config"),
}, },
}, },
} }