This was a very straightforward workaround I used in a project to get things done while the assemble team is working on some serious converter gulp-convert.
Created
April 7, 2014 23:42
-
-
Save rayfranco/10074082 to your computer and use it in GitHub Desktop.
Convert YML to JSON with gulp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Minimal requirements | |
var map = require('map-stream'); | |
var yaml = require('js-yaml'); | |
var gulp = require('gulp'); | |
// Create JS files from YML files | |
gulp.task('data', function(){ | |
gulp.src('src/data/*.yml') | |
.pipe(map(function(file,cb){ | |
if (file.isNull()) return cb(null, file); // pass along | |
if (file.isStream()) return cb(new Error("Streaming not supported")); | |
var json; | |
try { | |
json = yaml.load(String(file.contents.toString('utf8'))); | |
} catch(e) { | |
console.log(e); | |
console.log(json); | |
} | |
file.path = gutil.replaceExtension(file.path, '.json'); | |
file.contents = new Buffer(JSON.stringify(json)); | |
cb(null,file); | |
})) | |
.pipe(gulp.dest('build/data')); | |
}); |
awesome, it saved my day.... thanks
Looks like a plugin just got released by @crissdev
https://github.com/CrissDev/gulp-yaml
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked! I just had to add
var gutil = require("gulp-util");
.