Registry
M

playcanvas-esm-scripts

No description available

marklundin11 executions

  • Legacy
  • playcanvas
  • esm
  • scripts
  • migration
Connect a repo
npx codemod playcanvas-esm-scripts

Updates legacy PlayCanvas scripts to the newer ESM Scripts format

This codemod transforms legacy PlayCanvas Scripts into their newer modern equivalents. You can open this codemod and run it over your existing scripts in vscode using the link to the side.

The codemod fully supports all syntax transformations apart from 'json' type attributes..

To run this codemod use

sh
npx codemod playcanvas-esm-scripts -i "./your-file.js"

This will translate the following older Script

javascript
var Rotator = pc.createScript('rotator');

Rotator.attributes.add('speed', { type: 'number', default: 10, min: 0, max: 10 });

Rotator.prototype.update = function (dt) {
    this.entity.rotateLocal(0, this.speed, 0);
};

transforms it into the modern ESM Scripts format

javascript
import { Script } from 'playcanvas'

export class Rotator extends Script {
    /** 
     * @attribute
     * @type {number}
     * @range [0, 10]
     */
    speed = 10;

    update(dt) {
        this.entity.rotateLocal(0, this.speed, 0);
    }
}

It will map any attribute properties to their relevant jsdocs tags according to the spec, and export all classes in the correct format. It will also handle enums correctly.

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.