balena-cli/extras/capitanodoc/index.coffee

47 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2015-04-16 13:34:40 +00:00
_ = require('lodash')
2015-07-07 22:01:25 +00:00
path = require('path')
2017-04-26 13:16:06 +00:00
capitanodoc = require('../../capitanodoc')
2015-04-16 13:34:40 +00:00
markdown = require('./markdown')
result = {}
result.title = capitanodoc.title
result.introduction = capitanodoc.introduction
result.categories = []
for commandCategory in capitanodoc.categories
category = {}
category.title = commandCategory.title
category.commands = []
for file in commandCategory.files
2015-07-07 22:01:25 +00:00
actions = require(path.join(process.cwd(), file))
2015-04-16 13:34:40 +00:00
2015-07-07 22:01:25 +00:00
if actions.signature?
category.commands.push(_.omit(actions, 'action'))
else
for actionName, actionCommand of actions
category.commands.push(_.omit(actionCommand, 'action'))
2015-04-16 13:34:40 +00:00
result.categories.push(category)
result.toc = _.cloneDeep(result.categories)
result.toc = _.map result.toc, (category) ->
category.commands = _.map category.commands, (command) ->
2015-04-16 14:42:09 +00:00
return {
signature: command.signature
2015-07-07 22:01:25 +00:00
anchor: '#' + command.signature
2015-04-16 14:42:09 +00:00
.replace(/\s/g,'-')
.replace(/</g, '60-')
.replace(/>/g, '-62-')
.replace(/\[/g, '')
.replace(/\]/g, '-')
.replace(/--/g, '-')
.replace(/\.\.\./g, '')
.replace(/\|/g, '')
.toLowerCase()
}
2015-04-16 13:34:40 +00:00
return category
console.log(markdown.display(result))