You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
2 years ago
|
'use strict';
|
||
|
|
||
|
var clone = require('clone');
|
||
|
var objectAssign = require('object-assign');
|
||
|
var Transform = require('readable-stream/transform');
|
||
|
var common = require('./common');
|
||
|
var Parser = require('./parser');
|
||
|
|
||
|
module.exports = function (options, userConfig) {
|
||
|
var tasksPromise = common.parseTasks(options);
|
||
|
|
||
|
var config = {
|
||
|
keepUnassigned: false,
|
||
|
keepBlockTags: false,
|
||
|
resolvePaths: false
|
||
|
};
|
||
|
|
||
|
if (typeof userConfig === 'boolean') {
|
||
|
config.keepUnassigned = userConfig;
|
||
|
} else if (typeof userConfig === 'object') {
|
||
|
objectAssign(config, userConfig);
|
||
|
}
|
||
|
|
||
|
return new Transform({
|
||
|
objectMode: true,
|
||
|
transform: function (file, enc, callback) {
|
||
|
tasksPromise
|
||
|
.then(function (tasks) {
|
||
|
|
||
|
var parser = new Parser(clone(tasks), config, file);
|
||
|
|
||
|
if (file.isBuffer()) {
|
||
|
parser.write(file.contents);
|
||
|
parser.end();
|
||
|
|
||
|
var contents = new Buffer(0);
|
||
|
parser.on('data', function (data) {
|
||
|
contents = Buffer.concat([contents, data]);
|
||
|
});
|
||
|
parser.once('end', function () {
|
||
|
file.contents = contents;
|
||
|
callback(null, file);
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (file.isStream()) {
|
||
|
file.contents = file.contents.pipe(parser);
|
||
|
}
|
||
|
|
||
|
callback(null, file);
|
||
|
})
|
||
|
.catch(callback);
|
||
|
}
|
||
|
});
|
||
|
};
|