MixeryOSS / engine

The Mixery engine, as known as "the heart of Mixery Digital Audio Workspace"
GNU General Public License v3.0
1 stars 0 forks source link

Create addons using node packages #3

Open nahkd123 opened 1 year ago

nahkd123 commented 1 year ago

A typical node package consists of package.json, package-lock.json and some source files.

We want to use this package format for all Mixery addons. Basically, you can use npm pack, put it into Mixery DAW and it will automatically unpack, build TypeScript sources (if needed) and run as an addon.

But first, I need to find a way to "link" @mixery/* imports to Mixery namespace (which will be available in globalThis).

nahkd123 commented 1 year ago

By using external option in esbuild, I can build a script that can be loaded in browser but also uses require() to import external modules, such as @mixery/engine, @mixery/uikit or @mixery/state-machine.

@mixery/engine doesn't come with @mixery/uikit, so we need to somehow get uikit tells the engine that it exists. Or we can just add uikit to workspace inside DAW module.

// "@mixery/daw"
import * as uikit from "@mixery/uikit";

workspace.requires.set("@mixery/uikit", uikit);

let ext = new ExternalAddonLoader();
ext.runScript("require('@mixery/uikit')");
nahkd123 commented 1 year ago

A new repository was created with addon generator and builder, which build whatever addon that is in current working directory into script.js, which can be loaded using Mixery Engine.

The Workspace.loadAddonFromUrl() method will be pushed soon. It's almost 2AM in the morning and I need to sleep.

(yes I know loading addons from URL is not safe, but if we show warning message when they are about to enter addon URL, I think it should be fine).