New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@contentrain/generator

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentrain/generator

`@contentrain/generator` is a type and schema generator tool for the Contentrain SDK. It generates TypeScript interfaces for your content models and can be used via CLI or programmatically.

  • 3.1.0
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

@contentrain/generator

@contentrain/generator is a type and schema generator tool for the Contentrain SDK. It generates TypeScript interfaces for your content models and can be used via CLI or programmatically.

Installation

You can install the package via npm:

npm install @contentrain/generator

Usage

CLI Usage

The CLI tool allows you to generate type definitions for your models.

# Generate types for all models
contentrain-generate

# Generate types with custom configuration
contentrain-generate --models ./content --output ./types

Programmatic Usage

You can use the ContentrainGenerator class to generate type definitions programmatically.

import { ContentrainGenerator } from '@contentrain/generator';

// Initialize the generator
const generator = new ContentrainGenerator({
  modelsDir: './content',
  outputDir: './types'
});

// Generate types
await generator.generateTypes();

Configuration

The ContentrainGenerator class supports the following configuration options:

interface GeneratorConfig {
  // Path to the models directory (default: 'contentrain/models')
  modelsDir?: string;

  // Output path for generated types (default: 'contentrain/types')
  outputDir?: string;
}

Additionally, you can provide configuration via a contentrain-config.json file in the root directory. This file will be merged with the default configuration.

Generated Types

This tool generates TypeScript interfaces for your content models. Example:

// Base model type that all content models extend
export interface BaseContentrainModel {
  ID: string;
  createdAt: string;
  updatedAt: string;
  status: 'draft' | 'changed' | 'publish';
}

// Generated from metadata.json
// {
//   "name": "BlogPost",
//   "modelId": "blog-posts",
//   ...
// }
interface IBlogPost extends BaseContentrainModel {
  title: string;
  content: string;
  author: string;
  tags: string[];
}

// Type mapping for model IDs to their respective interfaces
export type ContentrainTypeMap = {
  'blog-posts': IBlogPost;
  'authors': IAuthor;
}

CLI Options

The CLI tool supports the following options:

Options:
  --models     Path to the models directory  [string] [default: "contentrain/models"]
  --output     Output path for types         [string] [default: "contentrain/types"]
  --help       Show help                     [boolean]
  --version    Show version number           [boolean]

License

MIT

FAQs

Package last updated on 06 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc