02. Client SDK/CLI Toolbelt

Enterprise CLI (npx apex)

The CLI manages offline content synchronization, schema validation, TypeScript generation, and edge deployments through a Git-like workflow.

GIT-LIKE WORKFLOW
Diff & Push
Atomic Upstream Synchronizations

“Track local schema modifications against the remote database with colorized diffs and conflict guards.”

npx apex diff · npx apex push

CLI Command Catalog

WIZARD

npx apex init

Scans project, creates .env.local, injects /sw.js, and auto-generates the Next.js revalidation route.

SYNC

npx apex pull

Downloads production schemas and compiles offline .nx encrypted binaries.

CHANGESET

npx apex diff

Shows pending changes (Added, Removed, Modified) between your local sandbox and upstream.

DEPLOY

npx apex push

Validates against schema and executes an atomic push transaction to production.

npx apex init

Runs the interactive initialization wizard:

  1. Detects your framework (Next.js App Router, Vite, Astro, SvelteKit).
  2. Validates Project ID & API Key against the Control Plane.
  3. Writes credentials to .env.local and updates .gitignore.
  4. Injects the Next.js revalidation route (app/api/revalidate/route.ts).
  5. Injects the PWA WebPush service worker (public/sw.js).
  6. Provisions dependencies (@gnapex/sdk, @opennextjs/cloudflare).

npx apex pull

Downloads remote content and creates an encrypted upstream baseline (origin.nx):

1$ npx apex pull
2✔ Connected to GN-Apex Edge API
3✔ Pulled 4 pages
4✔ Pulled 2 collections (blog_posts, products)
5✔ Compiled .nexus/origin.nx upstream baseline
6✔ Content synchronized successfully!

npx apex diff

Compares your local .nexus/local/*.nx binaries against origin.nx:

1$ npx apex diff
2Pending Changeset:
3 + [Added] blog_posts[2]: {"title": "Announcing v2.0", "slug": "v2"}
4 ~ [Modified] pages.home.hero_title: -"Old Headline" +"The Sovereign Platform"
5 - [Removed] pages.about.deprecated_field
6 
7Total changes: 3 (use 'npx apex push' to publish)

npx apex push

Validates your local data against the schema and pushes it live. Includes an upstream conflict-checking guard to prevent overwriting coworker changes made in the dashboard:

Conflict Resolution
If someone edited content in the dashboard after your last npx apex pull, the push will abort with a conflict warning. Run npx apex pull to re-sync or append --force to overwrite.

npx apex types

Auto-generates strict TypeScript definitions from your CMS schema:

1$ npx apex types --output types/nexus.d.ts
2✔ Schema loaded (4 pages, 2 collections)
3✔ Generated types/nexus.d.ts (184 lines)
4✔ Augmented @gnapex/sdk ContentEngine

npx apex deploy

Compiles your Next.js application and deploys it directly to Cloudflare Pages:

  1. Requests an ephemeral 15-minute scoped deployment token from the Control Plane.
  2. Provisions a Cloudflare D1 tag cache database ([project]-tag-cache).
  3. Provisions a Cloudflare R2 cache bucket ([project]-cache-r2).
  4. Builds standalone output using opennextjs-cloudflare.
  5. Transfers assets to Cloudflare and binds your custom subdomain.

npx apex doctor

Runs a diagnostic health check on your local environment (Node version, lockfile integrity, API connectivity, and package installation).