Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

2.0 KB
Raw Blame
import { PNPM_VERSION } from '../constants.js'
import type { PackageManager } from '../types.js'

/**
 * Root package.json for a generated project: the `spree` convenience scripts
 * plus `@spree/cli` / `@spree/docs` as dependencies. On pnpm scaffolds (the
 * default, matching detection) it also pins `packageManager: pnpm@…`; omitted
 * for npm/yarn, which don't read it and corepack would misfire on.
 */
export function rootPackageJsonContent(name: string, pm: PackageManager = 'pnpm'): string {
  const pkg = {
    name,
    private: true,
    // Steers corepack and doubles as the pnpm/action-setup fallback when a
    // workflow runs from the root. Omitted for npm/yarn scaffolds — they
    // don't read it, and a pnpm pin would make corepack block yarn outright.
    ...(pm === 'pnpm' ? { packageManager: `pnpm@${PNPM_VERSION}` } : {}),
    scripts: {
      dev: 'spree dev',
      stop: 'spree stop',
      down: 'docker compose down',
      upgrade: 'spree upgrade',
      eject: 'spree eject',
      logs: 'spree logs',
      'logs:worker': 'spree logs worker',
      seed: 'spree seed',
      'load-sample-data': 'spree sample-data',
      console: 'spree console',
      api: 'spree api',
      auth: 'spree auth',
      'api-key': 'spree api-key',
    },
    dependencies: {
      // The floor matches the CLI behavior this scaffold relies on (the
      // --quiet delegation, dev co-run, first-run setup, and `spree add
      // seller-dashboard`) — an older resolve rejects the flags and silently
      // drops an admin app. Bump it in lockstep with any new CLI capability
      // the scaffold calls, or the scaffold asks for something the pinned CLI
      // has never heard of.
      // SPREE_CLI_VERSION overrides the spec for testing unreleased CLIs —
      // a range, or a `file:`/`link:` path to a packed tarball / checkout
      // (mirrors the starter Dockerfile's ARG of the same name).
      '@spree/cli': process.env.SPREE_CLI_VERSION ?? '^3.4.0',
      '@spree/docs': 'latest',
    },
  }

  return `${JSON.stringify(pkg, null, 2)}\n`
}