Skip to content

Instantly share code, notes, and snippets.

@thomashope
Created December 4, 2025 21:35
Show Gist options
  • Select an option

  • Save thomashope/4938b059285e07e51f9b1957fc6c06d1 to your computer and use it in GitHub Desktop.

Select an option

Save thomashope/4938b059285e07e51f9b1957fc6c06d1 to your computer and use it in GitHub Desktop.
An example of how you could use Premake for your asset building pipeline.
newaction {
trigger = "assets",
description = "Build game assets",
execute = function()
local assetSourcePaths = os.matchfiles("assets/source/**")
local assetBuiltPaths = os.matchfiles("assets/built/**")
removeJunkFiles(assetSourcePaths)
removeJunkFiles(assetBuiltPaths)
local filesToMirror = {}
local generatorPaths = {}
-- gather the files
for i, path in ipairs(assetSourcePaths) do
if path:endswith("generator.lua") then
table.insert(generatorPaths, path)
elseif not path:endswithanyof({".prog", ".vert", ".frag", ".blend", ".blend1"}) then
table.insert(filesToMirror, path)
end
end
local generators = loadGenerators(generatorPaths)
local generatorOutputs = {}
-- build a list of generator outputs
for _,generator in ipairs(generators) do
for _,rule in ipairs(generator.rules) do
for _,output in ipairs(rule.outputs) do
table.insert(generatorOutputs, output)
end
end
end
print("\n# Cleaning Built Assets Folder")
-- delete orphaned assets from the built folder
for i,built in ipairs(assetBuiltPaths) do
local src = built:gsub("assets/built", "assets/source")
if not table.contains(filesToMirror, src) and -- file is to be mirrored
not table.contains(generatorOutputs, built) -- file is a generated output
then
print("removing", built)
if not os.remove(built) then
printError("ERROR: failed to remove file: "..built)
end
end
end
print("\n# Copying Assets")
copyModifiedFiles(filesToMirror)
print("\n# Running Generators")
executeGenerators(generators)
print("\n# Done Building Assets")
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment