-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeconstruct_sdk.luau
86 lines (73 loc) · 2.5 KB
/
deconstruct_sdk.luau
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local fs = require("@lune/fs")
local roblox = require("@lune/roblox")
local process = require("@lune/process")
local luau = require("@lune/luau")
local serde = require("@lune/serde")
local workDir = process.args[1]
local file = fs.readFile(`{workDir}/superbiz.rbxm`)
local superbizSDK = roblox.deserializeModel(file)[1]
local CLASS_NAME_REFER = {
["Script"] = ".server.lua",
["LocalScript"] = ".client.lua",
["ModuleScript"] = ".lua",
}
local function CheckScriptConvert(targetScript, recursive)
if CLASS_NAME_REFER[targetScript.ClassName] and #targetScript:GetChildren() > 0 then
local newContainer = roblox.Instance.new("Folder")
newContainer.Name = targetScript.Name
newContainer.Parent = targetScript.Parent
local newScript = targetScript:Clone()
newScript.Name = "init"
newScript.Parent = newContainer
for _, child in pairs(targetScript:GetChildren()) do
child.Parent = newContainer
if CLASS_NAME_REFER[child.ClassName] then
CheckScriptConvert(child, true)
end
end
targetScript:Destroy()
end
end
local function StartConvertNestedScript()
for _, item in pairs(superbizSDK:GetChildren()) do
if CLASS_NAME_REFER[item.ClassName] then
CheckScriptConvert(item, true)
end
end
end
-- Use the FS API to write the file
local function RecursiveGenRojoFolder(targetFolder, targetPath)
fs.writeDir(targetPath)
for _, child in pairs(targetFolder:GetChildren()) do
if child:IsA("Folder") then
RecursiveGenRojoFolder(child, targetPath .. "/" .. child.Name)
elseif CLASS_NAME_REFER[child.ClassName] then
fs.writeFile(targetPath .. "/" .. child.Name .. CLASS_NAME_REFER[child.ClassName], child.Source)
end
end
end
local function GetSDKVersion()
local sdkConfig = superbizSDK:FindFirstChild("InternalConfig")
if sdkConfig then
local configFileSrc = sdkConfig.Source
configFileSrc = "game = { ReplicatedStorage = { FindFirstChild = function() end } }\n" .. configFileSrc -- Monkey patch for SDK
return luau.load(configFileSrc)().SDK_VERSION or "00"
end
return "00"
end
local function CreateRojoProject(SDKName, tree)
local rojoSDK = {
-- name = SDKName,
name = "bloxbiz-sdk",
tree = tree,
}
fs.writeFile(`{workDir}/{SDKName}/default.project.json`, serde.encode("json", rojoSDK))
end
do
local SDKversion = GetSDKVersion()
local SDKname = `bloxbiz-sdk-v{SDKversion}`
StartConvertNestedScript()
RecursiveGenRojoFolder(superbizSDK, `{workDir}/{SDKname}/src`)
CreateRojoProject(SDKname, { ["$path"] = "src" })
print(`{SDKname},{SDKversion}`) -- Send the SDK name back to Python
end