Tsgen Plugin

The tsgen plugin is a Contentstack CLI plugin that generates TypeScript typings from content types. The type file containing the TypeScript typings assists developers in working with content types in TypeScript.

With the tsgen plugin, you can annotate interfaces and fields with comments from the JSDoc library. Additionally, the tsgen plugin allows you to add prefixes to interfaces.

This step-by-step guide lets you install and use the tsgen plugin in CLI.

Prerequisites

Steps for execution

  1. Install the tsgen plugin using the following command:
  2. csdx plugin:install contentstack-cli-tsgen
  3. Add the delivery token as an alias to the CLI using the following command:
  4. csdx auth:tokens:add -d

    Note: Skip this step if you already have a delivery token.

Usage

$ csdx tsgen

Options

  • -a--token-alias=token-alias: [mandatory] Delivery token alias.
  • -d--[no-]doc: [optional] Includes documentation comments. By default, this flag is enabled.
  • -o--output=output: [mandatory] The full path to output.
  • -p--prefix=prefix: [optional] Interface prefix, e.g., "I".

Examples

  1. To generate a type file with a delivery token alias and output file path:
    $ csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts"
  2. To generate a type file with a prefix:
    $ csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" -p "I"
  3. To generate a type file excluding documentation comments:
    $ csdx tsgen -a "delivery token alias" -o "contentstack/generated.d.ts" --no-doc

Supported Contentstack Fields

  • Number
  • Text
  • IsoDate
  • Boolean
  • Single Select w/ String and Number Types
  • Multiple Select w/ String and Number Types
  • Modular Block
  • Global Field
  • Group
  • Link
  • File
  • References

Supported Field Options

  • Mandatory
  • Multiple
  • Multiple Max Limit
  • Description (used in JSDoc comment)

Was this article helpful?

Thanks for your feedbackSmile-icon

On This Page

^