A vanilla TypeScript library for defining and managing content models for headless CMS implementations using Optical (a GovTech product wrapping Directus). This library provides type-safe content models and utilities that map to the Optical CMS API responses and SGDS web components.
- Vanilla TypeScript/JavaScript with no framework dependencies
- Type-safe content model definitions
- SGDS web component integration
- Lightweight and framework-agnostic design
- Built with
@govtechsg/sgds-web-componentfor consistent UI
├── src/
│ ├── models/ # TypeScript interfaces for content models
│ ├── components/ # SGDS web component utilities and wrappers
│ ├── services/ # API services and data transformation
│ ├── types/ # Shared TypeScript types and type guards
│ └── index.ts # Main library exports
├── tests/ # Test files
├── .gitignore
├── package.json
├── tsconfig.json # TypeScript configuration
└── README.md
- Node.js 16+
- npm or yarn
npm install @your-org/cms-content-model
# or
yarn add @your-org/cms-content-model- Only use components from
@govtechsg/sgds-web-component - Create utility functions to work with SGDS web components
- Provide TypeScript types for web component properties and events
- Document component usage with JSDoc and examples
- No framework-specific code - keep it vanilla JavaScript/TypeScript
- Component Creation Guide - Learn how to create new renderer components
Detailed documentation for the project can be found in the docs/ directory.
- Define clear interfaces for each content type
- Use TypeScript's type system to enforce data structure
- Document required and optional fields
- Include validation where necessary
- Follow TypeScript best practices
- Use ESLint and Prettier for consistent formatting
- Write JSDoc for all public APIs
import { ContentRenderer } from '@your-org/cms-content-model';
// Example of rendering content from Optical CMS API
const content = await fetchContentFromOptical('content-id');
const element = document.getElementById('content-container');
if (element) {
const renderer = new ContentRenderer();
renderer.render(content, element);
}Run the test suite:
npm test
# or
yarn testWe use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request