Git Product home page Git Product logo

gulp-yaml's Introduction

gulp-yaml

JavaScript Style Guide npm version Build Status Build status Dependency Status

A Gulp plugin to convert YAML to JSON using js-yaml.

Install

npm install gulp-yaml --save-dev

Usage

const yaml = require('gulp-yaml');

gulp.src('./src/*.yml')
  .pipe(yaml({ schema: 'DEFAULT_SAFE_SCHEMA' }))
  .pipe(gulp.dest('./dist/'))

gulp.src('./src/*.yml')
  .pipe(yaml({ space: 2 }))
  .pipe(gulp.dest('./dist/'))

gulp.src('./src/*.yml')
  .pipe(yaml({ safe: true }))
  .pipe(gulp.dest('./dist/'))

API

yaml([options])

options.safe

Type: Boolean

Default: true

Enable or disable support for regexps, functions and undefined.

This flag should always be enabled when working with untrusted data.

When this flag is enabled then safeLoad method is used, otherwise load.

options.space

Type: Number or String

Default: null

Control spacing in the resulting output. It has the same usage as for JSON.stringify

options.replacer

Type: Function or Array

Default: null

Further transform the resulting output. It has the same usage as for JSON.stringify

options.schema

Type: String

Default: DEFAULT_SAFE_SCHEMA or DEFAULT_FULL_SCHEMA

Specifies what schema to use. Valid values are the same that js-yaml supports, except they are received as strings (lowercase or uppercase). See the example in the Usage section of this README. The default schema is chosen using the safe option.

options.filename

Type: String

Default: the path of the file processed

String to be used as a file path in error/warning messages.

options.ext

Type: String

Default: .json

File extension of the generated file.

options.json

Type: Boolean

Default: false

Compatibility with JSON.parse behaviour. If true, then duplicate keys in a mapping will override values rather than throwing an error.

options.onWarning

Type: Function

Default: null

Function to call on warning messages. Loader will throw on warnings if this function is not provided.

License

MIT © Cristian Trifan

gulp-yaml's People

Contributors

crissdev avatar ehmicky avatar seahindeniz avatar thedancingcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gulp-yaml's Issues

"Error: Schema [object Object] is not valid" after upgrade to 1.0.0

I get the error "Error: Schema [object Object] is not valid" after the upgrade to 1.0.0

If it is of any help the [object Object] in the error message looks like this:

{ include: 
   [ { include: [Object],
       implicit: [],
       explicit: [],
       compiledImplicit: [Object],
       compiledExplicit: [Object],
       compiledTypeMap: [Object] } ],
  implicit: 
   [ { tag: 'tag:yaml.org,2002:timestamp',
       kind: 'scalar',
       resolve: [Function: resolveYamlTimestamp],
       construct: [Function: constructYamlTimestamp],
       instanceOf: [Function: Date],
       predicate: null,
       represent: [Function: representYamlTimestamp],
       defaultStyle: null,
       styleAliases: {} },
     { tag: 'tag:yaml.org,2002:merge',
       kind: 'scalar',
       resolve: [Function: resolveYamlMerge],
       construct: [Function],
       instanceOf: null,
       predicate: null,
       represent: null,
       defaultStyle: null,
       styleAliases: {} } ],
  explicit: 
   [ { tag: 'tag:yaml.org,2002:binary',
       kind: 'scalar',
...

plumber is invalid when error occurred

if i add a comma to the end of a line, this plugin will throw a YAMLException which will break gulp watch.
i tried to add gulp-plumber to prevent it, but it doesn't effect
how could i solve it

image
image

add a parseContents function

Hi,
Coin we add a parseContents function?

This function will be optional and it will manipulate the file contents.

The need of this manipulation of the content of an yaml file is for instance if you use https://www.npmjs.com/package/yaml-include-loader

I have cloned your repository and I have done this change. Then I did npm link to that one.
It will be very handy for me if you include this option otherwise I can't use it with yaml-include-loader.

Example:

        function parseImports(content, filePath, options) {

            var oldLines = content.toString('utf8').split('\n');
            var newLines = [];
            var importKeyword = 'import';
            var importRawKeyword = 'import-raw';
            var regex = new RegExp("^(\\s+|)(\\w+):\\s(!(" + importKeyword + "|" + importRawKeyword + ")\\s+?(.*)(\\.ya?ml|\\.json)?)?\\s*$");
            var space = '';

            for (var i = 0; i < oldLines.length; i++) {
                var line = oldLines[i];
                var match = line.match(regex);
                if (!match) {
                    newLines.push(space + line);
                } else {
                    var fileName = match[3].substr(match[3].lastIndexOf('/')+1);
                    var fileNameArray = fileName.split('.');
                    newLines.push(line.replace(match[3], '"[!' + fileNameArray[0] + '!]"'));
                }
            }

            return new Buffer(newLines.join('\n'));
        }

        gulp
            .src([
                './configuration/*.yml'
            ])
            .pipe(yaml({
                parseContents: parseImports
            }))

Implementation:

             ' is empty. YAML loader cannot load empty content'));
         return callback();
       }
+      if (options.parseContents) {
+        file.contents = options.parseContents(file.contents, file.path, options);
+      }
       try {
         file.contents = yaml2json(file.contents, options);
         file.path = gutil.replaceExtension(file.path, '.json');

JSON to YAML

Hello, since js-yaml supports serializing JSON into YAML, can this plugin support it as well?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.