Skip to content

Commit 1afdda6

Browse files
committed
Add support for revision specific package creation
- using the asset format: "<assetId>@<revisionId>" to specify the asset ID and the revision ID - will fail if revision is invalid/doesnt exist - debug prints will now include a excerpt of response body
1 parent 0a9dfe1 commit 1afdda6

4 files changed

Lines changed: 49 additions & 17 deletions

File tree

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ So that when you work with rojo, you can do something like this when handling pa
114114
## Todo
115115

116116
- [x] Generate package map for a given package (asset)
117-
- [ ] generate from specific revision
117+
- [x] generate from specific revision
118118
- [x] embed revision ID into package
119119
- [x] Generate a matching map for a given directory
120120
- [x] Compare mappings for changes

src/API.luau

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ local URLS: {[string]: URL} = {
3131
url = "https://apis.roblox.com/assets/v1/assets/{ASSET_ID}",
3232
method = "GET"
3333
},
34-
GET_META_BY_VERSION = {
35-
url = "https://apis.roblox.com/assets/v1/assets/{ASSET_ID}/versions/{VERSION_NUMBER}",
36-
method = "GET"
37-
},
3834
GET_CONTENT = {
3935
url = "https://apis.roblox.com/asset-delivery-api/v1/assetId/{ASSET_ID}",
4036
method = "GET"
@@ -150,6 +146,9 @@ function API.makeRequest(
150146
Util.dprint("Request to URL failed:", url)
151147
Util.dprint("Status Code:", response.statusCode)
152148
Util.dprint("Response Body:", response.body)
149+
else
150+
Util.dprint("Request to URL succeeded:", url)
151+
Util.dprint("Response Body:", response.body:sub(1, 100) .. ( #response.body > 100 and "..." or "" ))
153152
end
154153

155154
return response.statusCode, response.body

src/Repackage.luau

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,46 @@ local function promptContinue(
5454
return lowered == "y" or lowered == "yes"
5555
end
5656

57+
local function getAssetFromString(
58+
assetStr: string
59+
): RobloxAPI.RequestedAsset
60+
if assetStr:find("@") then
61+
local parts = assetStr:split("@")
62+
local assetIdStr = parts[1]
63+
local revisionIdStr = parts[2]
64+
65+
local assetId = tonumber(assetIdStr)
66+
local revisionId = tonumber(revisionIdStr)
67+
68+
if assetId == nil then
69+
error("Invalid asset ID: " .. assetIdStr)
70+
end
71+
72+
if revisionId == nil then
73+
Util.error("Invalid revision ID: `" .. revisionIdStr .. "`")
74+
print("The proper format for asset revisions is: " .. formatted("<assetId>", "yellow") .. formatted("@", "magenta") .. formatted("<revisionId>", "yellow"))
75+
print("For example: " .. formatted("12345678900@3", "light_green"))
76+
error("")
77+
end
78+
79+
return RobloxAPI.asset(
80+
assetId,
81+
revisionId
82+
)
83+
else
84+
local assetId = tonumber(assetStr)
85+
if assetId == nil then
86+
error("Invalid asset ID: " .. assetStr)
87+
end
88+
89+
return RobloxAPI.asset(assetId)
90+
end
91+
end
92+
5793
local function createPackage(
58-
assetId: string
94+
assetString: string
5995
)
60-
local asset = RobloxAPI.asset(assetId)
96+
local asset = getAssetFromString(assetString)
6197
local packageName, tree = RobloxAPI.getPackageTree(asset)
6298
if not tree or not packageName then
6399
Util.error("Failed to retrieve package tree.")
@@ -84,7 +120,7 @@ local function createPackage(
84120
Tree.writeInstanceTreeToFS(tree, outDir, true)
85121
fs.writeFile(packageMetaFile, serde.encode("json", tree, true))
86122

87-
Util.info("Package created at:", packageOutDir)
123+
Util.info("Package created at:", packageOutDir, asset.assetRevisionId and formatted(" (Revision: " .. asset.assetRevisionId .. ")", "grey") or "")
88124
end
89125

90126
local function updateLocalPackage(
@@ -473,8 +509,8 @@ local Commands: {[string]: Command} = {
473509
create = {
474510
args = {
475511
{
476-
name = "Package Asset ID",
477-
type = "number"
512+
name = "Package Asset ID / Package Asset String",
513+
type = "string"
478514
}
479515
},
480516
desc = "Create a package onto the filesystem from a package asset",

src/RobloxAPI.luau

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ function RobloxAPI.getAssetMeta(
161161
): AssetMetadata?
162162
local replacements = {ASSET_ID = asset.assetId}
163163
local urlData: API.URL = API.URLS.GET_META
164-
if asset.assetRevisionId then
165-
urlData = API.URLS.GET_META_BY_VERSION
166-
replacements["VERSION_NUMBER"] = tostring(asset.assetRevisionId)
167-
end
168164

169165
local statusCode, response = API.makeRequest(
170166
urlData,
@@ -177,9 +173,6 @@ function RobloxAPI.getAssetMeta(
177173
return jsonResponse
178174
else
179175
local base = "Failed to get asset meta for assetId: " .. asset.assetId
180-
if asset.assetRevisionId then
181-
base ..= " with version:" .. asset.assetRevisionId
182-
end
183176
Util.dprint(base, "Status Code:", statusCode, "Response:", response)
184177
return nil
185178
end
@@ -286,6 +279,10 @@ function RobloxAPI.getPackageTree(
286279
local packageRevisionId: string = meta["revisionId"]
287280
local content: ContentResponse? = RobloxAPI.getPackageContent(asset)
288281
if content then
282+
if asset.assetRevisionId then
283+
packageRevisionId = tostring(asset.assetRevisionId)
284+
end
285+
289286
local dataLocation = content["location"]
290287
local _statusCode, response = API.makeRequest(
291288
{

0 commit comments

Comments
 (0)