dgeni-packages
Advanced tools
Comparing version 0.2.2 to 0.2.3
var _ = require('lodash'); | ||
var doctrine = require('doctrine'); | ||
var log = require('winston'); | ||
// A simple container of parsed tags with helpers | ||
var Tags = function(content) { | ||
var parsed = doctrine.parse(content); | ||
this.tags = parsed.tags; | ||
var Tags = function(content, tags) { | ||
// Sloppy implies support for jsdoc3 and closure compiler style types | ||
// Recoverable allows us to collect up information about the bad tags | ||
var parsed = doctrine.parse(content, { sloppy: true, recoverable: true, tags: tags }); | ||
// Filter out the bad tags into a separate collection | ||
var badTags = this.badTags = []; | ||
this.tags = _.filter(parsed.tags, function(tag) { | ||
if ( tag.errors ) { | ||
badTags.push(tag); | ||
} | ||
return !tag.errors; | ||
}); | ||
// Extract the description if necessary | ||
@@ -35,2 +48,3 @@ if ( parsed.description ) { | ||
getType: function(tag) { | ||
try { | ||
var isOptional = tag.type.type === 'OptionalType'; | ||
@@ -54,6 +68,29 @@ var mainType = isOptional ? tag.type.expression : tag.type; | ||
}; | ||
} catch(e) { | ||
console.log(e); | ||
console.log(tag); | ||
throw e; | ||
} | ||
} | ||
}; | ||
function formatBadTagErrorMessage(doc) { | ||
var message = 'Bad tags found in doc "' + doc.id + '" from file "' + doc.file + '" line ' + doc.startingLine + '\n'; | ||
_.forEach(doc.tags.badTags, function(badTag) { | ||
var title = badTag.title || '<missing>'; | ||
var description = | ||
badTag.name || | ||
(_.isString(badTag.description) ? (badTag.description.substr(0, 20) + '...') : '<missing>'); | ||
message += ' - Bad tag: "' + title + '" - "' + description + '"\n'; | ||
_.forEach(badTag.errors, function(error) { | ||
message += ' * ' + error + '\n'; | ||
}); | ||
}); | ||
return message + '\n'; | ||
} | ||
var tags; | ||
var plugin = module.exports = { | ||
@@ -64,7 +101,14 @@ name: 'doctrine-tag-parser', | ||
runBefore: ['tags-parsed'], | ||
init: function(config) { | ||
tags = _.pluck(config.get('processing.tagDefinitions'), 'name'); | ||
log.debug('Tags to parse:', tags); | ||
}, | ||
process: function parseDocsWithDoctrine(docs) { | ||
_.forEach(docs, function(doc) { | ||
doc.tags = new Tags(doc.content); | ||
doc.tags = new Tags(doc.content, tags); | ||
if ( doc.tags.badTags.length > 0 ) { | ||
log.warn(formatBadTagErrorMessage(doc)); | ||
} | ||
}); | ||
} | ||
}; |
{ | ||
"name": "dgeni-packages", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "A collection of dgeni packages for generating documentation from source code", | ||
@@ -36,3 +36,3 @@ "scripts": { | ||
"winston": "~0.7.2", | ||
"doctrine": "~0.2.0", | ||
"doctrine": "~0.3.0", | ||
"graceful-fs": "~2.0.1", | ||
@@ -39,0 +39,0 @@ "q": "~1.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114425
2540
+ Addeddoctrine@0.3.0(transitive)
- Removeddoctrine@0.2.0(transitive)
Updateddoctrine@~0.3.0