logoContent Collections

CLI

The command line interface (CLI) can be used if no adapter is available for your framework or if you want to use the adapter in a different way. The CLI is a Node.js application that can be run parallel to your dev server and before your production build.

Installation

First, install the required packages:

We have to install the following packages:

  • @content-collections/core
  • @content-collections/next
  • concurrently
npm i @content-collections/core @content-collections/cli concurrently -D

After installation we have to add a path alias for the generated collections to the tsconfig.json:

{
  "compilerOptions": {
    // ...
    "paths": {
      "content-collections": ["./.content-collections/generated"]
    }
  }
}

Add the content-collection cli to your package.json scripts:

{
  "scripts": {
    "dev": "concurrently \"content-collections watch\" \"build-scripts dev\"",
    "build": "content-collections build && build-scripts build"
  }
}

First, we modify the dev script to simultaneously execute the content-collections watch command along with our regular dev command.

Next, we execute the content-collections build command prior to our regular build command.

The build-scripts command is a placeholder for your actual build command. Replace it with the command you use to build your project.

Commands

The CLI provides the following commands:

Watch

content-collections watch watches the configured paths for changes and updates the collections accordingly. This command is useful during development to keep the collections up to date. It is recommended to run this command in parallel to your dev server.

FlagDescription
--config <path>Path to the configuration file. Defaults to content-collections.ts.

Build

content-collections build builds the collections and writes them to the file system. This command is useful for production builds.

FlagDescription
--config <path>Path to the configuration file. Defaults to content-collections.ts.

On this page