Skip to content

About

The addons of Astratch

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

AstratchAddons

简体中文

The plugin center of Astratch — source code, compiled release artifacts, and build scripts.

No self-hosted server, database, GitHub Pages, or backend. Distribution and updates rely only on GitHub's public infrastructure — the repo itself, Raw links, and GitHub Actions.

How it works

GitHub Actions (push to main)
   │  npm ci → typecheck → validate → build → prepare-release
   ▼
main branch:
  addons/<id>/info.yaml, main.tsx, ...   ← source code only

release branch (append-only, never removes old versions):
  <id>@v<version>/                        ← flat release dirs (addon.js, info.json, assets/, i18n/)
  registry.json                           ← store entry (generated during release, not on main)
   │
   ▼
Astratch (runtime)
   1. startup → reads cached registry → shows the store immediately
   2. silently fetches the latest registry.json from release branch → updates the cache
   3. downloads <id>@v<version>/addon.js via GitHub Raw when the user installs an addon

The release branch is append-only — old versions are never removed or overwritten. New versions are added alongside existing ones.

Structure

addons.json                   List of released addon ids (source of truth for CI)
schemas/info.schema.json      JSON schema that validates every addon's info.yaml
addons/<id>/
  info.yaml                   Addon metadata (id, name, version, main, settings, ...)
  main.tsx / main.ts          TypeScript source (compiled by CI)
  main.js                     Plain JavaScript source
  assets/icon.svg             Addon icon
  i18n/<locale>.json          Optional user-visible translations
  README/<locale>.md          Optional localized README files
  releases/<version>/         Compiled release artifacts (gitignored on main, lives on release branch)
    addon.js                  Compiled entry point
    info.json                 info.yaml converted to JSON
    assets/                   Copied resources
scripts/
  build.mjs                   Compiles each addon to releases/<version>/
  validate.mjs                Validates all addons' info.yaml against the schema
  prepare-release.mjs         Generates registry.json + copies releases to flat <id>@v<version>/ dirs
.gitattributes                Marks releases/** as linguist-generated

Release branch

A separate orphan release branch contains only compiled artifacts:

<id>@v<version>/              ← flat release dirs
  addon.js
  info.json
  assets/
  i18n/
  README/
registry.json                 ← generated store entry (not on main)

No source code, no scripts, no workflow files. The Astratch runtime fetches from this branch.

info.yaml

Every addon lives in addons/<id>/ and is described by an info.yaml:

id: example
name: Example Addon
version: 1.0.0
author: AstrasTeam
description: A sample addon that shows a notification when enabled.
license: MIT
icon: assets/icon.svg
main: main.tsx          # required — .ts/.tsx for TS, .js for plain JS
typescript: true        # set when main is .ts/.tsx
defaultEnabled: false

astratch:
  version: '>=1.0.0'
  settings:
    - name: greeting name
      id: name
      type: string
      default: world

Fields

Field Required Description
id yes Must match the folder name. Pattern: ^[a-z0-9]+(-[a-z0-9]+)*$
name yes Display name
version yes Semver; bumping creates a new immutable release
author yes Author name
description yes Short description
icon yes Path to icon inside the addon folder
main yes Entry point. Must be .ts/.tsx when typescript: true, .js otherwise
license no License identifier (default: MIT)
typescript no true when source is TypeScript/JSX
files no Extra JS files to include for multi-file plain JS addons
defaultEnabled no Whether the addon starts enabled for new users
astratch.version no Compatible Astratch version range (semver range)
astratch.settings no Array of setting definitions (see below)

Settings

Declared under astratch.settings. Each becomes a control in the Astratch Settings panel:

astratch:
  settings:
    - name: greeting name    # display label (translatable via @settings/<id>)
      id: name               # unique key for read/write
      type: string           # "string" | "number" | "boolean"
      default: world         # default value
      min: 0                 # (number) minimum
      max: 100               # (number) maximum
      allowLines: true       # (string) render as textarea

Multi-file plain JS addons

TypeScript addons are bundled by esbuild into a single addon.js. For plain JS addons with multiple files, use the files field:

main: main.js
files:
  - utils.js       # specific file
  - lib/           # all .js files under lib/ (recursive)

The entry point (main) is always included. The build and the runtime both bundle listed files into a single addon.js.

registry.json

Generated by prepare-release.mjs and deployed only to the release branch. Not committed to main.

{
  "schemaVersion": 1,
  "generatedAt": "2026-08-20T...",
  "addons": [
    {
      "id": "example",
      "name": "Example Addon",
      "version": "1.0.0",
      "author": "AstrasTeam",
      "description": "...",
      "license": "MIT",
      "icon": "assets/icon.svg",
      "defaultEnabled": false,
      "settings": [...],
      "i18n": ["en", "zh-CN"],
      "readme": ["en", "zh-CN"],
      "astratch": { "version": ">=1.0.0" },
      "versions": ["1.0.0", "1.1.0"]
    }
  ]
}

Icon, i18n, and README use paths relative to the version directory, not inline data. The client fetches them on demand.

Releasing

  1. Bump version in addons/<id>/info.yaml
  2. Commit to main
  3. CI builds releases/<new-version>/, generates registry.json, and force-pushes the release branch

Existing version directories are never overwritten.

Writing an addon

The entry point must default-export a function:

export default (ctx: AddonContext) => void | (() => void)

Return a cleanup function to run when the addon is disabled.

TypeScript/JSX

Set main: main.tsx (or main.ts) and typescript: true in info.yaml. JSX is supported — import h and Fragment from ../../shared/jsx:

import { h } from "../../shared/jsx";
import type { AddonContext } from "../../shared/types";

export default (ctx: AddonContext) => {
  ctx.toast.create({
    type: "info",
    id: "example_greet",
    text: ctx.t("addon_example:greet"),
  });
};

Plain JavaScript

Set main: main.js (no typescript key):

export default (ctx) => {
  ctx.toast.create({
    type: "info",
    id: "my_greet",
    text: "Hello from my addon!",
  });
};

AddonContext API

Property Type Description
vm IVM The virtual machine
blockly Blockly Blockly instance
toast IToastManager Notification manager
t TFunction i18next translation function
storage IAddonStorage Namespace-scoped key-value storage
settings IAddonSettingsApi Read/write addon settings

i18n

Translations live in i18n/<locale>.json, registered under namespace addon_<id>:

{
  "@name": "My Addon",
  "@description": "What it does",
  "@settings/name": "Greeting name",
  "greet": "Hello!"
}

Use in code: ctx.t("addon_<id>:key")

Building

npm install
npm run check            # typecheck + validate + build
npm run prepare-release  # generate registry.json + copy releases to flat <id>@v<version>/ dirs

GitHub Actions runs npm run check on every push to main, then runs prepare-release and force-pushes the release branch with the generated registry.json and compiled artifacts. To release an addon, add its id to addons.json and commit the source.

About

The addons of Astratch

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages