This is a repo with a setup of tools to handle some of the more common needs of users with the REST API.
Currently they are:
- Downloading a build to self host
- Downloading a build and add Content Security Policy (CSP) rules
- Archiving a project for offline backup and importing a branch into a new project
- Archiving all branches in a project for backup
All downloaded files can be found in temp/out
.
Install Node JS (v12+)
- Clone this repo
mv .env.template .env
and add your PlayCanvas Auth Token in theremv config.template.json config.json
and add your configuration in there (Project name, branch, scenes, CSP rules, etc. The parameters for the PlayCanvas object are explained in the User Manual).npm install
This uses the Download App REST API to download a build from your project to self host.
npm run download
$ npm run download
✔️ Requested build from Playcanvas
↪️ Polling job 99999
job still running
will wait 1s and then retry
↪️ Polling job 99999
✔️ Job complete!
✔ Downloading zip https://somefilename.zip
Success somefilename_Download.zip
This uses the Download App REST API to download a build from your project to self host.
It will unzip the build, add the CSP rules to the index.html
file and rezip the project.
Please configure the CSP lists in config.json
under csp
.
npm run csp
$ npm run csp
✔️ Requested build from Playcanvas
↪️ Polling job 99999
job still running
will wait 1s and then retry
↪️ Polling job 99999
✔️ Job complete!
✔ Downloading zip https://somefilename.zip
✔️ Adding CSP
✔️ Zipping it all back again
✔️... Done! somefilename_WithCSP.zip
This uses the Archive Project REST API to archive a single branch that can be imported into a new project on PlayCanvas.
npm run archive
$ npm run archive
✔️ Requested archive from Playcanvas
↪️ Polling job 99999
job still running
will wait 1s and then retry
↪️ Polling job 99999
✔️ Job complete!
✔ Downloading zip https://somefilename.zip
Success somefilename_Download.zip
This uses the Archive Project and List Branches REST APIs to download all open branches in a project.
As the API is strict limited, it is a slow job and may take a while to complete if you have a lot of branches.
npm run archive-all
$ npm run archive-all
✔️ Requested branch list from Playcanvas
↪️ Processing branch list from Playcanvas
↪️ Start archiving all 2 branches...
↪️ 1 of 2 branches: b1
✔️ Requested archive from Playcanvas
↪️ Polling job 99999
job still running
will wait 1s and then retry
↪️ Polling job 99999
✔️ Job complete!
✔ Downloading zip https://somefilename.zip
↪️ 2 of 2 branches: b10
✔️ Requested archive from Playcanvas
↪️ Polling job 99999
job still running
will wait 1s and then retry
↪️ Polling job 99999
✔️ Job complete!
✔ Downloading zip hhttps://somefilename.zip
Success
This uses the Download App REST API to download a build from your project to self host.
The script will then unzip the project, convert assets, scripts, etc into Base64 and embed them into the index.html with the intention to be used for some playable ads formats.
Once finished, it will copy the HTML file to the out folder.
There are some limitations:
- Modules are not supported (Basis and Ammo)
- Texture compression formats are not supported
Spine runtime is not supportedNow supported since since PR#42- Any code relying on asset URLs being a file path will not work as they will be Base64 encoded
Adds an engine patch to remove any XHR requests and decodes the base64 URLs directly. This may be required for some platforms where this is not permitted. As this is a patch, there may be edge cases where some asset types may not work. If you find any any, please report them in the issues.
The option can be found in config.json
under one_page
. Set patch_xhr_out
to true.
Adds an engine patch to decode base64 URLS for JS scripts when the engine adds them to the page document. This may be required for some platforms that block base64 encoded JS URLs. As this is a patch, there may be edge cases where some asset types may not work. If you find any any, please report them in the issues.
The option can be found in config.json
under one_page
. Set inline_game_scripts
to true.
Enabling this will keep the PlayCanvas engine code and game data as separate files. It will also zip up these files as the output file. This can be used for platforms that have a larger allowance for a zipped package to be used compared to a single HTML file.
The option can be found in config.json
under one_page
. Set extern_files
to true.
npm run one-page
$ npm run one-page
✔️ Requested build from Playcanvas
↪️ Polling job 710439
job still running
will wait 1s and then retry
↪️ Polling job 710439
✔️ Job complete!
✔ Downloading zip someBuild.zip
✔️ Unzipping someBuild.zip
↪️ Removing manifest.json
↪️ Removing __modules__.js
↪️ Inlining style.css into index.html
↪️ Base64 encode all urls in config.json
↪️ Remove __loading__.js
↪️ Base64 encode the scene JSON and config JSON files
↪️ Patching __start__.js
↪️ Inline JS scripts in index.html
✔️ Finishing up
Success someProject.html