1 | /*! |
||
2 | * @license gulp-yaml-include (c) 2015 aaharu |
||
3 | * Copyrights licensed under the 2-clause BSD License. See the accompanying LICENSE file for terms. |
||
4 | */ |
||
5 | |||
6 | "use strict"; |
||
7 | |||
8 | var through = require("through2"), |
||
9 | yaml = require("js-yaml"), |
||
10 | yamlinc = require("yaml-include"), |
||
11 | es = require("event-stream"), |
||
12 | PassThrough = require("stream").PassThrough; |
||
13 | |||
14 | module.exports = function () { |
||
15 | return through.obj(function (file, enc, cb) { |
||
16 | if (file.isNull()) { |
||
17 | // return empty file |
||
18 | return cb(null, file); |
||
19 | } |
||
20 | yamlinc.setBaseFile(file.path); |
||
21 | 4 | if (file.isBuffer()) { |
|
22 | var yml = yaml.load(file.contents.toString(enc), { |
||
23 | 4 | schema: yamlinc.YAML_INCLUDE_SCHEMA, |
|
24 | filename: file.path |
||
25 | }); |
||
26 | file.contents = Buffer.from(yaml.dump(yml), enc); |
||
0 ignored issues
–
show
|
|||
27 | cb(null, file); |
||
0 ignored issues
–
show
|
|||
28 | } else if (file.isStream()) { |
||
29 | file.contents.setEncoding(enc); |
||
30 | file.contents.pipe(es.wait(function(err, data) { |
||
31 | var ymlobj = yaml.load(data.toString(), { |
||
32 | schema: yamlinc.YAML_INCLUDE_SCHEMA, |
||
33 | filename: file.path |
||
34 | }); |
||
35 | var stream = new PassThrough(); |
||
36 | stream.write(yaml.dump(ymlobj)); |
||
37 | stream.end(); |
||
38 | file.contents = file.contents.pipe(stream); |
||
39 | cb(null, file); |
||
40 | })); |
||
0 ignored issues
–
show
|
|||
41 | } else { |
||
42 | cb(null, file); |
||
0 ignored issues
–
show
|
|||
43 | } |
||
44 | }); |
||
45 | }; |
||
46 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.