An open API service indexing awesome lists of open source software.

https://github.com/fsegurai/manifest-generator

Manifest Generator is a tool to generate manifest files and search indexes based on a given documentation structure.
https://github.com/fsegurai/manifest-generator

cli docs documentation generator javascript javascript-library manifest markdown search-index typescript typescript-library

Last synced: about 2 months ago
JSON representation

Manifest Generator is a tool to generate manifest files and search indexes based on a given documentation structure.

Awesome Lists containing this project

README

          


Manifest Generator Logo



Build Main Status


Latest Release



GitHub contributors
Dependency status for repo

GitHub License



Stars
Forks

# @fsegurai/manifest-generator

**A library and CLI tool for generating documentation manifests and search indexes from Markdown files.**

A powerful and flexible documentation manifest generator that automatically creates
navigation structures and search indexes for your Markdown documentation.

### πŸ“‹ Table of Contents

- [πŸš€ Features](#-features)
- [πŸ“¦ Installation](#-installation)
- [πŸ–₯️ CLI Usage](#️-cli-usage)
- [Global Installation](#global-installation)
- [Using npx (Recommended)](#using-npx-recommended)
- [CLI Commands](#cli-commands)
- [Production Examples](#production-examples)
- [πŸ“š API Usage](#-api-usage)
- [ES Modules](#es-modules)
- [CommonJS](#commonjs)
- [API Reference](#api-reference)
- [πŸ“ Project Structure Detection](#-project-structure-detection)
- [πŸ“„ Output Files](#-output-files)
- [βš™οΈ Configuration](#️-configuration)
- [πŸ”§ Integration Examples](#-integration-examples)
- [πŸ“ Frontmatter Support](#-frontmatter-support)
- [🀝 Contributing](#-contributing)
- [πŸ“„ License](#-license)

---

## πŸš€ Features

- **Automatic Discovery**: Intelligently finds documentation projects in various folder structures
- **Flexible Input**: Supports both direct markdown files and docs subfolders
- **CLI & API**: Use via command line or programmatically in your code
- **Frontmatter Parsing**: Extracts metadata from YAML frontmatter
- **Search Index Generation**: Creates searchable indexes for your documentation
- **TypeScript Support**: Full TypeScript definitions included
- **Cross-Platform**: Works on Windows, macOS, and Linux
- **Multiple Output Formats**: Generates both navigation manifests and search indexes

## πŸ“¦ Installation

### Global Installation

```bash
npm install -g @fsegurai/manifest-generator
```

### Project Dependency

```bash
# As a dev dependency
npm install --save-dev @fsegurai/manifest-generator

# As a regular dependency
npm install @fsegurai/manifest-generator
```

## πŸ–₯️ CLI Usage

### Using npx (Recommended)

No installation requiredβ€”run directly:

```bash
# Process all projects in current directory
npx @fsegurai/manifest-generator --all

# Process specific project
npx @fsegurai/manifest-generator --project my-docs

# Get help
npx @fsegurai/manifest-generator --help
```

### Global Installation

If installed globally, use the `manifest-generator` command:

```bash
manifest-generator --all
manifest-generator --project my-docs
```

### CLI Commands

#### Basic Usage

```bash
# Process all projects automatically
npx @fsegurai/manifest-generator --all

# Process a specific project by name
npx @fsegurai/manifest-generator --project sample-project

# Process a specific documentation path
npx @fsegurai/manifest-generator --route ./docs

# Discover projects without processing
npx @fsegurai/manifest-generator --discover
```

#### Advanced Options

```bash
# Specify custom docs root directory
npx @fsegurai/manifest-generator --all --docs-root ./my-projects

# Custom output directory
npx @fsegurai/manifest-generator --route ./docs --output ./dist

# Custom docs subfolder name (default: 'docs')
npx @fsegurai/manifest-generator --all --docs-subfolder documentation

# Process positional path argument
npx @fsegurai/manifest-generator ./path/to/documentation
```

#### Help and Information

```bash
# Show help
npx @fsegurai/manifest-generator --help

# Show version
npx @fsegurai/manifest-generator --version
```

### Production Examples

#### CI/CD Pipeline (GitHub Actions)

```yaml
- name: Generate Documentation Manifests
run: npx @fsegurai/manifest-generator --all --docs-root ./projects
```

#### Monorepo Processing

```bash
# Process all packages in a monorepo
npx @fsegurai/manifest-generator --all --docs-root ./packages

# Process specific package
npx @fsegurai/manifest-generator --project my-package --docs-root ./packages
```

#### Build Pipeline Integration

```bash
# Generate manifests for built documentation
npx @fsegurai/manifest-generator --route ./dist/docs --output ./public
```

#### Package.json Scripts

```json
{
"scripts": {
"build:docs": "manifest-generator --all",
"docs:manifest": "manifest-generator --route ./documentation",
"docs:discover": "manifest-generator --discover"
}
}
```

## πŸ“š API Usage

### ES Modules

```javascript
import {
generateManifest,
generateDocsManifests,
generateManifestsWithDiscovery,
discoverProjects
} from '@fsegurai/manifest-generator';

// Generate manifest for a single project
const result = generateManifest('./docs');
console.log('Generated:', result.manifest);
console.log('Search Index:', result.searchIndex);

// Process all projects with auto-discovery
const results = generateManifestsWithDiscovery('./projects', {
autoDetect: true,
docsSubfolder: 'docs'
});

// Discover projects without processing
const projects = discoverProjects('./projects');
console.log('Found projects:', projects);
```

### CommonJS

```javascript
const {
generateManifest,
generateManifestsWithDiscovery
} = require('@fsegurai/manifest-generator');

// Process specific project
generateManifestsWithDiscovery('./projects', {
project: 'my-app',
outputDir: './dist'
});
```

### API Reference

#### Core Functions

##### `generateManifest(projectPath: string): ManifestResult`

Generates a manifest for a single documentation project.

```javascript
const result = generateManifest('./my-docs');
// Returns: { manifest: NavigationItem[], searchIndex: SearchEntry[] }
```

##### `generateDocsManifests(docsRoot: string): void`

Processes all subdirectories as separate projects.

```javascript
generateDocsManifests('./projects');
// Generates manifest.json and search-index.json in each subdirectory
```

##### `generateManifestsWithDiscovery(rootDir: string, options?: GenerationOptions): ProcessingResult[]`

Advanced function with flexible options and auto-discovery.

```javascript
const results = generateManifestsWithDiscovery('./projects', {
project: 'specific-project', // Process specific project
route: './custom/path', // Process specific path
outputDir: './output', // Custom output directory
docsSubfolder: 'documentation', // Custom docs folder name
autoDetect: true // Auto-discover projects
});
```

##### `discoverProjects(rootDir: string, options?: DiscoveryOptions): DiscoveredProject[]`

Discovers documentation projects without processing them.

```javascript
const projects = discoverProjects('./projects', {
docsSubfolder: 'docs', // Folder name to look for
pattern: null // Future: regex pattern support
});
```

#### Utility Functions

##### `formatTitle(name: string): string`

Converts filenames to readable titles.

```javascript
formatTitle('getting-started-guide.md'); // "Getting Started Guide"
```

##### `parseFrontmatter(content: string): Record`

Extracts YAML frontmatter from Markdown content.

```javascript
const frontmatter = parseFrontmatter(`---
label: My Document
tags: ["guide", "tutorial"]
---
# Content here`);
// Returns: { label: "My Document", tags: ["guide", "tutorial"] }
```

#### TypeScript Interfaces

```typescript
interface NavigationItem {
label: string;
path?: string;
tags?: string[];
children?: NavigationItem[];
}

interface SearchEntry {
label: string;
path: string;
tags?: string[];
}

interface ManifestResult {
manifest: NavigationItem[];
searchIndex: SearchEntry[];
}

interface DiscoveredProject {
name: string;
projectPath: string;
docsPath: string;
type: 'subfolder' | 'direct';
}

interface GenerationOptions {
project?: string | null;
route?: string | null;
outputDir?: string | null;
docsSubfolder?: string;
autoDetect?: boolean;
}
```

## πŸ“ Project Structure Detection

The generator automatically detects different documentation structures:

### Structure 1: Docs Subfolders

```
projects/
β”œβ”€β”€ project-a/
β”‚ β”œβ”€β”€ docs/ ← Documentation here
β”‚ β”‚ β”œβ”€β”€ README.md
β”‚ β”‚ β”œβ”€β”€ guide.md
β”‚ β”‚ └── api/
β”‚ β”œβ”€β”€ manifest.json ← Generated here
β”‚ └── search-index.json
└── project-b/
└── docs/
└── *.md files
```

### Structure 2: Direct Markdown Files

```
projects/
β”œβ”€β”€ project-a/
β”‚ β”œβ”€β”€ README.md ← Documentation here
β”‚ β”œβ”€β”€ guide.md
β”‚ β”œβ”€β”€ manifest.json ← Generated here
β”‚ └── search-index.json
└── project-b/
└── *.md files
```

### Structure 3: Custom Documentation Folders

```
projects/
β”œβ”€β”€ project-a/
β”‚ β”œβ”€β”€ documentation/ ← Custom folder name
β”‚ β”‚ └── *.md files
β”‚ β”œβ”€β”€ manifest.json
β”‚ └── search-index.json
```

## πŸ“„ Output Files

### manifest.json

Contains the hierarchical navigation structure:

```json
[
{
"title": "Getting Started",
"path": "getting-started",
"tags": [
"tutorial",
"beginner"
]
},
{
"title": "API Reference",
"children": [
{
"title": "Authentication",
"path": "api/auth",
"tags": [
"api",
"security"
]
}
]
}
]
```

### search-index.json

Contains flattened search data:

```json
[
{
"title": "Getting Started",
"path": "getting-started",
"tags": [
"tutorial",
"beginner"
]
},
{
"title": "Authentication",
"path": "api/auth",
"tags": [
"api",
"security"
]
}
]
```

## βš™οΈ Configuration

### Frontmatter Options

Control document processing with frontmatter:

```markdown
---
label: "Custom Title" # Override generated title
tags: ["api", "reference"] # Add searchable tags
draft: true # Exclude from manifest
hidden: true # Hide from navigation
---

# Your content here
```

### CLI Options Reference

| Option | Short | Description | Default |
|---------------------------|-------|----------------------------------|-------------------|
| `--all` | `-a` | Process all projects | `false` |
| `--project ` | `-p` | Process specific project | `null` |
| `--route ` | `-r` | Process specific path | `null` |
| `--docs-root ` | `-d` | Root directory for docs | Current directory |
| `--output ` | `-o` | Output directory | Project directory |
| `--docs-subfolder ` | `-s` | Docs folder name | `'docs'` |
| `--discover` | | List projects without processing | `false` |
| `--help` | `-h` | Show help | |
| `--version` | `-v` | Show version | |

## πŸ”§ Integration Examples

### Webpack Integration

```javascript
// webpack.config.js
const {generateManifest} = require('@fsegurai/manifest-generator');

module.exports = {
// ...existing config
plugins: [
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap('ManifestGenerator', () => {
generateManifest('./src/docs');
});
}
}
]
};
```

### Gulp Integration

```javascript
// gulpfile.js
const {generateManifestsWithDiscovery} = require('@fsegurai/manifest-generator');

gulp.task('docs:manifest', () => {
return generateManifestsWithDiscovery('./src/projects', {
autoDetect: true,
outputDir: './dist'
});
});
```

### Node.js Script

```javascript
#!/usr/bin/env node
import {generateManifestsWithDiscovery} from '@fsegurai/manifest-generator';

async function buildDocs() {
try {
const results = generateManifestsWithDiscovery(process.cwd(), {
autoDetect: true
});

console.log(`βœ… Processed ${results.length} projects`);
} catch (error) {
console.error('❌ Error:', error.message);
process.exit(1);
}
}

buildDocs();
```

## πŸ“ Frontmatter Support

Supported frontmatter fields:

```yaml
---
label: "Document Title" # Custom title (overrides filename)
tags: [ "api", "guide" ] # Searchable tags
draft: true # Exclude from processing
hidden: true # Hide from navigation
weight: 10 # Future: custom ordering
description: "Brief summary" # Future: meta description
---
```

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to
discuss what you would like to change.

For more information, check out the [Contributing Guide](CONTRIBUTING.md).

## 🧼 License

Licensed under [MIT](https://opensource.org/licenses/MIT).