Structure

Main.js follows a consistent internal structure that all expansions adhere to. Understanding this structure helps you organize your code efficiently.


1. Module Exports

At the very top/bottom of the file:

module.exports.init = async () => { /**/ };
module.exports.metadata = { id: "apitest", version: "0.1" };
  • init: Entry point where everything is registered.

  • metadata: Basic info about the expansion (ID and version).


2. Initialization Function (init)

The init function is structured in a logical sequence:

  1. Access the internal API

    const nm = api.nexomaker;

    Provides all methods for registration, asset loading, and exporting.

  2. Optional logging

    api.console.log("Initializing expansion...");
  3. Register UI pages

    nm.registerModularPage("pageName", pathToComponent);
  4. Register overlays or background modules

    nm.registerBackgroundModule("overlayName", pathToOverlay, options);
  5. Load assets and models

    const icon = await nm.loadAsset(iconPath);
    const model = await nm.loadModel(modelPath);
    const texture = await nm.loadAsset(texturePath);
  6. Register sidebar buttons, templates, editor modules

    nm.postSidebarIcon({ /* ... */ });
    nm.postTemplate({ /* ... */ });
    nm.postEditorModule({ /* ... */ });
  7. Define export formats

    nm.postExportFormat(exportFormatObject);

The order is not strictly enforced, but this sequence ensures clarity and avoids dependency issues.


3. File References and Organization

Within Main.js, you reference other parts of the expansion:

  • Pages/ → React components for pages.

  • Components/ → Reusable UI components.

  • Overlays/ → Modular overlays or background modules.

  • Assets/ → Icons, textures, 3D models.

Main.js itself contains no UI logic; it only registers components and modules. This folder names and structures are just suggestions.


5. Key Structural Tips

  • Keep sections clearly separated (Pages, Overlays, Assets, Templates, Export Formats).

  • Use async/await for loading assets or models to avoid race conditions.

  • Always test that each registered component is accessible in Nexo Maker after adding it.

Last updated