@pipeville/sanity-scripts
v0.1.0
Published
Reusable Sanity CMS seeding utilities (plans, stock images, transactions, portable text helpers).
Downloads
93
Readme
@pipeville/sanity-scripts
Declarative Sanity dataset seeding: stock image resolution (reuse by originalFilename or download + upload), phased transaction commits with draft mirrors for Studio, portable text helpers, and transient API retries.
Install
pnpm add @pipeville/sanity-scripts @sanity/client@sanity/client is a peer dependency (^7). You can construct the client with next-sanity’s createClient or @sanity/client’s createClient — both are compatible with these APIs.
Local development (pnpm link)
From this repo, after clone:
pnpm install
pnpm buildIn your app (sibling folder example):
"@pipeville/sanity-scripts": "link:../sanity-scripts"Point the link at your checkout; rebuild this package when you change its source.
Usage
import { createClient } from "next-sanity"; // or @sanity/client
import { defineSeedPlan, runSeedPlan, logSeedFailure } from "@pipeville/sanity-scripts";
const plan = defineSeedPlan({
name: "my-site",
stockImages: [{ key: "hero", url: "https://…", filename: "seed-hero.jpg" }],
phases: [
{
id: "home",
documents: (ctx) => [
/* documents using ctx.imageField("hero"), ctx.ptBlock("…"), … */
],
},
],
});
const client = createClient({ projectId, dataset, apiVersion: "…", useCdn: false, token });
await runSeedPlan(client, plan, projectId, dataset).catch((err) => {
logSeedFailure(err);
process.exit(1);
});API
Exports match the former seed-utils module: defineSeedPlan, runSeedPlan, resolveStockImages, createSeedContext, portable text helpers, retry helpers, commitSeedTransaction, seedLog, logSeedFailure, and related types.
