Repository navigation
Expand file tree
/
Copy pathpackage.lua
More file actions
3838 lines (3320 loc) · 99 KB
/
Copy pathpackage.lua
File metadata and controls
3838 lines (3320 loc) · 99 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Start of Rostruct v0.1.4-alpha
--[[
Originally RuntimeLib.lua supplied by roblox-ts, modified for use when bundled.
]]
local TS = {
_G = {};
}
setmetatable(TS, {
__index = function(self, k)
if k == "Promise" then
self.Promise = TS.initialize("packages", "Promise")
return self.Promise
end
end
})
-- Runtime classes
local FilePtr
do
FilePtr = {}
FilePtr.__index = FilePtr
function FilePtr.new(path)
local fileName, slash = string.match(path, "([^/]+)(/*)$")
return setmetatable({
name = fileName,
path = string.sub(path, 1, -#fileName - (slash ~= "" and 2 or 1)),
}, FilePtr)
end
function FilePtr:__index(k)
if k == "Parent" then
return FilePtr.new(self.path)
end
end
end
local Module
do
Module = {}
Module.__index = Module
function Module.new(path, name, func)
return setmetatable({
-- Init files are representations of their parent directory,
-- so if it's an init file, we trim the "/init.lua" off of
-- the file path.
path = name ~= "init"
and path
or FilePtr.new(path).path,
name = name,
func = func,
data = nil;
}, Module)
end
function Module:__index(k)
if Module[k] then
return Module[k]
elseif k == "Parent" then
return FilePtr.new(self.path)
elseif k == "Name" then
return self.path
end
end
function Module:require()
if self.func then
self.data = self.func()
self.func = nil
end
return self.data
end
function Module:GetFullName()
return self.path
end
end
local Symbol
do
Symbol = {}
Symbol.__index = Symbol
setmetatable(
Symbol,
{
__call = function(_, description)
local self = setmetatable({}, Symbol)
self.description = "Symbol(" .. (description or "") .. ")"
return self
end,
}
)
local symbolRegistry = setmetatable(
{},
{
__index = function(self, k)
self[k] = Symbol(k)
return self[k]
end,
}
)
function Symbol:toString()
return self.description
end
Symbol.__tostring = Symbol.toString
-- Symbol.for
function Symbol.getFor(key)
return symbolRegistry[key]
end
function Symbol.keyFor(goalSymbol)
for key, symbol in pairs(symbolRegistry) do
if symbol == goalSymbol then
return key
end
end
end
end
TS.Symbol = Symbol
TS.Symbol_iterator = Symbol("Symbol.iterator")
-- Provides a way to attribute modules to files.
local modulesByPath = {}
local modulesByName = {}
-- Bundle compatibility
function TS.register(path, name, func)
local module = Module.new(path, name, func)
modulesByPath[path] = module
modulesByName[name] = module
return module
end
function TS.get(path)
return modulesByPath[path]
end
function TS.initialize(...)
local symbol = setmetatable({}, {__tostring = function()
return "root"
end})
local caller = TS.register(symbol, symbol)
return TS.import(caller, { path = "out/" }, ...)
end
-- module resolution
function TS.getModule(_object, _moduleName)
return error("TS.getModule is not supported", 2)
end
-- This is a hash which TS.import uses as a kind of linked-list-like history of [Script who Loaded] -> Library
local currentlyLoading = {}
local registeredLibraries = {}
function TS.import(caller, parentPtr, ...)
-- Because 'Module.Parent' returns a FilePtr, the module handles the indexing.
-- Getting 'parentPtr.path' will return the result of FilePtr.Parent.Parent...
local modulePath = parentPtr.path .. table.concat({...}, "/") .. ".lua"
local module = assert(
modulesByPath[modulePath] or modulesByPath[parentPtr.path .. table.concat({...}, "/") .. "/init.lua"],
"No module exists at path '" .. modulePath .. "'"
)
currentlyLoading[caller] = module
-- Check to see if a case like this occurs:
-- module -> Module1 -> Module2 -> module
-- WHERE currentlyLoading[module] is Module1
-- and currentlyLoading[Module1] is Module2
-- and currentlyLoading[Module2] is module
local currentModule = module
local depth = 0
while currentModule do
depth = depth + 1
currentModule = currentlyLoading[currentModule]
if currentModule == module then
local str = currentModule.name -- Get the string traceback
for _ = 1, depth do
currentModule = currentlyLoading[currentModule]
str ..= " => " .. currentModule.name
end
error("Failed to import! Detected a circular dependency chain: " .. str, 2)
end
end
if not registeredLibraries[module] then
if TS._G[module] then
error(
"Invalid module access! Do you have two TS runtimes trying to import this? " .. module.path,
2
)
end
TS._G[module] = TS
registeredLibraries[module] = true -- register as already loaded for subsequent calls
end
local data = module:require()
if currentlyLoading[caller] == module then -- Thread-safe cleanup!
currentlyLoading[caller] = nil
end
return data
end
-- general utility functions
function TS.async(callback)
local Promise = TS.Promise
return function(...)
local n = select("#", ...)
local args = { ... }
return Promise.new(function(resolve, reject)
coroutine.wrap(function()
local ok, result = pcall(callback, unpack(args, 1, n))
if ok then
resolve(result)
else
reject(result)
end
end)()
end)
end
end
function TS.await(promise)
local Promise = TS.Promise
if not Promise.is(promise) then
return promise
end
local status, value = promise:awaitStatus()
if status == Promise.Status.Resolved then
return value
elseif status == Promise.Status.Rejected then
error(value, 2)
else
error("The awaited Promise was cancelled", 2)
end
end
-- out/core/Reconciler/init.lua:
TS.register("out/core/Reconciler/init.lua", "init", function()
-- Setup
local script = TS.get("out/core/Reconciler/init.lua")
-- Start of init
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
--[[
* File: index.ts
* File Created: Friday, 4th June 2021 1:52:37 am
* Author: richard
* Description: Transforms files into Roblox objects.
]]
local transformDirectory = TS.import(script, script, "transformDirectory")
local VirtualScript = TS.import(script, script.Parent, "VirtualScript").VirtualScript
local globals = TS.import(script, script.Parent.Parent, "globals").globals
-- * Class used to transform files into a Roblox instance tree.
local Reconciler
do
Reconciler = setmetatable({}, {
__tostring = function()
return "Reconciler"
end,
})
Reconciler.__index = Reconciler
function Reconciler.new(...)
local self = setmetatable({}, Reconciler)
self:constructor(...)
return self
end
function Reconciler:constructor(target)
self.target = target
local _0 = globals.currentScope
globals.currentScope += 1
self.scope = _0
end
function Reconciler:reify(parent)
local directory = transformDirectory(self.target, self.scope)
directory.Parent = parent
return directory
end
function Reconciler:deployWorker()
local runtimeJobs = {}
local virtualScripts = VirtualScript:getVirtualScriptsOfScope(self.scope)
local _0 = virtualScripts
assert(_0, "Cannot deploy project with no scripts!")
for _, v in ipairs(virtualScripts) do
if v.instance:IsA("LocalScript") then
local _1 = runtimeJobs
local _2 = v:deferExecutor():andThen(function()
return v.instance
end)
-- ▼ Array.push ▼
_1[#_1 + 1] = _2
-- ▲ Array.push ▲
end
end
-- Define as constant because the typing for 'Promise.all' is faulty
local runtimeWorker = TS.Promise.all(runtimeJobs)
return runtimeWorker
end
end
return {
Reconciler = Reconciler,
}
-- End of init
end)
-- out/core/Reconciler/transformDirectory.lua:
TS.register("out/core/Reconciler/transformDirectory.lua", "transformDirectory", function()
-- Setup
local script = TS.get("out/core/Reconciler/transformDirectory.lua")
-- Start of transformDirectory
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
--[[
* File: transformDirectory.ts
* File Created: Friday, 4th June 2021 12:36:38 am
* Author: richard
* Description: Turns a folder directory into a Roblox instance.
]]
local Make = TS.import(script, script.Parent.Parent.Parent, "packages", "make")
local HttpService = TS.import(script, script.Parent.Parent.Parent, "packages", "services").HttpService
local _0 = TS.import(script, script.Parent.Parent.Parent, "utils", "filesystem")
local Directory = _0.Directory
local File = _0.File
local transformFile = TS.import(script, script.Parent, "transformFile")
-- * A list of file names that should not become files.
local RESERVED_NAMES = {
["init.lua"] = true,
["init.server.lua"] = true,
["init.client.lua"] = true,
["init.meta.json"] = true,
}
-- * Interface for `init.meta.json` data.
--[[
*
* Creates an instance from the given metadata.
* @param metadata The init.meta.json data.
* @param name The name of the instance.
* @returns A new instance.
]]
local function makeFromMetadata(metadata, name)
-- Create the instance first to ensure 'className' is always
-- prioritized, even if there are no properties set.
local instance = Make(metadata.className or "Folder", {
Name = name,
})
-- Currently, only primitive types can be defined.
if metadata.properties then
for key, value in pairs(metadata.properties) do
instance[key] = value
end
end
return instance
end
--[[
*
* Creates an Instance for the given folder.
* [Some files](https://rojo.space/docs/6.x/sync-details/#scripts) can modify the class and properties during creation.
* @param dir The directory to make an Instance from.
* @param parent Optional parent of the Instance.
* @returns THe instance created for the folder.
]]
local function transformDirectory(dir, scope)
local instance
-- Check if the directory contains a special init file.
-- https://rojo.space/docs/6.x/sync-details/#scripts
-- https://rojo.space/docs/6.x/sync-details/#meta-files
local init = dir.locateFiles("init.lua", "init.server.lua", "init.client.lua", "init.meta.json")
-- Turns the directory into a script instance using the init file.
local _1 = init
if _1 ~= nil then
_1 = _1.extension
end
if _1 == "lua" then
instance = transformFile(init, scope, dir.name)
else
local _2 = init
if _2 ~= nil then
_2 = _2.extension
end
if _2 == "json" then
instance = makeFromMetadata(HttpService:JSONDecode(readfile(init.location)), dir.name)
else
instance = Make("Folder", {
Name = dir.name,
})
end
end
-- Scan the file to descend the instance tree.
for _, f in ipairs(listfiles(dir.location)) do
local fileName = (string.match(f, "([^/]+)$"))
-- Make sure the file is not reserved for special use
local _2 = RESERVED_NAMES
local _3 = fileName
if _2[_3] ~= nil then
continue
end
if isfile(f) then
local obj = transformFile(File(f, dir.origin), scope)
if obj then
obj.Parent = instance
end
else
transformDirectory(Directory(f, dir.origin), scope).Parent = instance
end
end
-- An instance definitely exists! if there is no special file present, the
-- folder is made (see 'else' condition above).
return instance
end
return transformDirectory
-- End of transformDirectory
end)
-- out/core/Reconciler/transformFile.lua:
TS.register("out/core/Reconciler/transformFile.lua", "transformFile", function()
-- Setup
local script = TS.get("out/core/Reconciler/transformFile.lua")
-- Start of transformFile
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
--[[
* File: transformFile.ts
* File Created: Thursday, 3rd June 2021 11:13:25 pm
* Author: richard
* Description: Turns a file into a Roblox instance.
]]
local generateAssetId = TS.import(script, script.Parent.Parent.Parent, "globals").generateAssetId
local Make = TS.import(script, script.Parent.Parent.Parent, "packages", "make")
local VirtualScript = TS.import(script, script.Parent.Parent, "VirtualScript").VirtualScript
local HttpService = TS.import(script, script.Parent.Parent.Parent, "packages", "services").HttpService
--[[
*
* Creates an Instance using the given file information.
* If the object was a script, a reference to the file path is stored in the `Source` parameter.
* @param file The file to make an Instance from.
* @param name Optional name of the instance.
* @param parent Optional parent of the Instance.
* @returns A new Instance if possible.
]]
local function transformFile(file, scope, name)
local _0 = file.extension
repeat
if _0 == ("lua") then
local luaObj
local _1 = file.type
repeat
if _1 == ("server.lua") then
local _2 = {}
local _3 = "Name"
local _4 = name
if _4 == nil then
_4 = file.shortName
end
_2[_3] = _4
_2.Source = file.location
luaObj = Make("Script", _2)
break
end
if _1 == ("client.lua") then
local _2 = {}
local _3 = "Name"
local _4 = name
if _4 == nil then
_4 = file.shortName
end
_2[_3] = _4
_2.Source = file.location
luaObj = Make("LocalScript", _2)
break
end
local _2 = {}
local _3 = "Name"
local _4 = name
if _4 == nil then
_4 = file.extendedName
end
_2[_3] = _4
_2.Source = file.location
luaObj = Make("ModuleScript", _2)
until true
VirtualScript.new(luaObj, file, scope)
return luaObj
end
if _0 == ("json") then
local _1 = {}
local _2 = "Name"
local _3 = name
if _3 == nil then
_3 = file.extendedName
end
_1[_2] = _3
local jsonObj = Make("ModuleScript", _1)
VirtualScript.new(jsonObj, file, scope):setExecutor(function()
return HttpService:JSONDecode(readfile(file.location))
end)
return jsonObj
end
if _0 == ("txt") then
local _1 = {}
local _2 = "Name"
local _3 = name
if _3 == nil then
_3 = file.extendedName
end
_1[_2] = _3
_1.Value = readfile(file.location)
local txtObj = Make("StringValue", _1)
return txtObj
end
if _0 == ("rbxm") then
local _1 = generateAssetId
local _2 = "This exploit does not support rbxasset:// generation! (" .. file.location .. ")"
assert(_1 ~= 0 and _1 == _1 and _1 ~= "" and _1, _2)
return game:GetObjects(generateAssetId(file.location))[1]
end
if _0 == ("rbxmx") then
local _1 = generateAssetId
local _2 = "This exploit does not support rbxasset:// generation! (" .. file.location .. ")"
assert(_1 ~= 0 and _1 == _1 and _1 ~= "" and _1, _2)
return game:GetObjects(generateAssetId(file.location))[1]
end
break
until true
end
return transformFile
-- End of transformFile
end)
-- out/core/VirtualScript.lua:
TS.register("out/core/VirtualScript.lua", "VirtualScript", function()
-- Setup
local script = TS.get("out/core/VirtualScript.lua")
-- Start of VirtualScript
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
--[[
* File: VirtualScript.ts
* File Created: Tuesday, 1st June 2021 8:58:51 pm
* Author: richard
* Description: Execute files as Roblox instances.
]]
local HttpService = TS.import(script, script.Parent.Parent, "packages", "services").HttpService
-- * Class used to execute files in a Roblox instance context.
local VirtualScript
do
VirtualScript = setmetatable({}, {
__tostring = function()
return "VirtualScript"
end,
})
VirtualScript.__index = VirtualScript
function VirtualScript.new(...)
local self = setmetatable({}, VirtualScript)
self:constructor(...)
return self
end
function VirtualScript:constructor(instance, file, scope)
self.instance = instance
self.file = file
self.scope = scope
self.id = "VirtualScript-" .. HttpService:GenerateGUID(false)
self.jobComplete = false
local _0 = file.origin
local _1 = "VirtualScript file must have an origin (" .. file.location .. ")"
assert(_0 ~= "" and _0, _1)
self.env = {
script = instance,
require = function(obj)
return VirtualScript:require(obj)
end,
_PATH = file.location,
_ROOT = file.origin,
}
-- Initialize a scope array if it does not already exist.
local _2 = VirtualScript.virtualScriptsOfScope
local _3 = scope
if not (_2[_3] ~= nil) then
local _4 = VirtualScript.virtualScriptsOfScope
local _5 = scope
local _6 = { self }
-- ▼ Map.set ▼
_4[_5] = _6
-- ▲ Map.set ▲
else
local _4 = VirtualScript.virtualScriptsOfScope
local _5 = scope
local _6 = _4[_5]
local _7 = self
-- ▼ Array.push ▼
_6[#_6 + 1] = _7
-- ▲ Array.push ▲
end
-- Tracks this VirtualScript for external use.
local _4 = VirtualScript.virtualScriptsByInstance
local _5 = instance
local _6 = self
-- ▼ Map.set ▼
_4[_5] = _6
-- ▲ Map.set ▲
end
function VirtualScript:getFromInstance(obj)
local _0 = self.virtualScriptsByInstance
local _1 = obj
return _0[_1]
end
function VirtualScript:getVirtualScriptsOfScope(scope)
local _0 = self.virtualScriptsOfScope
local _1 = scope
return _0[_1]
end
function VirtualScript:require(obj)
local _0 = self.virtualScriptsByInstance
local _1 = obj
local virtualScript = _0[_1]
if virtualScript then
return virtualScript:runExecutor()
else
return require(obj)
end
end
function VirtualScript:getSource()
return "setfenv(1, setmetatable(..., { __index = getfenv(0) }));" .. readfile(self.file.location)
end
function VirtualScript:setExecutor(exec)
local _0 = self.jobComplete == false
assert(_0, "Cannot set executor after script was executed")
self.executor = exec
end
function VirtualScript:createExecutor()
local _0 = self.executor
if _0 ~= 0 and _0 == _0 and _0 ~= "" and _0 then
return self.executor
end
local f, err = loadstring(self:getSource(), "=" .. self.file.location)
local _1 = f
local _2 = err
assert(_1 ~= 0 and _1 == _1 and _1 ~= "" and _1, _2)
self.executor = f
return self.executor
end
function VirtualScript:runExecutor()
if self.jobComplete then
return self.result
end
local result = self:createExecutor()(self.env)
-- Modules must return a value.
if self.instance:IsA("ModuleScript") then
local _0 = result
local _1 = "Module '" .. self.file.location .. "' did not return any value"
assert(_0 ~= 0 and _0 == _0 and _0 ~= "" and _0, _1)
end
self.jobComplete = true
self.result = result
return self.result
end
function VirtualScript:deferExecutor()
return TS.Promise.defer(function(resolve)
return resolve(self:runExecutor())
end):timeout(30, "Script " .. self.file.location .. " reached execution timeout! Try not to yield the main thread in LocalScripts.")
end
VirtualScript.virtualScriptsByInstance = {}
VirtualScript.virtualScriptsOfScope = {}
end
return {
VirtualScript = VirtualScript,
}
-- End of VirtualScript
end)
-- out/core/buildProject.lua:
TS.register("out/core/buildProject.lua", "buildProject", function()
-- Setup
local script = TS.get("out/core/buildProject.lua")
-- Start of buildProject
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
local Directory = TS.import(script, script.Parent.Parent, "utils", "filesystem").Directory
local Reconciler = TS.import(script, script.Parent, "Reconciler").Reconciler
local VirtualScript = TS.import(script, script.Parent, "VirtualScript").VirtualScript
--[[
*
* Builds the given project as a Roblox Instance tree.
* @param target The target files to build.
* @param parent Optional parent of the Instance tree.
* @returns A project interface.
]]
local function buildProject(target, parent)
local directory = Directory(target, target)
local reconciler = Reconciler.new(directory)
return {
Instance = reconciler:reify(parent),
Location = directory.location,
}
end
--[[
*
* Builds the given project and executes every tracked LocalScript.
* @param target The target files to build.
* @param parent Optional parent of the Instance tree.
* @returns A project interface.
]]
local function deployProject(target, parent)
local directory = Directory(target, target)
local reconciler = Reconciler.new(directory)
local instance = reconciler:reify(parent)
return {
Instance = instance,
Location = directory.location,
RuntimeWorker = reconciler:deployWorker(),
}
end
--[[
*
* Builds the given project and executes every tracked LocalScript.
* @param target The target files to build.
* @param parent Optional parent of the Instance tree.
* @returns A project interface.
]]
local function requireProject(target, parent)
local directory = Directory(target, target)
local reconciler = Reconciler.new(directory)
local instance = reconciler:reify(parent)
local _0 = instance:IsA("LuaSourceContainer")
local _1 = "Failed to require " .. directory.location .. " (Project is not a module)"
assert(_0, _1)
return {
Instance = instance,
Location = directory.location,
RuntimeWorker = reconciler:deployWorker(),
Module = VirtualScript:getFromInstance(instance):deferExecutor(),
}
end
return {
buildProject = buildProject,
deployProject = deployProject,
requireProject = requireProject,
}
-- End of buildProject
end)
-- out/core/downloadAsset.lua:
TS.register("out/core/downloadAsset.lua", "downloadAsset", function()
-- Setup
local script = TS.get("out/core/downloadAsset.lua")
-- Start of downloadAsset
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
local http = TS.import(script, script.Parent.Parent, "utils", "common", "http")
local makeFile = TS.import(script, script.Parent.Parent, "utils", "filesystem").makeFile
local extract = TS.import(script, script.Parent.Parent, "utils", "common", "extract").extract
--[[
*
* Downloads the asset file for a release.
* @param release The release to get the asset from.
* @param assetName Optional name of the asset. If not provided, the function returns the zipball URL.
* @returns The file data for an asset.
]]
local downloadAsset = TS.async(function(release, path, assetName)
local assetUrl
if assetName ~= nil then
local _0 = release.assets
local _1 = function(asset)
return asset.name == assetName
end
-- ▼ ReadonlyArray.find ▼
local _2 = nil
for _3, _4 in ipairs(_0) do
if _1(_4, _3 - 1, _0) == true then
_2 = _4
break
end
end
-- ▲ ReadonlyArray.find ▲
local asset = _2
local _3 = asset
local _4 = "Release '" .. release.name .. "' does not have asset '" .. assetName .. "'"
assert(_3, _4)
assetUrl = asset.browser_download_url
else
assetUrl = release.zipball_url
end
local response = TS.await(http.request({
Url = assetUrl,
Headers = {
["User-Agent"] = "rostruct",
},
}))
local _0 = response.Success
local _1 = response.StatusMessage
assert(_0, _1)
local _2
if assetName ~= nil and (string.match(assetName, "([^%.]+)$")) ~= "zip" then
_2 = makeFile(path .. assetName, response.Body)
else
_2 = extract(response.Body, path, assetName == nil)
end
end)
return {
downloadAsset = downloadAsset,
}
-- End of downloadAsset
end)
-- out/core/downloadRelease.lua:
TS.register("out/core/downloadRelease.lua", "downloadRelease", function()
-- Setup
local script = TS.get("out/core/downloadRelease.lua")
-- Start of downloadRelease
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
local openJson = TS.import(script, script.Parent.Parent, "utils", "common", "openJson").openJson
local _0 = TS.import(script, script.Parent.Parent, "utils", "github-release")
local getLatestRelease = _0.getLatestRelease
local getRelease = _0.getRelease
local identify = _0.identify
local downloadAsset = TS.import(script, script.Parent, "downloadAsset").downloadAsset
local fileManager = TS.import(script, script.Parent, "file-manager")
local cacheObject = openJson(fileManager.lintPath("rostruct/cache/release_tags.json"))
--[[
*
* Downloads a release from the given repository. If `assetName` is undefined, it downloads
* the source zip files and extracts them. Automatically extracts .zip files.
* This function does not download prereleases or drafts.
* @param owner The owner of the repository.
* @param repo The name of the repository.
* @param tag The release tag to download.
* @param assetName Optional asset to download. Defaults to the source files.
* @returns A download result interface.
]]
local downloadRelease = TS.async(function(owner, repo, tag, assetName)
local id = identify(owner, repo, tag, assetName)
local path = fileManager.lintPath("rostruct/cache/releases/", id) .. "/"
-- If the path is taken, don't download it again
if isfolder(path) then
return TS.Promise.resolve({
Location = path,
Tag = tag,
Updated = false,
})
end
local release = TS.await(getRelease(owner, repo, tag))
TS.await(downloadAsset(release, path, assetName))
return {
Location = path,
Tag = tag,
Updated = true,
}
end)
--[[
*
* Downloads the latest release from the given repository. If `assetName` is undefined,
* it downloads the source zip files and extracts them. Automatically extracts .zip files.
* This function does not download prereleases or drafts.
* @param owner The owner of the repository.
* @param repo The name of the repository.
* @param assetName Optional asset to download. Defaults to the source files.
* @returns A download result interface.
]]
local downloadLatestRelease = TS.async(function(owner, repo, assetName)
local id = identify(owner, repo, nil, assetName)
local path = fileManager.lintPath("rostruct/cache/releases/", id) .. "/"
local release = TS.await(getLatestRelease(owner, repo))
local cacheData = cacheObject:load()
-- Check if the cache is up-to-date
if cacheData[id] == release.tag_name and isfolder(path) then
return {
Location = path,
Tag = release.tag_name,
Updated = false,
}
end
-- Update the cache with the new tag
cacheData[id] = release.tag_name
cacheObject:save()
-- Make sure nothing is at the path before downloading!
if isfolder(path) then
delfolder(path)
end
-- Download the asset to the cache
TS.await(downloadAsset(release, path, assetName))
return {
Location = path,
Tag = release.tag_name,
Updated = true,
}
end)
-- * Clears the release cache.
local function clearReleaseCache()
delfolder(fileManager.lintPath("rostruct/cache/releases/"))
makefolder(fileManager.lintPath("rostruct/cache/releases/"))
writefile(fileManager.lintPath("rostruct/cache/release_tags.json"), "{}")
end
return {
downloadRelease = downloadRelease,
downloadLatestRelease = downloadLatestRelease,
clearReleaseCache = clearReleaseCache,
}
-- End of downloadRelease
end)
-- out/core/file-manager.lua:
TS.register("out/core/file-manager.lua", "file-manager", function()
-- Setup
local script = TS.get("out/core/file-manager.lua")
-- Start of file-manager
-- Compiled with roblox-ts v1.1.1
local TS = TS._G[script]
local makeFiles = TS.import(script, script.Parent.Parent, "utils", "filesystem").makeFiles
-- * Maps a list of files that handle Rostruct file storage.
local fileArray = { { "rostruct/", "" }, { "rostruct/cache/", "" }, { "rostruct/cache/releases/", "" }, { "rostruct/cache/release_tags.json", "{}" } }
--[[
*
* Gets the value of `dir .. file`. Mainly used with linting to flag unchanged files when changing paths.
* Might be bad practice! Let me know of better ways to do this.
* @param start The directory to index.
* @param path The local path.
* @returns A reference to the file.
]]
local function lintPath(start, path)
return path ~= nil and start .. path or start
end
-- * Initializes the file structure for Rostruct.
local function init()
makeFiles(fileArray)
end
return {
lintPath = lintPath,
init = init,
}
-- End of file-manager
end)
-- out/core/init.lua:
TS.register("out/core/init.lua", "init", function()
-- Setup
local script = TS.get("out/core/init.lua")
-- Start of init