简体   繁体   English

如何解析Gulp中的.json文件以传递给Firebase?

[英]How do I parse a .json file in Gulp to pass along to Firebase?

Alright so I have YAML files, that are being transformed into JSON files. 好的,所以我有YAML文件,这些文件已被转换为JSON文件。 That part is done. 这部分完成了。 But I need to read the JSON files into their appropriate json objects to send to a Firebase Database. 但是我需要将JSON文件读入其相应的json对象中,以发送到Firebase数据库。 Current gulpfile: 当前的gulpfile:

var gulp = require('gulp');
var yaml = require('gulp-yaml');
var replace = require('gulp-replace');
var firebase = require('firebase');
var paths = {
    yaml: ['~/devel/Git/core-rules/feats/*.yml',
        '~/devel/Git/core-rules/banes/*.yml',
        '~/devel/Git/core-rules/boons/*.yml']
};

require('firebase/auth');
require('firebase/database');


// compile rules from yaml to json and output to
gulp.task('yaml', function(){
  gulp.src(paths.yaml)
    .pipe(yaml({
        space: 2
    }))
    // replaces newlines from YAML "foo : |" linebreaks
    .pipe(replace('\\n', '<br />'))
    .pipe(gulp.dest('./app'))
});

It has no dependancy problems, but only reads 1 file (there should be 3) I need to get the JSON that was written (once there's a JSON file for each YAML file) into a JSON object. 它没有依赖性问题,但是只读取1个文件(应该为3个),我需要将写入的JSON(每个YAML文件都有一个JSON文件)写入JSON对象。 Once that's done, it'll be set/pushed to the firebase database. 完成后,将其设置/推送到firebase数据库。

Thanks to: @hapticdata and @Jon Surrell 感谢:@hapticdata和@Jon Surrell

var fs = require('fs');

var json = JSON.parse(fs.readFileSync('./data.json'));

Duplicate of Question 问题重复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM