gulp-yaml-dirs
Create a JSON file from YAML file in a directory structure
Introduction
Suppose that you have multiple YAML file in a directory structure like so:
i18n
├── global.yml
└── schemas
├── address.yml
└── configuration.yml
Using this plugin will create the following JSON file:
{
// Content of global.yml as JSON
...
"schemas": {
// Content of address.yml as JSON
...
// Content of configuration.yml as JSON
...
}
}
Installation
Install this plugin as a NPM development dependency:
npm i -D gulp-yaml-dirs
Usage
A simple example for generating DRY translation from a directory of YAML files:
gulp = require 'gulp'gp = require 'gulp-load-plugins'del = require 'del'yamlDirs = require './tools/gulp-yaml-dirs' i18n = src: 'i18n/**/*.yml' temp: 'i18n.json' dest: 'app/i18n' gulptask 'i18n.clean'-> del i18ndest gulptask 'i18n.build'-> gulpsrc 'i18n'read: false # Avoid breaking stream on error and notify error pipe gpplumberNotifier # Concatenante YAML files and transform them into JSON pipe yamlDirs i18ntemp # Separate translations into one file per locale pipe gpi18nCompile '[locale].json'localePlaceholder: '[locale]' # Set the proper extension required by TAPi18n pipe gprename extname: '.i18n.json' pipe gulpdest i18ndest gulptask 'i18n.watch'-> gulpwatch i18nsrc'i18n.build' gulptask 'clean''i18n.clean'gulptask 'build''i18n.build'gulptask 'watch''i18n.watch'gulptask 'default''clean''build''watch'