apidoc-markdown3
Advanced tools
Comparing version 0.3.7 to 1.0.0
136
index.js
#!/usr/bin/env node | ||
"use strict"; | ||
const fs = require('fs'); | ||
const ejs = require('ejs'); | ||
const _ = require('underscore'); | ||
var fs = require('fs'), | ||
ejs = require('ejs'), | ||
_ = require('underscore'); | ||
/* eslint-disable prefer-destructuring */ | ||
const argv = require('optimist') | ||
.usage('Generate documentation from apidoc data.\nUsage: apidoc-markdown2 -p [path] -o [output file]') | ||
.demand(['path', 'output']) | ||
.alias({ | ||
path: 'p', | ||
output: 'o', | ||
template: 't', | ||
}) | ||
.describe({ | ||
path: 'Path to generated apidoc output. Where api_data.json & api_project.json resides.', | ||
output: 'Output file to write.', | ||
template: 'Path to EJS template file, if not specified default template will be used.', | ||
prepend: 'Prepend file after TOC.', | ||
}).argv; | ||
/* eslint-enable prefer-destructuring */ | ||
var argv = require('optimist') | ||
.usage('Generate documentation from apidoc data.\nUsage: apidoc-markdown2 -p [path] -o [output file]') | ||
.demand(['path', 'output']) | ||
.alias({ | ||
'path': 'p', | ||
'output': 'o', | ||
'template': 't' | ||
}) | ||
.describe({ | ||
'path': 'Path to generated apidoc output. Where api_data.json & api_project.json resides.', | ||
'output': 'Output file to write.', | ||
'template': 'Path to EJS template file, if not specified default template will be used.', | ||
'prepend': 'Prepend file after TOC.' | ||
}).argv; | ||
function undef(obj) { | ||
return obj || ''; | ||
} | ||
ejs.filters.undef = function (obj) { | ||
return obj ? obj : ''; | ||
}; | ||
function mlink(obj) { | ||
return (obj || '').toLowerCase().replace(/\s/g, '-'); | ||
} | ||
ejs.filters.mlink = function (obj) { | ||
return (obj || '').toLowerCase().replace(/\s/g, '-'); | ||
}; | ||
function strip(obj) { | ||
return (obj || '').replace(/<[^>]*>/g, ''); | ||
} | ||
ejs.filters.strip = function (obj) { | ||
return (obj || '').replace(/<[^>]*>/g, ''); | ||
}; | ||
function upcase(obj) { | ||
return (obj || '').toUpperCase(); | ||
} | ||
ejs.filters.padding = function (obj) { | ||
var parts = (obj || '').split('.'); | ||
var padding = new Array(parts.length - 1).fill(' ').join(''); | ||
function padding(obj) { | ||
const parts = (obj || '').split('.'); | ||
const padded = new Array(parts.length - 1).fill(' ').join(''); | ||
return [padding, parts[parts.length - 1]].join(''); | ||
}; | ||
return [padded, parts[parts.length - 1]].join(''); | ||
} | ||
var tmplFile = argv.template ? argv.template : __dirname + '/templates/default.md', | ||
apiData = JSON.parse(fs.readFileSync(argv.path + '/api_data.json')), | ||
projData = JSON.parse(fs.readFileSync(argv.path + '/api_project.json')), | ||
template = ejs.compile(fs.readFileSync(tmplFile).toString()); | ||
const tmplFile = argv.template ? argv.template : `${__dirname}/templates/default.md`; | ||
apiData = _.filter(apiData, function (entry) { | ||
return entry.type; | ||
}); | ||
let apiData = JSON.parse(fs.readFileSync(`${argv.path}/api_data.json`)); | ||
var apiByGroup = _.groupBy(apiData, function (entry) { | ||
return entry.group; | ||
}); | ||
const projData = JSON.parse(fs.readFileSync(`${argv.path}/api_project.json`)); | ||
var apiByGroupAndName = {}; | ||
Object.keys(apiByGroup).forEach(function (key) { | ||
apiByGroupAndName[key] = _.groupBy(apiByGroup[key], function (entry) { | ||
return entry.name; | ||
}); | ||
const template = ejs.compile(fs.readFileSync(tmplFile).toString()); | ||
apiData = _.filter(apiData, entry => entry.type); | ||
const apiByGroup = _.groupBy(apiData, entry => entry.group); | ||
const apiByGroupAndName = {}; | ||
Object.keys(apiByGroup).forEach((key) => { | ||
apiByGroupAndName[key] = _.groupBy(apiByGroup[key], entry => entry.name); | ||
}); | ||
function createApiSorter(order) { | ||
return function sort(name) { | ||
var idx = order.indexOf(name); | ||
if (idx === -1) return Infinity; | ||
return idx; | ||
} | ||
return function sort(name) { | ||
const idx = order.indexOf(name); | ||
if (idx === -1) return Infinity; | ||
return idx; | ||
}; | ||
} | ||
var sorter = createApiSorter(projData.order || []); | ||
const sorter = createApiSorter(projData.order || []); | ||
var groupOrder = _.sortBy(Object.keys(apiByGroup), sorter); | ||
const groupOrder = _.sortBy(Object.keys(apiByGroup), sorter); | ||
var nameOrderInGroup = {}; | ||
Object.keys(apiByGroupAndName).forEach(function (group) { | ||
nameOrderInGroup[group] = _.sortBy(Object.keys(apiByGroupAndName[group]), sorter); | ||
const nameOrderInGroup = {}; | ||
Object.keys(apiByGroupAndName).forEach((group) => { | ||
nameOrderInGroup[group] = _.sortBy(Object.keys(apiByGroupAndName[group]), sorter); | ||
}); | ||
var data = { | ||
project: projData, | ||
data: apiByGroupAndName, | ||
groupOrder: groupOrder, | ||
nameOrder: nameOrderInGroup | ||
const data = { | ||
project: projData, | ||
data: apiByGroupAndName, | ||
groupOrder, | ||
nameOrder: nameOrderInGroup, | ||
filters: { | ||
undef, | ||
mlink, | ||
strip, | ||
padding, | ||
upcase, | ||
}, | ||
}; | ||
@@ -89,2 +97,4 @@ | ||
fs.writeFileSync(argv.output, template(data)); | ||
console.log('Wrote apidoc-markdown2 template output to: ' + argv.output); | ||
/* eslint-disable no-console */ | ||
console.log(`Wrote apidoc-markdown2 template output to: ${argv.output}`); | ||
/* eslint-enable no-console */ |
{ | ||
"name": "apidoc-markdown3", | ||
"version": "0.3.7", | ||
"version": "1.0.0", | ||
"description": "Generate API documentation in markdown format from apidoc data.", | ||
@@ -31,9 +31,12 @@ "main": "index.js", | ||
"dependencies": { | ||
"ejs": "^2.6.1", | ||
"optimist": "~0.6.0", | ||
"underscore": "~1.5.2", | ||
"ejs": "~0.8.5" | ||
"underscore": "~1.5.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.4.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"release-it": "^7.5.0" | ||
} | ||
} |
# apidoc-markdown3 | ||
>NOTE: forked and updated vulnerable dependencies | ||
>NOTE: forked and updated vulnerable ejs to latest version (filters are no longer supported) | ||
@@ -5,0 +5,0 @@ Generate API documentation in markdown from [apidoc](https://github.com/apidoc/apidoc) data. |
@@ -7,5 +7,5 @@ <a name="top"></a> | ||
<% groupOrder.forEach(function (group) { -%> | ||
- [<%= group %>](#<%=: group | mlink %>) | ||
- [<%= group %>](#<%= filters.mlink(group) %>) | ||
<% nameOrder[group].forEach(function (sub) { -%> | ||
- [<%= data[group][sub][0].title %>](#<%=: data[group][sub][0].title | mlink %>) | ||
- [<%= data[group][sub][0].title %>](#<%= filters.mlink(data[group][sub][0].title) %>) | ||
<% }); -%> | ||
@@ -19,11 +19,11 @@ | ||
<% groupOrder.forEach(function (group) { -%> | ||
# <a name='<%=: group | mlink %>'></a> <%= group %> | ||
# <a name='<%= filters.mlink(group) %>'></a> <%= group %> | ||
<% nameOrder[group].forEach(function (sub) { -%> | ||
## <a name='<%=: data[group][sub][0].title | mlink %>'></a> <%= data[group][sub][0].title %> | ||
## <a name='<%= filters.mlink(data[group][sub][0].title) %>'></a> <%= data[group][sub][0].title %> | ||
[Back to top](#top) | ||
<%-: data[group][sub][0].description | undef %> | ||
<%- filters.undef(data[group][sub][0].description) %> | ||
<%-: data[group][sub][0].type | upcase %> <%= data[group][sub][0].url %> | ||
<%- filters.upcase(data[group][sub][0].type) %> <%= data[group][sub][0].url %> | ||
@@ -30,0 +30,0 @@ <% if (data[group][sub][0].header && data[group][sub][0].header.fields.Header.length) { -%> |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
526
1
25137
4
8
+ Addedejs@2.7.4(transitive)
- Removedejs@0.8.8(transitive)
Updatedejs@^2.6.1