forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeapisets.js
45 lines (35 loc) · 1.01 KB
/
makeapisets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var path = require('path');
var stream = require('stream');
var util = require('util');
var StringDecoder = require('string_decoder').StringDecoder;
var File = require('vinyl');
var jsdoc = require('./jsdocparser.js');
var MakeApiSets = function() {
if (!(this instanceof MakeApiSets)) return new MakeApiSets();
stream.Transform.call(this, {
objectMode: true // needed for Vinyl
});
this._sets = {};
};
util.inherits(MakeApiSets, stream.Transform);
MakeApiSets.prototype._transform = function(file, encoding, callback) {
var decoder = new StringDecoder('utf8');
var obj = JSON.parse(decoder.write(file.contents));
var set = this._sets[obj.setName];
if (!set) {
set = this._sets[obj.setName] = [];
}
delete obj.setName;
set.push(obj);
callback();
};
MakeApiSets.prototype._flush = function(callback) {
var file = new File({
path: 'apisets.json',
contents: new Buffer(JSON.stringify(this._sets))
});
this.push(file);
callback();
};
module.exports = MakeApiSets;