Skip to content

Migrating Addons from Devkit1 to Devkit2

jwilm edited this page Nov 10, 2014 · 5 revisions

NOTE: This is a work in progress. If you have alternative directions, please update this document.

Devkit2 makes a major change to the way addons are managed in devkit games, most notably changing the import process and allowing specific checkouts of each addon per game (so you can update the addons in one game without breaking your other games).

Migrating a devkit 1 addon to support devkit 2 is easy. The following instructions should work for pretty much any addon. If you migrate an addon, please include a short test application and any necessary install instructions (for example, if you need 3rd party SDKs). This will help the maintainers validate the functionality and will serve as a great jumping off point for new developers who want to use the addon.

Step 1

Add a top level package.json which exposes the import paths -- this is the example for flurry. In this example, the key in the “clientPaths” object indicates that in your game code, importing flurry will import the js/index.js file.

{
  "name": "devkit-flurry",
  "version": "0.0.1",
  "devkit": {
    "clientPaths": {
      "flurry": "js"
    },
    "extensions": {
      "android": "android",
      "ios": "ios"
    }
  }
}

Step 2

Remove any top level index.js files, or anything else that exists just to change import paths.

Devkit2 prefers imports that look like “import flurry” rather than “import flurry.flurry”. To achieve this, you need to create an index.js file in the js folder of your addon. If you had a previous main file in your folder, e.g. flurry/js/flurry.js, then you simply need to rename it to index.js (eg. flurry/js/flurry.js -> flurry/js/index.js).

Step 3

Update the README.md with the devkit2 installation and import/usage information.

Make special notes for your users about updating their games when they switch from the devkit1 version to the devkit2 version (particularly changed imports).

Step 4

If you’re hosting the addon on github, users will be able to install your addon by running: devkit install https://github.com/[username]/[addon-repo]#tag-name

Step 5

Update any imports within the project if necessary (ex: accelerometer ShakeDetect imported accelerometer locally with import .accelerometer -- this was updated to import accelerometer)

Step 6

Include a short test application and any necessary install instructions (for example, if you need 3rd party SDKs). This will help the maintainers validate the functionality and will serve as a great jumping off point for new developers who want to use the addon.

Example: Migrating the Accelerometer Plugin:

Devkit 1

Original Usage:
import plugins.accelerometer.accelerometer;
import plugins.accelerometer.ShakeDetect;
Original File Structure:
accelerometer
├── index.js
├── js
    ├── accelerometer.js
    └── ShakeDetect.js
├── android
    └── ...
└── ios
    └── ...

Devkit 2

New Usage:
import accelerometer;
import accelerometer.util.shakedetect;
New File Structure:
accelerometer
├── package.json
├── js
├── accelerometer
    ├──index.js
    └── util
        └── shakedetect
            └── index.js
├── android
    └── ...
├── ios
    └── ...

Package.json

{
  "name": "devkit-accelerometer",
  "version": "0.0.1",
  "devkit": {
    "clientPaths": {
      "accelerometer": "js/accelerometer"
    },
    "extensions": {
      "android": "android",
      "ios": "ios"
    }
  }
}