UNPKG

apeman-doc

Version:
107 lines (97 loc) 3.87 kB
/** * Documentize an apemanfile. * @function apemanfileDocBud */ "use strict"; const _tmpl = require('./_tmpl'), assert = require('assert'), arraysort = require('arraysort'), textconv = require('textconv'); /** @lends apemanfileDocBud */ function apemanfileDocBud(apemanfile) { if (typeof apemanfile === 'string') { apemanfile = require(apemanfile); } assert.ok(apemanfile, 'apemanfile is required.'); let $pkg = apemanfile.$pkg, $apps = apemanfile.$apps, $notes = apemanfile.$notes, $needs = apemanfile.$needs, $tmpls = apemanfile.$tmpls, $tasks = apemanfile.$tasks, $wchs = apemanfile.$wchs, $proto = apemanfile.$proto; let stringCompare = arraysort.stringCompare(); return { force: true, mode: '444', mkdirp: true, tmpl: _tmpl('apemanfile_doc.md.hbs'), data: { get 'pkg'() { return $pkg; }, get 'proto'() { return $proto && $proto.map((proto) => { return proto.$pkg; }); }, get 'apps'() { return $apps && Object.keys($apps).sort(stringCompare).map((name) => { let app = $apps[name], $note = $notes && $notes['$apps.' + name]; let desc = $note || app.$desc || app.$description || JSON.stringify(app); return { name: name, desc: textconv.chop(textconv.inline(desc), 80, {ellipsis: true}) } }) ; }, get 'tmpls'() { return $tmpls && Object.keys($tmpls).sort(stringCompare).map((path) => { let tmpl = $tmpls[path]; return { path: path, force: tmpl.force, mode: tmpl.mode, get tmpl() { let value = textconv.inline(tmpl.tmpl); return textconv.chop(value, 40, {ellipsis: true}); }, get data() { var value = textconv.inline(JSON.stringify(tmpl.data)); return textconv.chop(value, 40, {ellipsis: true}); } } }); }, get 'tasks'() { return $tasks && Object.keys($tasks).sort(stringCompare).map((name) => { let task = $tasks[name], $note = $notes && $notes['$tasks.' + name]; let desc = $note || task.$desc || task.$description || JSON.stringify(task); return { name: name, desc: textconv.chop(textconv.inline(desc), 80, {ellipsis: true}) } }); }, get 'wchs'() { return $wchs && Object.keys($wchs).sort(stringCompare).map((name) => { let watch = $wchs[name], $note = $notes && $notes['$wchs.' + name]; let desc = $note || watch.$desc || watch.$description || JSON.stringify(watch); return { name: name, desc: textconv.chop(textconv.inline(desc), 80, {ellipsis: true}) } }); }, get 'needs'() { return $needs; } } } } module.exports = apemanfileDocBud;