added api.md generation [ci skip]
This commit is contained in:
@ -8,6 +8,7 @@ var clean = require('../../clean');
|
||||
var urlParamRE = /\{(\w+)\}/g;
|
||||
|
||||
var outputPath = _.joinPath(__dirname, '../../../src/lib/api.js');
|
||||
var docOutputPath = _.joinPath(__dirname, '../../../docs/api.md');
|
||||
|
||||
function download() {
|
||||
require('./actions').on('ready', function (actions) {
|
||||
@ -27,6 +28,9 @@ function download() {
|
||||
actions: actions,
|
||||
namespaces: _.unique(namespaces.sort(), true)
|
||||
}));
|
||||
fs.writeFileSync(docOutputPath, templates.apiDocs({
|
||||
actions: actions
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
39
scripts/generate/js_api/templates/api_docs.tmpl
Normal file
39
scripts/generate/js_api/templates/api_docs.tmpl
Normal file
@ -0,0 +1,39 @@
|
||||
# API
|
||||
|
||||
## Table Of Contents
|
||||
|
||||
<%
|
||||
|
||||
function esc(str) {
|
||||
return str.replace(/\|/g, '|');
|
||||
}
|
||||
|
||||
var _paramWithDefault = paramWithDefault;
|
||||
paramWithDefault = function (name, _default) {
|
||||
return esc(_paramWithDefault(name, _default));
|
||||
};
|
||||
|
||||
var _paramType = paramType;
|
||||
paramType = function (type) {
|
||||
return esc(_paramType(type));
|
||||
};
|
||||
|
||||
_.each(actions, function (action) {%>
|
||||
- [<%= action.name %>](#<%= action.name.toLowerCase().replace(/[^\w]/g, '') %>)<%
|
||||
})
|
||||
|
||||
_.each(actions, function (action) {
|
||||
%>
|
||||
|
||||
### <%= action.name %>()
|
||||
|
||||
<%= action.docUrl %>
|
||||
|
||||
| Name | Type | Description |
|
||||
| ---- | ---- | ----------- |
|
||||
<%
|
||||
_.each(action.allParams, function(param, paramName) {
|
||||
%>|`<%= paramWithDefault(paramName, param.default) %>` | <%= paramType(param.type) %> | <%= esc(param.description || '') %>|
|
||||
<% })
|
||||
|
||||
}); %>
|
||||
@ -87,13 +87,13 @@ var templateGlobals = {
|
||||
paramType: function (type) {
|
||||
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
|
||||
case 'time':
|
||||
return 'Date|Number';
|
||||
return 'Date or Number';
|
||||
case 'any':
|
||||
return '*';
|
||||
case 'enum':
|
||||
return 'String';
|
||||
case 'list':
|
||||
return 'String|ArrayOfStrings|Boolean';
|
||||
return 'String or String[] or Boolean';
|
||||
default:
|
||||
return _.ucfirst(type);
|
||||
}
|
||||
@ -125,5 +125,6 @@ fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
||||
templates.text = templates.string;
|
||||
|
||||
module.exports = {
|
||||
apiFile: templates.api_file
|
||||
apiFile: templates.api_file,
|
||||
apiDocs: templates.api_docs
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user