XMD Init Command and Data Import Features
XMD Init Command and Data Import Features
Overview
Implementing two major features:
xmd initcommand with .xmd/xmd.yaml configuration- JSON/YAML import functionality with unified data handling
Feature 1: xmd init Command
Purpose
- Create .xmd directory and xmd.yaml configuration file
- Allow multiple entry points and targets
- Support
xmd,xmd process, andxmd watchwithout arguments
Configuration Structure (xmd.yaml)
version: "1.0"
projects:
default:
entry:
- "src/main.md"
- "src/components/*.md"
output: "dist/index.md"
watch: true
docs:
entry: "docs/**/*.md"
output: "build/docs.md"
api:
entry: "api/spec.md"
output: "public/api.html"
process:
- import: "api/config.yaml"
- import: "api/endpoints.json"
Implementation Steps
- Add
initcommand to CLI - Create .xmd directory structure
- Generate default xmd.yaml
- Modify existing commands to read configuration
- Support project selection
Feature 2: JSON/YAML Import
Purpose
- Import JSON and YAML files seamlessly
- Provide unified data structure for both formats
- Add built-in functions for data manipulation
Unified Data Structure
- Use XMDโs variable system as the unified format
- JSON objects โ XMD objects (store)
- JSON arrays โ XMD arrays
- YAML maps โ XMD objects
- YAML sequences โ XMD arrays
Built-in Functions
# File I/O
write "./output.md" "content"
append "./log.md" "new line"
exists "./file.md"
# Data serialization
to_json data
from_json string
to_yaml data
from_yaml string
# Data manipulation
keys object
values object
merge obj1 obj2
filter array condition
map array transform
Implementation Plan
Phase 1: xmd init command
- Update CLI to handle init command
- Create directory and file generators
- Add YAML parsing with libyaml
- Create configuration reader
Phase 2: Import functionality
- Add JSON parsing with json-c
- Create unified data converters
- Implement import directive enhancement
- Add file type detection
Phase 3: Built-in functions
- Implement file I/O functions
- Add serialization functions
- Create data manipulation functions
- Update documentation
Technical Considerations
- Use libyaml for YAML parsing
- Use json-c for JSON parsing
- Maintain backward compatibility
- Follow existing code structure
- One function per file rule
- Comprehensive testing