CatmintAdapter

Interface for platform-specific deployment adapters. Implement this interface to add support for a new deployment target.

Import

import type { CatmintAdapter } from 'catmint/config'

Signature

interface CatmintAdapter {
  name: string
  adapt(context: AdapterContext): Promise<void>
}

Properties

PropertyTypeDescription
namestringUnique identifier for the adapter (e.g. '@catmint/adapter-node').
adapt(context: AdapterContext) => Promise<void>Called after the build completes. Transforms build output into platform-specific artifacts.

AdapterContext

The context object passed to adapt() during the build process:

interface AdapterContext {
  manifest: unknown
  serverDir: string
  clientDir: string
  staticDir: string
  writeFile(path: string, content: string | Buffer): Promise<void>
  copyDir(src: string, dest: string): Promise<void>
  log: (message: string) => void
}
PropertyTypeDescription
manifestunknownThe build manifest describing routes, server functions, and assets.
serverDirstringAbsolute path to the server build output directory.
clientDirstringAbsolute path to the client build output directory.
staticDirstringAbsolute path to the pre-rendered static pages directory.
writeFile(path: string, content: string | Buffer) => Promise<void>Write a file to the output.
copyDir(src: string, dest: string) => Promise<void>Copy a directory recursively.
log(message: string) => voidLog a message during the adapt step.

Examples

// Using a built-in adapter
import { defineConfig } from 'catmint/config'
import node from '@catmint/adapter-node'

export default defineConfig({
  adapter: node({ port: 3000 }),
})
// Implementing a custom adapter
import type { CatmintAdapter, AdapterContext } from 'catmint/config'

function myAdapter(): CatmintAdapter {
  return {
    name: 'my-custom-adapter',
    async adapt(context: AdapterContext) {
      context.log('Building custom output...')

      // Copy static assets
      await context.copyDir(context.clientDir, '/output/public')

      // Generate a custom entry point
      await context.writeFile('/output/index.js', `
        import { handler } from './server/handler.js'
        export default handler
      `)
    },
  }
}

See Also