Skip to content

Instantly share code, notes, and snippets.

@OverHash
Created July 21, 2020 19:08
Show Gist options
  • Save OverHash/1e48b525d19be92f24a8fc795bf41112 to your computer and use it in GitHub Desktop.
Save OverHash/1e48b525d19be92f24a8fc795bf41112 to your computer and use it in GitHub Desktop.
Auto generate assets.d.ts file
-- instructions:
-- put the assets.lua into a ModuleScript inside ServerScriptService, then run this script inside the command bar
-- it will generate an output file in ServerScriptService, which you can then paste into assets.d.ts
local assets = require(game.ServerScriptService.assets)
local gen = [[declare namespace assetIds {
const ]]
function generateSection(sec)
local res = ''
for key, value in pairs(sec) do
if not (key:find(' ') or key:find('-')) then
res = res .. key .. ': '
else
res = res .. "'" .. key .. "': "
end
if type(value) == 'table' then
res = res .. '{\n'..generateSection(value)..'};\n'
elseif type(value) == 'string' then
res = res ..'string;\n'
end
end
return res
end
local res = generateSection(assets):sub(0, -2)
res = res:gsub("'images'", 'images')
gen = gen .. res .. '\n}\n\nexport = assetIds;\n'
local output = game.ServerScriptService:FindFirstChild('output')
if not output then
output = Instance.new('ModuleScript')
output.Name = 'output'
output.Parent = game.ServerScriptService
end
output.Source = gen
print('DONE. SEE ServerScriptService > output')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment