YAML File Merger CLI

1.1.2 · maintenance · verified Wed Apr 22

merge-yaml-cli is a command-line utility for concatenating and merging multiple YAML files into a single output file. It leverages `glob` patterns for flexible input file selection, making it suitable for configuration management in projects with fragmented YAML setups. The package also exposes a Node.js API, allowing programmatic integration into larger JavaScript applications. The current stable version is 1.1.2. Based on its last publish date 8 years ago and limited recent activity, the project appears to be in a maintenance state with infrequent updates. While it provides a core utility, users seeking more advanced merge strategies (e.g., array concatenation vs. deep merging, or specific key-based merging) might need to explore alternatives like `yq` or `yaml-merge` which offer more nuanced control over the merge process.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global installation and usage of the `merge-yaml-cli` command-line utility to merge multiple YAML files using glob patterns and output the result.

#!/usr/bin/env node

// Create dummy YAML files for demonstration
const fs = require('fs');
fs.writeFileSync('config/base.yml', 'name: MyApp\nversion: 1.0.0\nenvironment: development');
fs.writeFileSync('config/overrides/prod.yml', 'environment: production\nscale: large\nfeatures:\n  - analytics\n  - monitoring');
fs.writeFileSync('config/overrides/test.yml', 'environment: testing\nscale: medium\nfeatures:\n  - logging');

console.log('Dummy YAML files created.');
console.log('Running merge-yaml-cli...');

// Simulate CLI execution (assuming global install or PATH setup)
const { execSync } = require('child_process');
try {
  execSync('npm i -g merge-yaml-cli', { stdio: 'inherit' });
  const cliCommand = 'merge-yaml -i config/base.yml config/overrides/*.yml -o merged.yml';
  console.log(`Executing: ${cliCommand}`);
  execSync(cliCommand, { stdio: 'inherit' });
  console.log('\nMerged YAML content:');
  console.log(fs.readFileSync('merged.yml', 'utf8'));

  // Clean up dummy files
  fs.unlinkSync('config/base.yml');
  fs.unlinkSync('config/overrides/prod.yml');
  fs.unlinkSync('config/overrides/test.yml');
  fs.unlinkSync('merged.yml');
  fs.rmdirSync('config/overrides');
  fs.rmdirSync('config');
  console.log('\nCleanup complete.');
} catch (error) {
  console.error(`Error during quickstart: ${error.message}`);
  process.exit(1);
}

view raw JSON →