yaml-splitter
is a CLI tool to split and manage YAML files, especially OpenAPI Specification (OAS) YAML files. It helps developers break large YAML files into smaller, manageable parts and merge them back when needed.
- Split OAS YAML files into individual files based on endpoints (paths).
- List available YAML files in a directory.
- Interactive mode for user-friendly file selection.
- Merge split YAML files back into a single file.
To install yaml-splitter
globally, run:
npm install -g yaml-splitter
After installation, the yaml-splitter command becomes available globally. Here are the available commands:
List all .yaml or .yml files in a specified directory:
yaml-splitter list --dir <directory>
Example:
yaml-splitter list --dir ./my_yaml_files
Split a YAML file into smaller files based on endpoints (paths):
yaml-splitter split --file <path-to-yaml> --output-dir <output-directory>
Example:
yaml-splitter split --file ./input_folder/sample.yaml --output-dir ./output_folder
Options:
--file
: Path to the input YAML file.--output-dir
: Directory to save the split files (default: ./split_endpoints).
Interactively select a YAML file to split:
yaml-splitter interactive --dir <directory>
Example:
yaml-splitter interactive --dir ./input_folder
The command will:
- List all YAML files in the specified directory.
- Prompt you to select a file and specify an output directory.
Merge multiple YAML files from a directory into one:
yaml-splitter merge --input-dir <input-directory> --output <output-file>
Example:
yaml-splitter merge --input-dir ./output_folder --output ./combined.yaml
Options:
--input-dir
: Directory containing split YAML files.
--output
: Path to save the combined YAML file.
Suppose you have an OpenAPI YAML file (api.yaml) in the ./input_folder
, and you want to split it into individual files based on endpoints:
yaml-splitter split --file ./input_folder/api.yaml --output-dir ./split_output
After running the command, you’ll find split YAML files in the ./split_output folder
.
Run the interactive command to select and split a file:
yaml-splitter interactive --dir ./input_folder
The tool will:
- List all YAML files in
./input_folder
. - Allow you to choose a file.
- Prompt for an output directory (or use the default ./split_endpoints).
To combine all split YAML files from ./split_output into a single file:
yaml-splitter merge --input-dir ./split_output --output ./merged_api.yaml
The result is a merged_api.yaml
file.
- Node.js v14 or higher.
- YAML files must follow a valid structure (e.g., OpenAPI Specification).
Contributions are welcome! If you encounter any issues or have feature requests, feel free to open an issue or submit a pull request on GitHub.