Skip to content

Commit c21648a

Browse files
committed
Merge branch 'jsdoc-api'
2 parents 62ba544 + c0a3340 commit c21648a

58 files changed

Lines changed: 317 additions & 3005 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
3-
- 'node'
4-
- '4.2'
3+
- '5'
4+
- '4'
55
- '0.12'
66
- '0.10'
77
- 'iojs'

bin/cli.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,17 @@ try {
1717
}
1818

1919
if (options.help) {
20-
console.log(usage)
20+
console.error(usage)
2121
process.exit(0)
2222
}
2323

24-
var parseStream
25-
if (options.src && options.src.length) {
26-
parseStream = parse(options)
27-
parseStream
28-
.on('error', function (err) {
29-
stop(err.stack, 1)
30-
})
31-
.pipe(process.stdout)
32-
} else {
33-
parseStream = parse(options)
34-
parseStream.on('error', function (err) {
24+
var parseStream = parse(options)
25+
.on('error', function (err) {
3526
stop(err.stack, 1)
3627
})
37-
process.stdin.pipe(parseStream).pipe(process.stdout)
38-
}
28+
parseStream.pipe(process.stdout)
29+
30+
if (!options.src) process.stdin.pipe(parseStream)
3931

4032
function stop (msg, code) {
4133
console.error(ansi.format(msg, 'red'))

es5/jsdoc-parse.js

Lines changed: 73 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,63 @@
11
'use strict';
22

3+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
4+
35
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
46

5-
var cp = require('child_process');
7+
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
8+
69
var path = require('path');
7-
var util = require('util');
810
var a = require('array-tools');
9-
var o = require('object-tools');
10-
var fs = require('fs');
1111
var fileSet = require('file-set');
1212
var Transform = require('stream').Transform;
1313
var cliOptions = require('./cli-options');
14-
var getTempPath = require('temp-path');
15-
var walkBack = require('walk-back');
16-
17-
function tempPath() {
18-
return getTempPath() + 'jsdoc-parse.js';
19-
}
14+
var jsdoc = require('jsdoc-api');
15+
var transform = require('./transform');
16+
var collectJson = require('collect-json');
17+
var assert = require('assert');
18+
var connect = require('stream-connect');
2019

2120
module.exports = jsdocParse;
2221
jsdocParse.cliOptions = cliOptions.definitions;
2322

24-
var ParseOptions = function ParseOptions() {
25-
_classCallCheck(this, ParseOptions);
26-
27-
this.src = null;
28-
29-
this.private = false;
30-
31-
this.stats;
32-
33-
this.html = false;
34-
35-
this.conf = null;
36-
37-
this['sort-by'] = ['scope', 'category', 'kind', 'order'];
38-
};
39-
4023
function jsdocParse(options) {
41-
options = o.extend(new ParseOptions(), options);
42-
var src = options.src;
43-
44-
if (src) {
45-
var inputFiles = fileSet(src);
46-
src = inputFiles.files;
47-
48-
var output = new OutputTransform(options);
49-
50-
if (!src.length) {
51-
var msg = util.format('[jsdoc-parse] please specify valid input files. ');
52-
if (inputFiles.notExisting) {
53-
msg += 'These files do not exist: ' + inputFiles.notExisting.join(', ');
54-
}
55-
24+
options = new ParseOptions(options);
25+
try {
26+
options.validate();
27+
} catch (err) {
28+
var _ret = (function () {
29+
var output = new Transform();
5630
process.nextTick(function () {
57-
output.emit('error', new Error(msg));
58-
});
59-
} else {
60-
getJsdocOutput(src, options, function (err, data) {
61-
if (err) {
62-
output.emit('error', err);
63-
} else {
64-
output.end(data);
65-
}
66-
});
67-
}
68-
return output;
69-
} else {
70-
var inputStream = new Transform();
71-
var inputFilePath = tempPath();
72-
73-
var buf = new Buffer(0);
74-
inputStream._transform = function (chunk, enc, done) {
75-
if (chunk) buf = Buffer.concat([buf, chunk]);
76-
done();
77-
};
78-
inputStream._flush = function (done) {
79-
var self = this;
80-
fs.writeFileSync(inputFilePath, buf);
81-
getJsdocOutput([inputFilePath], options, function (err, data) {
82-
if (err) {
83-
done(err);
84-
} else {
85-
try {
86-
data = applyOptions(data, options);
87-
self.push(data);
88-
self.push(null);
89-
done();
90-
} catch (err) {
91-
done(err);
92-
}
93-
}
94-
fs.unlinkSync(inputFilePath);
31+
output.emit('error', err);
9532
});
96-
};
97-
return inputStream;
33+
return {
34+
v: output
35+
};
36+
})();
37+
38+
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
9839
}
99-
}
10040

101-
function OutputTransform(options) {
102-
Transform.call(this);
103-
this.json = new Buffer(0);
104-
this._transform = function (chunk, enc, done) {
105-
if (chunk) this.json = Buffer.concat([this.json, chunk]);
106-
done();
107-
};
108-
this._flush = function () {
109-
try {
110-
this.json = applyOptions(this.json, options);
111-
} catch (err) {
112-
err.message += ' [Problem parsing the JSON data output by jsdoc, input data: ' + this.json.toString().substr(0, 100) + ']';
113-
return this.emit('error', err);
114-
}
115-
this.push(this.json);
116-
this.push(null);
117-
};
118-
}
119-
util.inherits(OutputTransform, Transform);
41+
var jsdocOptions = {};
42+
if (options.html) jsdocOptions.configure = path.resolve(__dirname, 'html-conf.json');
43+
jsdocOptions.files = options.files;
12044

121-
function getJsdocOutput(src, options, done) {
122-
var jsdocTemplatePath = __dirname;
123-
var jsdocPath = walkBack(path.join(__dirname, '..'), path.join('node_modules', 'jsdoc-75lb', 'jsdoc.js'));
45+
var explainStream = jsdoc.createExplainStream(jsdocOptions).once('error', emitError);
12446

125-
if (!fs.existsSync(jsdocPath)) {
126-
throw Error('jsdoc-parse: cannot find jsdoc: ' + jsdocPath);
127-
}
128-
var args = [jsdocPath, '--pedantic', '-t', jsdocTemplatePath];
129-
if (options.html) {
130-
args = args.concat(['-c', path.resolve(__dirname, 'default-conf.json')]);
131-
} else if (options.conf) {
132-
args = args.concat(['-c', path.resolve(options.conf)]);
47+
var transformedStream = transform().once('error', emitError);
48+
49+
var outputStream = collectJson(function (data) {
50+
return applyOptions(data, options);
51+
}).once('error', emitError);
52+
53+
function emitError(err) {
54+
outputStream.emit('error', err);
13355
}
134-
args = args.concat(src);
135-
136-
var outputFilePath = tempPath();
137-
var outputFile = fs.openSync(outputFilePath, 'w');
138-
var outputStderrPath = tempPath();
139-
var outputStderr = fs.openSync(outputStderrPath, 'w');
140-
var handle = cp.spawn('node', args, { stdio: [process.stdin, outputFile, outputStderr] });
141-
handle.on('error', done);
142-
handle.on('close', function (code) {
143-
var stderr = fs.readFileSync(outputStderrPath, 'utf8');
144-
var stdout = fs.readFileSync(outputFilePath, 'utf8');
145-
if (/no input files/.test(stdout)) code = 1;
146-
147-
if (code) {
148-
fs.unlinkSync(outputFilePath);
149-
fs.unlinkSync(outputStderrPath);
150-
done(new Error(stderr || stdout));
151-
} else {
152-
fs.unlinkSync(outputFilePath);
153-
fs.unlinkSync(outputStderrPath);
154-
done(null, stdout);
155-
}
156-
});
56+
57+
return connect(explainStream, connect(transformedStream, outputStream));
15758
}
15859

15960
function applyOptions(data, options) {
160-
data = JSON.parse(data.toString());
16161
if (options.stats) {
16262
return JSON.stringify(getStats(data), null, ' ') + '\n';
16363
} else {
@@ -198,4 +98,40 @@ function sort(array, sortBy) {
19898
} else {
19999
return a.sortBy(array, sortBy, order);
200100
}
201-
}
101+
}
102+
103+
var ParseOptions = (function () {
104+
function ParseOptions(options) {
105+
_classCallCheck(this, ParseOptions);
106+
107+
this.src = null;
108+
109+
this.private = false;
110+
111+
this.stats;
112+
113+
this.html = false;
114+
115+
this.conf = null;
116+
117+
this['sort-by'] = ['scope', 'category', 'kind', 'order'];
118+
119+
Object.assign(this, options);
120+
if (this.src) {
121+
this.fileSet = fileSet(this.src);
122+
this.files = this.fileSet.files;
123+
}
124+
}
125+
126+
_createClass(ParseOptions, [{
127+
key: 'validate',
128+
value: function validate() {
129+
if (this.src) {
130+
assert.ok(this.fileSet.files.length, 'Please specify valid input files.');
131+
assert.ok(!(this.fileSet.notExisting && this.fileSet.notExisting.length), 'These files do not exist: ' + this.fileSet.notExisting.join(', '));
132+
}
133+
}
134+
}]);
135+
136+
return ParseOptions;
137+
})();

es5/transform.js

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,66 @@
33
var o = require('object-tools');
44
var a = require('array-tools');
55
var testValue = require('test-value');
6+
var collectJson = require('collect-json');
67

7-
var data;
8-
exports.createConstructor = createConstructor;
9-
exports.insertConstructors = insertConstructors;
10-
exports.fixConstructorMemberLongnames = fixConstructorMemberLongnames;
11-
exports.setIsExportedFlag = setIsExportedFlag;
12-
exports.setCodename = setCodename;
13-
exports.setID = setID;
14-
exports.updateIDReferences = updateIDReferences;
15-
16-
exports.setData = function (d) {
17-
data = d;return this;
18-
};
19-
exports.getData = function () {
20-
return data;
21-
};
22-
exports.removeQuotes = removeQuotes;
23-
exports.wantedProperties = wantedProperties;
24-
exports.removeUnwanted = removeUnwanted;
25-
exports.cleanProperties = cleanProperties;
26-
exports.buildTodoList = buildTodoList;
27-
exports.extractTypicalName = extractTypicalName;
28-
exports.extractCategory = extractCategory;
29-
exports.extractChainable = extractChainable;
30-
exports.extractCustomTags = extractCustomTags;
31-
exports.setTypedefScope = setTypedefScope;
32-
exports.sortIdentifier = sortIdentifier;
33-
exports.renameThisProperty = renameThisProperty;
34-
exports.removeMemberofFromModule = removeMemberofFromModule;
35-
exports.update = update;
8+
module.exports = transform;
9+
10+
function transform() {
11+
return collectJson(function (data) {
12+
data = fixConstructorMemberLongnames(data);
13+
14+
var json = data.filter(function (i) {
15+
return !i.undocumented && !/package|file/.test(i.kind);
16+
});
17+
18+
json = json.map(setIsExportedFlag);
19+
json = json.map(setCodename);
20+
json = insertConstructors(json);
21+
22+
json = json.map(function (identifier) {
23+
identifier = setID(identifier);
24+
25+
identifier = removeQuotes(identifier);
26+
identifier = cleanProperties(identifier);
27+
identifier = buildTodoList(identifier);
28+
identifier = extractTypicalName(identifier);
29+
identifier = extractCategory(identifier);
30+
identifier = extractChainable(identifier);
31+
identifier = extractCustomTags(identifier);
32+
identifier = setTypedefScope(identifier);
33+
identifier = renameThisProperty(identifier);
34+
identifier = removeMemberofFromModule(identifier);
35+
return identifier;
36+
});
37+
38+
var exported = a.where(json, { isExported: true });
39+
var newIDs = a.pluck(exported, 'id');
40+
41+
newIDs.forEach(function (newID) {
42+
update(json, { isExported: undefined, '!kind': 'module' }, function (identifier) {
43+
return updateIDReferences(identifier, newID);
44+
});
45+
});
46+
47+
json = json.filter(function (identifier) {
48+
var parent = a.findWhere(json, { id: identifier.memberof });
49+
if (parent && parent.isEnum) {
50+
return false;
51+
} else {
52+
return true;
53+
}
54+
});
55+
56+
json = json.map(removeUnwanted);
57+
json = json.map(sortIdentifier);
58+
59+
json.forEach(function (identifier, index) {
60+
identifier.order = index;
61+
});
62+
63+
return JSON.stringify(json, null, ' ');
64+
});
65+
}
3666

3767
function setID(identifier) {
3868
if (identifier.longname) {

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var detect = require('feature-detect-es6')
22

3-
if (detect.all('class', 'arrowFunction', 'let', 'const', 'newArrayFeatures' )) {
3+
if (detect.all('class', 'arrowFunction', 'let', 'const', 'newArrayFeatures')) {
44
module.exports = require('./lib/jsdoc-parse')
55
} else {
6+
require('core-js/es6/object')
67
module.exports = require('./es5/jsdoc-parse')
78
}

0 commit comments

Comments
 (0)