I'm trying to extract data from a set of files that I get with gulp.src(content/*.md)
.
This should list all Markdown-files inside content
. Then I wanted to iterate over an array of file-paths, process each file, return an object that stores the extracted information and save this to a .json-file.
var gulp = require("gulp"),
jsonfile = require('jsonfile'),
gulp.task("myTask", function(){
// Contains JS objects that contain extracted information
// from the files; see processFile()
var extractions = [];
// Read from the stream???
gulp.src("content/*.md");
// An array of all filepaths found by gulp.src()
var files = [];
for (i = 0; i < files.length; i++) {
var information = processFile(files[i])
// Append information-object to extractions array
extractions.push(information);
}
// Save extractions as .json-file
jsonfile.writeFile("information.json", extractions, function (err) {
console.error(err);
});
});
function processFile(content) {
// Process each file's content one by one and return
//a JS-object with the extracted information.
}
In one approach I tried to use console.log( gulp.src("content/*.md").content.toString() )
to output the data from the stream that is returned by gulp.src()
, but undefined
will be outputted.