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

Type and schema generator for Contentrain SDK.

  • 3.0.1
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

@contentrain/generator

Type and schema generator for Contentrain SDK.

Installation

npm install @contentrain/generator

Usage

CLI Usage

# Generate types for all models
contentrain-generate

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

Programmatic Usage

import { ContentrainGenerator } from '@contentrain/generator'

// Initialize generator
const generator = new ContentrainGenerator({
  contentPath: './content',
  output: './types'
})

// Generate types
await generator.generate()

Configuration

interface GeneratorConfig {
  // Path to content directory (default: 'contentrain')
  contentPath?: string

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

Generated Types

The generator creates TypeScript interfaces for your content models. For example:

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

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

// Generated from metadata.json
// {
//   "name": "Author",
//   "modelId": "authors",
//   ...
// }
interface IAuthor extends BaseContentrainModel {
  name: string
  bio: string
  avatar: string
}

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

CLI Options

Options:
  --content    Path to content directory     [string] [default: "contentrain"]
  --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 05 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