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
e019e5a8ed
commit
51994dfd13
3 changed files with 109 additions and 97 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue