Skip to content

Project Structure ​

After running acodez init, your project directory will look like this:

my-plugin/
├── src/
│   ├── index.ts         ← Plugin entry point (lifecycle & settings)
│   ├── commands/
│   │   └── index.ts     ← Command palette registrations
│   ├── styles/
│   │   └── main.scss    ← Plugin styles (SASS)
│   └── types/
│       ├── module.d.ts  ← Ambient module declarations
│       └── styles.d.ts  ← SCSS raw string module declaration
├── dist/                ← Compiled output (auto-generated)
│   └── main.js
├── .gitignore           ← Ignores dist/, node_modules/, test/, etc.
├── plugin.json          ← Acode plugin manifest
├── icon.png             ← Plugin icon (auto-optimized on build)
├── readme.md            ← Plugin readme (shown in Acode)
├── changelogs.md        ← Plugin changelogs (shown in Acode)
├── package.json
├── tsconfig.json        ← Pre-configured with acode-plugin-types
└── plugin.zip           ← Final distributable (auto-generated)

Key Files ​

plugin.json — The Manifest ​

This is the most important file. Acode reads this to register your plugin in the marketplace.

json
{
  "id": "com.yourname.myplugin",
  "name": "My Plugin",
  "version": "1.0.0",
  "main": "dist/main.js",
  "icon": "icon.png",
  "readme": "readme.md",
  "changelogs": "changelogs.md",
  "keywords": ["editor", "tool"],
  "minVersionCode": 290,
  "price": 0,
  "author": {
    "name": "Your Name",
    "email": "",
    "github": ""
  }
}

src/index.ts — The Entry Point ​

The core of your plugin. This class is instantiated by Acode when your plugin is loaded.

typescript
import plugin from "../plugin.json";
import { registerCommands, unregisterCommands } from "./commands/index";
import style from "./styles/main.scss";

class AcodePlugin {
  public baseUrl: string = "";
  public $page: Acode.WCPage | null = null;
  public ctx: Acode.PluginContext | null = null;
  private readonly styleId = `${plugin.id}-styles`;
  public settingsState: Record<string, unknown> = {
    showToastOnStart: true,
  };

  public async init(
    baseUrl: string,
    $page: Acode.WCPage,
    options: Acode.PluginInitOptions
  ): Promise<void> {
    this.baseUrl = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
    this.$page = $page;
    this.ctx = options?.ctx ?? null;

    // 1. Inject plugin stylesheet
    const styleSheet = document.createElement("style");
    styleSheet.id = this.styleId;
    styleSheet.textContent = style;
    document.head.appendChild(styleSheet);

    // 2. Register commands to command palette
    registerCommands(this);

    // 3. Optional welcome toast
    if (this.settingsState.showToastOnStart) {
      const toast = acode.require("toast");
      if (toast) {
        toast(`${plugin.name} loaded successfully!`, 3000);
      }
    }
  }

  public get settings(): Acode.PluginSettings {
    return {
      list: [
        {
          key: "showToastOnStart",
          text: "Show Welcome Toast",
          info: "Display a toast notification whenever the plugin initializes",
          checkbox: Boolean(this.settingsState.showToastOnStart),
        },
      ],
      cb: (key: string, value: unknown) => {
        this.settingsState[key] = value;
      },
    };
  }

  public async destroy(): Promise<void> {
    document.getElementById(this.styleId)?.remove();
    unregisterCommands();
  }
}

if (window.acode) {
  const acodePlugin = new AcodePlugin();
  window.acode.setPluginInit(
    plugin.id,
    async (baseUrl: string, $page: Acode.WCPage, options: Acode.PluginInitOptions) => {
      await acodePlugin.init(baseUrl, $page, options);
    },
    acodePlugin.settings
  );
  window.acode.setPluginUnmount(plugin.id, () => {
    void acodePlugin.destroy();
  });
}

tsconfig.json — TypeScript Config ​

Pre-configured for the Acode WebView target (Chrome 90+) and fully typed via acode-plugin-types.

json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ES2020",
    "lib": ["ES2020", "DOM"],
    "strict": true,
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "noEmit": true,
    "types": ["acode-plugin-types"]
  },
  "include": ["src"]
}

Built with precision by Rugved.