Improve Sync server and plugin

This commit is contained in:
Lewin Kelly 2024-01-31 22:40:13 +00:00
parent ae94c72b33
commit 431f540b42
4 changed files with 79 additions and 11 deletions

View File

@ -191,10 +191,10 @@ end
local function makeScript(s) -- because no continue
local path = s.path -- { "ServerScriptService", "script" }
local content = s.content
local type = s.type
local filetype = s.type
local obj = game
local ok2 = pcall(function()
local ok, err = pcall(function()
for i = 1, #path - 1 do
obj = obj:FindFirstChild(path[i])
if not obj then
@ -205,12 +205,13 @@ local function makeScript(s) -- because no continue
end
end
end)
if not ok2 then
if not ok then
notify(
"Failed to sync "
.. table.concat(path, ".")
.. "! Is the path correct?"
)
print("Failed to sync:", err)
return
end
@ -218,7 +219,18 @@ local function makeScript(s) -- because no continue
local existingObj = obj:FindFirstChild(name)
if existingObj then
if existingObj:IsA "Script" then
existingObj.Source = content
local ok2, err2 = pcall(function()
existingObj.Source = content
end)
if not ok2 then
notify(
"Failed to sync "
.. table.concat(path, ".")
.. " to an existing file!"
)
print("Failed to sync to existing:", err2)
return
end
else
notify(
"Object already exists at path "
@ -230,17 +242,37 @@ local function makeScript(s) -- because no continue
else
local createScript
if type == "server" then
if filetype == "server" then
createScript = Instance.new "Script"
elseif type == "client" then
elseif filetype == "client" then
createScript = Instance.new "LocalScript"
else
return
end
createScript.Name = name
createScript.Source = content
createScript.Parent = obj
print("Name", name)
print("Content", content, type(content))
if type(content) == "table" then
for i, v in pairs(content) do
print(i, v)
end
end
local ok2, err2 = pcall(function()
createScript.Name = name
createScript.Source = content
createScript.Parent = obj
end)
if not ok2 then
notify(
"Failed to write "
.. table.concat(path, ".")
.. "! Is the content valid?"
)
print("Failed to write:", err2)
return
end
end
end

View File

@ -0,0 +1,21 @@
{
rules: [
"convert_index_to_field",
"remove_spaces",
"remove_compound_assignment",
"remove_interpolated_string",
"group_local_assignment",
// "compute_expression",
"remove_unused_if_branch",
"remove_unused_while",
"remove_empty_do",
"remove_types",
// "remove_method_definition",
"remove_function_call_parens",
"filter_after_early_return",
{
rule: "rename_variables",
globals: ["$default", "$roblox"],
},
],
}

View File

@ -12,7 +12,10 @@ func CompileLuau(sourcePath string) (string, error) {
}
cmd := exec.Command(path, "process", sourcePath, "./temp.lua")
cmd.Run()
err = cmd.Run()
if err != nil {
return "", err
}
// Return the compiled file
file, _ := os.ReadFile("./temp.lua")

View File

@ -93,6 +93,7 @@ func main() {
// scripttype = "module"
fmt.Println(c.InRed("Unknown script type: ") + c.InUnderline(c.InPurple(formatPath)) + c.InRed("!"))
fmt.Println(c.InYellow("If you were trying to sync a ModuleScript, these are not supported by Mercury Sync. Please transpose them manually."))
return nil
}
formatPath = strings.ReplaceAll(formatPath, string(os.PathSeparator), "$dot$")
@ -115,6 +116,12 @@ func main() {
case "luau":
fmt.Println(c.InBlue("Compiling ") + c.InUnderline(c.InPurple(dottedPath)) + c.InBlue("..."))
content, err = CompileLuau(path)
if content == "" {
fmt.Println(c.InYellow("After compilation, file ") + c.InUnderline(c.InPurple(dottedPath)) + c.InYellow(" was empty!"))
content = "-- Mercury Sync: Empty file"
}
if err != nil {
fmt.Println(c.InRed("Error while compiling Luau file:"), err)
if strings.Contains(err.Error(), "file does not exist") ||
@ -131,6 +138,11 @@ func main() {
return nil
}
content = string(file)
if content == "" {
fmt.Println(c.InYellow("File ") + c.InUnderline(c.InPurple(dottedPath)) + c.InYellow(" is empty!"))
content = "-- Mercury Sync: Empty file"
}
}
fmt.Println(c.InGreen("Sending ") + c.InUnderline(c.InPurple(dottedPath)) + c.InGreen("..."))
@ -150,7 +162,7 @@ func main() {
return nil
})
os.Remove("./temp.lua")
// os.Remove("./temp.lua")
cx.JSON(200, Response)
})