-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
'use strict'; | ||
|
||
// Import functions | ||
const getContext = require('./getContext.js'); | ||
const templatizer = require('./templatizer.js'); | ||
const validate = require('./configValidation.js'); | ||
|
||
// Import template | ||
const configDefault = require('./template/configDefault.json'); | ||
|
||
// Create error if no docs passed | ||
const noDocsError = new Error('No documentation passed'); | ||
|
||
/** | ||
* Do parsing of documentation and return JSON-Schema with result of parsing | ||
* @param {string} doc - documentation of cli | ||
* @param {object} config - user config of parser | ||
* @throws {error} - if no documentation passed | ||
* @return {object} context - internal config with parsed documentation | ||
*/ | ||
const parser = (doc, config) => { | ||
const configValidated = config ? validate(config) : configDefault; | ||
if (!doc) throw noDocsError; | ||
const context = getContext(doc, configValidated); | ||
return templatizer(context, configValidated); | ||
}; | ||
|
||
// Export function | ||
module.exports = parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters