diff --git a/lib/jsdoc-to-json-schema.js b/lib/jsdoc-to-json-schema.js index 33166ef..1398000 100755 --- a/lib/jsdoc-to-json-schema.js +++ b/lib/jsdoc-to-json-schema.js @@ -1,50 +1,36 @@ var string2stream = require('string-to-stream'); -var stream2string = require('stream-to-string'); var fs = require('fs-extra-promise'); -var jsDocParse = require('jsdoc-parse'); +var jsdoc2md = require('jsdoc-to-markdown'); module.exports = function(input, output) { input = input || process.stdin; // default stdin output = output || process.stdout; // default stdout - // get input as a stream - return getInputAsStream(input).then(function(inputStream) { + return jsdoc2md.getTemplateData({ files: input, 'no-cache': true }).then((comments) => { - var parser = jsDocParse(); + // build json schema from comments + var jsonSchema = buildJsonSchema(comments); - // send input into jsdoc-parser - inputStream.pipe(parser); + // if the output is a stream + if (output.write) { - // read jsdoc-parse output as json string - return stream2string(parser).then(function(comments) { - - // convert json string into JSON array of comments - var jsonComments = JSON.parse(comments); - - // build json schema from comments - var jsonSchema = buildJsonSchema(jsonComments); - - // if the output is a stream - if (output.write) { - - // send result to output stream - string2stream(JSON.stringify(jsonSchema)).pipe(output); - } - else { + // send result to output stream + string2stream(JSON.stringify(jsonSchema)).pipe(output); + } + else { - // otherwise, write output to disk - fs.writeJsonAsync(output, jsonSchema, { spaces: 4 }).then(function(err) { - if (err) { - console.error(err); - } - }); - } + // otherwise, write output to disk + fs.writeJsonAsync(output, jsonSchema, { spaces: 4 }).then(function(err) { + if (err) { + console.error(err); + } + }); + } - // if no output object, return promise with JSON object - return Promise.resolve(jsonSchema); + // if no output object, return promise with JSON object + return Promise.resolve(jsonSchema); - }); }); }; diff --git a/package.json b/package.json index 511d575..4e6b3b0 100755 --- a/package.json +++ b/package.json @@ -29,8 +29,7 @@ "dependencies": { "commander": "^2.9.0", "fs-extra-promise": "^0.3.1", - "jsdoc-parse": "^1.2.7", - "stream-to-string": "^1.0.1", + "jsdoc-to-markdown": "^6.0.1", "string-to-stream": "^1.1.0" }, "devDependencies": {