A solution to using a remote ide


Like most people, I like the play canvas ide,especially it’s auto complete. From time to time I like to refractor and I need a way to quickly edit code from there to here. So I nabbed the playcanvaswebpackplugin, zombie’d it, and wrote this script. Works with an exported project to save it back up.

const fs= require('fs');

const request = require('request-promise')
var filepath =process.argv[process.argv.length -1];
var match =/(\d+)\\\d\\([a-zA-Z0-9_-]+\.js)$/.exec(filepath)
if(!match) process.exit();

var assetId = match[1];
var content = fs.readFileSync(filepath,'utf8'); 
let options = {
   "bearer": " ",
   "assetId": assetId,
   "project":  '' 

   console.log("Uploading " + filepath  + " to PlayCanvas") 
   let req = request({
       uri: `https://playcanvas.com/api/assets/${assetId}`,
       method: 'PUT',
       headers: {
           "Authorization": `Bearer ${options.bearer}`
   let form = req.form()
    form.append("file", content, {
       filename: filepath,
       contentType: "text/javascript"
   req.then(() => {
       console.log("Upload complete for file " + filepath)
   }, (e) => {

you can use it on save to auto upload existing asset. tested