From b1c3295bdf515e7960dc60987203d24dc810fe37 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 25 Sep 2026 10:41:22 +0000 Subject: [PATCH] fix(examples): restore --offchain and vanity examples dropped from source DEV-180: two example source files had accumulated drift from their published index.js because nobody had re-run `node scripts/build-examples.js` after a bad edit. - src/examples/core/create-asset/cli.sh: source used --json where the real flag on `mplx core asset create --files` is --offchain (confirmed against metaplex-foundation/cli src/commands/core/asset/create.ts, which declares an `offchain` flag and has no `json` file-metadata flag at all). The published index.js already had this right and also had a vanity-asset-address example the source was missing -- source, not the published output, was wrong on both counts. Restored --offchain and the vanity example. - src/examples/token-metadata/fungibles/create/cli.sh: same shape of drift -- the source was missing a vanity-mint-address example (--mint-keypair, confirmed as a real flag on `toolbox token create` in the same CLI source) that the published index.js still had. Restored it. Regenerating both (`node scripts/build-examples.js`) now produces a diff of exactly zero against the committed index.js files -- source and output are back in sync. Ran the regenerator across the whole `src/examples/` tree to confirm no other directory has silent drift; none did. Also adds .github/workflows/examples-drift.yml (the ticket's suggested follow-up): runs build-examples on every PR touching src/examples/** and fails if it produces an uncommitted diff, modeled directly on the existing heading-anchors.yml workflow (same pinned action SHAs, same read-only permissions, same no-persist-credentials checkout). --- .github/workflows/examples-drift.yml | 48 +++++++++++++++++++ src/examples/core/create-asset/cli.sh | 8 +++- .../token-metadata/fungibles/create/cli.sh | 7 +++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/examples-drift.yml diff --git a/.github/workflows/examples-drift.yml b/.github/workflows/examples-drift.yml new file mode 100644 index 000000000..ed88bc1fe --- /dev/null +++ b/.github/workflows/examples-drift.yml @@ -0,0 +1,48 @@ +name: Examples drift + +# Fails when a src/examples/**/index.js is out of sync with the native +# source files (kit.js, umi.js, cli.sh, etc.) it's generated from, so a +# hand-edited source can no longer drift silently from the published docs. + +on: + pull_request: + paths: + - 'src/examples/**' + - 'scripts/build-examples.js' + - 'package.json' + - '.github/workflows/examples-drift.yml' + push: + branches: [main] + +# This job checks out and installs pull-request-controlled code, so it gets no +# more than read access and never keeps the checkout token on disk. +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + steps: + # Actions are pinned to commit SHAs; a tag can be moved, a SHA cannot. + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false + + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 + + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: + node-version: 20 + cache: pnpm + + - run: pnpm install --frozen-lockfile + + - run: pnpm run build-examples + + - name: Fail if build-examples produced a diff + run: | + if ! git diff --quiet -- src/examples; then + echo "::error::src/examples/**/index.js is out of sync with its source files. Run 'pnpm run build-examples' locally and commit the result." + git diff --stat -- src/examples + exit 1 + fi diff --git a/src/examples/core/create-asset/cli.sh b/src/examples/core/create-asset/cli.sh index e1c544bd6..90017fbf5 100644 --- a/src/examples/core/create-asset/cli.sh +++ b/src/examples/core/create-asset/cli.sh @@ -7,4 +7,10 @@ mplx core asset create --wizard mplx core asset create --name "My NFT" --uri "https://example.com/metadata.json" # Create with files (image + metadata) -mplx core asset create --files --image "./my-nft.png" --json "./metadata.json" +mplx core asset create --files --image "./my-nft.png" --offchain "./metadata.json" + +# Create with a vanity asset address +mplx core asset create \ + --name "My NFT" \ + --uri "https://example.com/metadata.json" \ + --mint-keypair ./vanity-asset.json diff --git a/src/examples/token-metadata/fungibles/create/cli.sh b/src/examples/token-metadata/fungibles/create/cli.sh index a69d5fff4..43d98b64b 100644 --- a/src/examples/token-metadata/fungibles/create/cli.sh +++ b/src/examples/token-metadata/fungibles/create/cli.sh @@ -18,6 +18,13 @@ mplx toolbox token create \ --decimals 9 \ --mint-amount 1000000000000000 +# Create with a vanity mint address +mplx toolbox token create \ + --name "Cool Token" \ + --symbol "COOL" \ + --mint-amount 1000000 \ + --mint-keypair ./vanity-mint.json + # Note: mint-amount is in smallest units # With --decimals 9, to mint 1,000,000 tokens: --mint-amount 1000000000000000 # With --decimals 0 (default), to mint 1,000,000 tokens: --mint-amount 1000000