Skip to content

Commit

Permalink
Reduce size by replacing jsdoc-to-markdown with jsdoc-parse and dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Jul 14, 2016
1 parent 4fc2758 commit 1467cf9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
42 changes: 22 additions & 20 deletions handlebars/helpers.js
Expand Up @@ -12,6 +12,8 @@ var qfs = require('q-io/fs')
var util = require('util')
var collect = require('stream-collect')
var Q = require('q')
var jsdocParse = require('jsdoc-parse')
var dmd = require('dmd')

module.exports = {
/**
Expand All @@ -21,12 +23,15 @@ module.exports = {
* @param {string} headerPrefix a string such as '##' that is use as prefix for lines starting with '#' to reduced the header-size
*/
jsdoc: function (globPattern, headerPrefix) {
var jsdoc2md = require('jsdoc-to-markdown')
return collect(jsdoc2md({src: globPattern}))
.then(function (output) {
var markdown = output.toString('utf-8')
return markdown.replace(/^#/mg, headerPrefix + '#')
})
var deferred = Q.defer()
var stream = jsdocParse({src: globPattern})
.on('error', function(err) { deferred.reject(err) })
.pipe(dmd())
.on('error', function(err) { deferred.reject(err) })

return collect(stream, 'utf-8', function (markdown) {
deferred.fulfill(markdown.replace(/^#/mg, (headerPrefix || '') + '#'))
})
},

/**
Expand Down Expand Up @@ -224,7 +229,7 @@ module.exports = {
return options.fn(this, {data: data})
},

github: function(filePath) {
github: function (filePath) {
return githubUrl(filePath)
},

Expand All @@ -233,22 +238,22 @@ module.exports = {
* @param options
* @returns {string=} the repository path within github.com (or null)
*/
githubRepo: function(options) {
var url = null;
githubRepo: function (options) {
var url = null
try {
url = options.data.root.package.repository.url
var match = url.match(/.*?(:\/\/|@)github\.com[/:](.*?)(#.*?)?$/)
if (match) {
return match[2].replace(/\.git$/, '')
} else {
return null;
return null
}
} catch (e) {
console.log("Cannot find repository url");
console.log('Cannot find repository url')
url = null
}

console.log(url.replace(""));
console.log(url.replace(''))
},

/**
Expand All @@ -257,7 +262,6 @@ module.exports = {
*/
npm: function (packageName) {
return '[' + packageName + '](https://npmjs.com/package/' + packageName + ')'

},

/**
Expand All @@ -278,13 +282,13 @@ module.exports = {
var travis = qfs.read('.travis.yml')
var appveyor = qfs.read('appveyor.yml')
return Q.allSettled([travis, appveyor]).then(function (files) {
var i;
for (i=0; i<files.length; i++) {
if (files[i].state==='fulfilled' && files[i].value.indexOf('coveralls')>=0) {
return true;
var i
for (i = 0; i < files.length; i++) {
if (files[i].state === 'fulfilled' && files[i].value.indexOf('coveralls') >= 0) {
return true
}
}
return false;
return false
})
}

Expand Down Expand Up @@ -388,7 +392,6 @@ function treeFromPathComponents (files, label) {
} else {
return result
}

}

function githubUrl (filePath) {
Expand All @@ -402,4 +405,3 @@ function githubUrl (filePath) {
return url.replace(/^git\+/, '').replace(/\.git$/, '') + '/blob/v' + version + '/' + relativePath
}
}

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -39,11 +39,12 @@
"customize-engine-handlebars": "<1.0.0",
"customize-write-files": "^0.1.2",
"debug": "^2.2.0",
"dmd": "^1.4.1",
"find-package": "^1.0.0",
"get-promise": "^1.3.1",
"glob": "^5.0.12",
"handlebars": "^3.0.3",
"jsdoc-to-markdown": "^1.1.1",
"jsdoc-parse": "^1.2.7",
"lodash": "^3.10.1",
"minimatch": "^2.0.10",
"multilang-apidocs": "^0.2.1",
Expand Down

0 comments on commit 1467cf9

Please sign in to comment.