moon-miniprogram

    MoonBit 微信小程序开发框架:类型安全运行时、状态自动 diff、跨页 store、声明式路由与无头测试基建

    miniprogram
    wechat
    weapp
    wxml
    framework
    Download zip
    Author
    Version
    0.5.3
    License
    Apache-2.0
    Last updated
    2 hours ago
    Downloads
    35

    #moon-miniprogram

    A MoonBit framework for building WeChat Mini Programs — type-safe runtime with automatic state diffing, declarative pages/components/routing, and headless testing infrastructure.

    version tests license CI


    #Features

    • Type-safe runtime — business logic is pure MoonBit code; data flows across the FFI boundary as typed JSON, and misuses are rejected at compile time.
    • Automatic state diffingset_state performs partial merge (React setState semantics) and emits minimal setData path patches; zero calls when nothing changed.
    • Shared cross-page statecreate_store + bind_store subscribe pages and components to a single source of truth; one update propagates minimal patches to all subscribers.
    • Declarative routingregister_route declares paths with parameter allow-lists; navigation never hand-builds URLs, and out-of-schema parameters are stripped with a dev warning instead of raising.
    • Full page / component / app model — typed component properties, observers, page lifetimes, value-returning hooks, and app-global data.
    • Headless testingscripts/sim/wx-sim.js simulates the WeChat runtime (path-aware setData, wx call records); end-to-end tests run without the WeChat DevTools.
    • CLI & scaffoldingscripts/new.cjs generates a project that pulls the framework from mooncakes; mmp.cjs covers check / test / build / dev / release.

    #Installation

    node scripts/new.cjs myapp cd myapp

    The scaffold pulls Magic486/moon-miniprogram from mooncakes.io and wires up the CommonJS export.

    To inspect this repository directly, run node scripts/mmp.cjs release, then import the repository root in WeChat DevTools. The included two-page showcase uses touristappid, so an evaluator can open it without editing project files.

    #Usage

    Business code lives in engine/engine.mbt; Mini Program files contain a single line of assembly.

    let page : @mp.PageDef = {
    path: "pages/index/index",
    data: @mp.jobj([("count", @mp.jnum(0.0))]),
    handlers: [
    ("onTap", (ctx, _payload) => {
    let n = match ctx.get_data() {
    Some(Json::Object(m)) =>
    match m.get("count") {
    Some(Json::Number(d, ..)) => d + 1.0
    _ => 1.0
    }
    _ => 1.0
    }
    ctx.set_state(@mp.jobj([("count", @mp.jnum(n))]))
    }),
    ],
    returns: [],
    }

    // app.js / pages/index/index.js require("./engine/moon-engine.js").launch(); require("../../engine/moon-engine.js").page("pages/index/index");

    Build and run:

    node mmp.cjs check # type check node mmp.cjs test # unit tests node mmp.cjs dev # watch-mode rebuild (open miniprogram/ in WeChat DevTools)

    #Performance

    Diff output is pinned by snapshot tests (runtime/bench_test.mbt); values are serialized JSON character counts per update.

    Scenarioset_state patchFull setData
    Append 1 item to a 1000-item list49 chars34,959 chars
    Change one leaf in a nested object24 chars75 chars
    No change0 chars (no setData call)75 chars

    #Documentation

    • Guide — from zero to a runnable Mini Program; state, components, routing, headless testing, release.
    • Acceptance guide — reproducible automated checks and a short WeChat DevTools review path.
    • References and compliance — originality, upstream references, licenses, and reuse boundaries.
    • wx API coverage table WeChat API coverage, domain by domain.
    • RFC 0001 platform adapter architecture (WeChat is the current target; Alipay / Douyin are designed for).
    • API reference per function is available on the mooncakes package page.

    #Repository

    runtime/ framework core (models, diff engine, store, router, wx bindings, platform probe) engine/ minimal example, used as the smoke-test host engine-export/ CommonJS export wrapper (foreign_library) miniprogram/ importable two-page WeChat DevTools showcase scripts/ scaffolding, mmp CLI, wx simulator, smoke tests, minifier docs/ guide, API coverage table, RFCs

    #Contributing

    git clone https://github.com/Magic486/moon-miniprogram moon test # 54 unit tests powershell scripts/build-example.ps1 # build showcase + 40 smoke assertions

    Bug reports and feature discussions go to GitHub Issues; release notes are on the Releases page.

    #License

    Apache-2.0