From 51994dfd1337465e7bf6512899dba9af0b0bf938 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Mon, 2 Dec 2024 16:57:31 +0000 Subject: [PATCH] style: apply stylua formatter --- src/generators/rojo/sourcemap.luau | 54 ++++++----- src/generators/rojo/sync_config.luau | 136 ++++++++++++++------------- src/init.luau | 16 ++-- 3 files changed, 109 insertions(+), 97 deletions(-) diff --git a/src/generators/rojo/sourcemap.luau b/src/generators/rojo/sourcemap.luau index d451b24..4d716b1 100644 --- a/src/generators/rojo/sourcemap.luau +++ b/src/generators/rojo/sourcemap.luau @@ -12,32 +12,36 @@ local PLATFORM_SEP = if process.os == "windows" then "\\" else "/" --- * The current process lacks permissions to a file --- * Any I/O error occurs return function(packageDirectory: string?): boolean - 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, + packageDirectory = packageDirectory or process.cwd - ["init.lua"] = stdio.write(serde.encode("json", { filePaths = { "init.lua" } }, false)), - ["init.luau"] = stdio.write(serde.encode("json", { filePaths = { "init.luau" } }, false)), - } + -- 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, - -- We go through the action mappings in order of priority and check for the - -- file predicates, if present, we execute the action and report our status - 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 + ["init.lua"] = stdio.write( + serde.encode("json", { filePaths = { "init.lua" } }, false) + ), + ["init.luau"] = stdio.write( + serde.encode("json", { filePaths = { "init.luau" } }, false) + ), + } - -- If we reached so far, that must mean none of the file predicates matched, - -- so we return a `false` signifying an error - return false + -- We go through the action mappings in order of priority and check for the + -- file predicates, if present, we execute the action and report our status + 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 diff --git a/src/generators/rojo/sync_config.luau b/src/generators/rojo/sync_config.luau index 5318724..9ece19e 100644 --- a/src/generators/rojo/sync_config.luau +++ b/src/generators/rojo/sync_config.luau @@ -3,102 +3,110 @@ local process = require("@lune/process") local serde = require("@lune/serde") export type TreeProperties = { - Name: never?, - Parent: never?, + Name: never?, + Parent: never?, } export type TreeBase = { - ["$className"]: string?, - ["$ignoreUnknownInstances"]: boolean?, - ["$path"]: string | { optional: string }?, - ["$properties"]: TreeProperties?, + ["$className"]: string?, + ["$ignoreUnknownInstances"]: boolean?, + ["$path"]: string | { optional: string }?, + ["$properties"]: TreeProperties?, } export type TreeNormal = TreeBase & { - [string]: TreeNormal, -} & ({ ["$className"]: string } | { ["$path"]: string | { optional: string } }) + [string]: TreeNormal, +} & ({ ["$className"]: string } | { + ["$path"]: string | { optional: string }, +}) export type TreeService = TreeBase & { - [string]: TreeNormal, + [string]: TreeNormal, } export type DataModelTree = TreeBase & { - StarterPlayer: (TreeBase & { - StarterPlayerScripts: TreeService?, - StarterCharacterScripts: TreeService?, - [string]: TreeNormal, - })?, - [string]: TreeService, + StarterPlayer: (TreeBase & { + StarterPlayerScripts: TreeService?, + StarterCharacterScripts: TreeService?, + [string]: TreeNormal, + })?, + [string]: TreeService, } export type Tree = (DataModelTree & { - ["$className"]: "DataModel", + ["$className"]: "DataModel", }) | TreeNormal export type SyncConfig = { - name: string, - servePort: number?, - servePlaceIds: { number }?, - placeId: number?, - gameId: number?, - serveAddress: string?, - globIgnorePaths: { string }?, - tree: Tree, + name: string, + servePort: number?, + servePlaceIds: { number }?, + placeId: number?, + gameId: number?, + serveAddress: string?, + globIgnorePaths: { string }?, + tree: Tree, } 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. --- ## Errors --- * The current process lacks permissions to a file --- * Any I/O error occurs -return function(packageDirectory: string?, files: { string }, writeToFile: boolean?): (boolean, string?) - packageDirectory = packageDirectory or process.cwd - local syncConfigPath = `{packageDirectory}{PLATFORM_SEP}default.project.json` - if fs.isFile(syncConfigPath) then - return true, nil - end +return function( + packageDirectory: string?, + files: { string }, + writeToFile: boolean? +): (boolean, string?) + 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 - -- Remove the `.lua` or `.luau` file extension from the file name - local name = string.gsub(file, ".luau?$", "") + for _, file in files do + -- Remove the `.lua` or `.luau` file extension from the file name + local name = string.gsub(file, ".luau?$", "") - if name == "init" then - syncConfigTree["$path"] = name - continue - end + if name == "init" then + syncConfigTree["$path"] = name + continue + end - syncConfigTree[name] = { - ["$path"] = file, - } - end + syncConfigTree[name] = { + ["$path"] = file, + } + end - -- If there isn't a top level path, we mark the entire thing as a Folder - if not syncConfigTree["$path"] then - syncConfigTree["$className"] = "Folder" - end + -- If there isn't a top level path, we mark the entire thing as a Folder + if not syncConfigTree["$path"] then + syncConfigTree["$className"] = "Folder" + end - -- 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 - -- are installed - if not syncConfigTree["roblox_packages"] then - syncConfigTree["roblox_packages"] = { - ["$path"] = { - optional = "roblox_packages", - }, - } - end + -- 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 + -- are installed + if not syncConfigTree["roblox_packages"] then + syncConfigTree["roblox_packages"] = { + ["$path"] = { + optional = "roblox_packages", + }, + } + end - -- 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) - if writeToFile then - fs.writeFile(syncConfigPath, serializedConfig) - end + -- 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) + if writeToFile then + fs.writeFile(syncConfigPath, serializedConfig) + end - return true, serializedConfig + return true, serializedConfig end diff --git a/src/init.luau b/src/init.luau index a9ff34a..cf48aa9 100644 --- a/src/init.luau +++ b/src/init.luau @@ -1,8 +1,8 @@ -return { - generators = { - rojo = { - sourcemap = require("./generators/rojo/sourcemap"), - syncConfig = require("./generators/rojo/sync_config"), - }, - }, -} +return { + generators = { + rojo = { + sourcemap = require("./generators/rojo/sourcemap"), + syncConfig = require("./generators/rojo/sync_config"), + }, + }, +}