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.5 KB
Raw Blame
interface Ecosystem {
  comment: string
  ecosystem: string
  directory: string
  /** Group-name prefix, unique per block (group names must be unique). */
  group: string
}

/**
 * Renders one `updates:` entry. Security and version updates are each bundled
 * into a single grouped PR per ecosystem (`applies-to`), so a weekly run opens
 * at most one security PR and one version PR instead of one per package.
 */
function ecosystemBlock({ comment, ecosystem, directory, group }: Ecosystem): string {
  return `  # ${comment}
  - package-ecosystem: ${ecosystem}
    directory: "${directory}"
    schedule:
      interval: weekly
    open-pull-requests-limit: 5
    groups:
      ${group}-security:
        applies-to: security-updates
        patterns:
          - "*"
      ${group}-version:
        applies-to: version-updates
        patterns:
          - "*"`
}

/**
 * Dependabot config for a generated project. Covers each package ecosystem in
 * the scaffold: the npm wrapper at the root, the Rails server gems, GitHub
 * Actions, and — when included — the Next.js storefront. Dockerfile base
 * images are intentionally left out: the server runs a prebuilt image until
 * `spree eject`, and the base tags are pinned via ARG defaults.
 *
 * Security updates additionally require the "Dependabot security updates"
 * toggle in the repo's Settings → Advanced Security; the config only groups
 * them.
 */
export function dependabotContent(
  hasStorefront: boolean,
  hasDashboard = false,
  hasSellerDashboard = false,
): string {
  const ecosystems: Ecosystem[] = [
    {
      comment: 'Root wrapper (@spree/cli, @spree/docs)',
      ecosystem: 'npm',
      directory: '/',
      group: 'root',
    },
    {
      comment: 'Rails server gems',
      ecosystem: 'bundler',
      directory: '/server',
      group: 'server',
    },
    {
      comment: 'CI workflows',
      ecosystem: 'github-actions',
      directory: '/',
      group: 'actions',
    },
  ]

  if (hasStorefront) {
    ecosystems.push({
      comment: 'Next.js storefront',
      ecosystem: 'npm',
      directory: '/apps/storefront',
      group: 'storefront',
    })
  }

  if (hasDashboard) {
    ecosystems.push({
      comment: 'Admin Dashboard',
      ecosystem: 'npm',
      directory: '/apps/dashboard',
      group: 'dashboard',
    })
  }

  if (hasSellerDashboard) {
    ecosystems.push({
      comment: 'Seller Panel',
      ecosystem: 'npm',
      directory: '/apps/seller-dashboard',
      group: 'seller-dashboard',
    })
  }

  return `version: 2
updates:
${ecosystems.map(ecosystemBlock).join('\n\n')}
`
}