rbxts-asset-sync
v0.4.2
Published
Local asset CDN pipeline for roblox-ts
Readme
rbxts-asset-sync
Local asset CDN pipeline for roblox-ts.
rbxts-asset-sync automates the process of uploading local asset files (images, audio, models, etc.) to Roblox via the Open Cloud API, and generates a TypeScript asset map for easy asset referencing in your roblox-ts projects.
Features
- Automatic Asset Upload: Uploads assets from a local folder to Roblox using Open Cloud.
- Asset Map Generation: Generates a TypeScript file mapping asset paths to
rbxassetid://IDs. - Change Watching: Optionally watches your asset folder and syncs changes automatically.
- Caching: Avoids re-uploading unchanged assets using a hash-based cache.
- Roblox-ts Integration: Asset map can be imported and used directly in roblox-ts scripts.
- Lossless WAV Support:
.wavfiles are transcoded to OGG (FLAC) on-the-fly before upload—no temp files required. - VS Code Integration: Install the VS Code extension to enjoy image/audio previews and information from simply hovering over.
Installation
npm install --save-dev rbxts-asset-syncOr use npx for one-off usage.
Setup
Roblox Open Cloud API Key:
Create an API key with the "Asset Management" permission for your user or group.
Set the following environment variables (e.g., in a
.envfile at your project root):ROBLOX_API_KEY=your-api-key-here ROBLOX_USER_ID=your-roblox-user-id # Optionally, for group uploads: # ROBLOX_GROUP_ID=your-group-id
Project Structure:
Place your assets (e.g., images, audio) in a folder (default:assets/).
Usage
One-time Sync
Uploads all assets in the watched folder and generates the asset map.
npx rbxts-asset-syncWatch Mode
Continuously watches for changes and uploads new/changed assets automatically.
npx rbxts-asset-sync --watchOptions
--path=assetsSet the folder to watch for assets (default:assets)--output=assetMap.tsSet the output path for the generated asset map (default:assetMap.ts)--cache=.rbx-sync-cache.jsonSet the cache file path
Example:
npx rbxts-asset-sync --path=assets --output=src/assetMap.ts --watchIntegration with roblox-ts
The tool generates a TypeScript file (default: assetMap.ts) like:
export const assets = {
"assets/test.png": "rbxassetid://1234567890",
// ...
} as const;
export function getAsset(path: keyof typeof assets): string {
return assets[path];
}Usage in your roblox-ts code:
import { getAsset } from "../../assetMap";
const assetId = getAsset("assets/test.png");
// Use assetId with Roblox APIsChanges to Rojo's file tree and tsconfig.json may be needed if assetMap.ts is outside of src, which is the default setting when no parameters are specified. View default.project.json and tsconfig.json in the example folder for reference.
Integration with VS Code
The rbxts-asset-sync VS Code extension provides a seamless workflow for working with assets in your roblox-ts projects. With the extension installed:
- Asset Previews: Hovering over asset references (such as keys in your generated asset map) shows a preview of the image or audio, along with useful metadata like dimensions or duration.
- Quick Navigation: Easily jump to the asset file in your workspace directly from the hover popup.
- Error Highlighting: Instantly see if an asset reference is missing or invalid, reducing runtime errors.
- Contextual Information: Get additional details about the asset, such as its Roblox asset ID, right in your editor.
These features help you quickly verify asset usage, reduce mistakes, and speed up development by keeping all asset-related information at your fingertips within VS Code.
Scripts Example
Add to your package.json:
{
"scripts": {
"asset-sync": "npx rbxts-asset-sync",
"asset-watch": "npx rbxts-asset-sync --watch"
}
}Troubleshooting
- Ensure your API key has the correct permissions.
- Make sure your
.envfile is present and correctly configured. - If assets are not uploading, check the CLI output for error messages.
GitHub Asset Map Push
If you want to automatically push a JSON asset map to a GitHub repository after syncing, you can use the --github option and a GitHub token. This is useful for sharing asset mappings across projects or CI workflows.
How to Use
Set up a GitHub Personal Access Token
- Go to GitHub Settings > Developer settings > Personal access tokens.
- Click "Generate new token" (classic or fine-grained).
- Give it
reposcope (for private repos) orpublic_repo(for public repos). - Copy the token and add it to your environment as
GITHUB_TOKEN(e.g., in your.envfile):GITHUB_TOKEN=ghp_...yourtoken...
Run the Sync Tool with the
--githubOption- Use the CLI with the
--github=<owner/repo>flag:npx rbxts-asset-sync --github=yourusernamFe/your-repo - The tool will generate a file called
github-asset-map.jsonwith the following structure:{ "<hash>": { "assetId": "<rbxassetid>", "filePath": "<relative/path>" }, ... } - This file will be pushed to the root of the specified repository (on the
mainbranch) as a commit.
- Use the CLI with the
Result
- After the sync completes, you will see
github-asset-map.jsonin your GitHub repository, always up to date with your latest asset uploads.
- After the sync completes, you will see
Example
GITHUB_TOKEN=ghp_...yourtoken... npx rbxts-asset-sync --github=evilbocchi/asset-maps-repoThis will push the asset map to the evilbocchi/asset-maps-repo repository.
License
MIT
