forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature styled apidocs (hyperledger-archives#2267)
* produced markdown api docs * turn off jsdoc * updates for unittests * put back what git took away * cleanup stray comment * link checker * remove api link;
- Loading branch information
Showing
19 changed files
with
406 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
packages/composer-common/lib/codegen/fromjs/jsongenerator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
// const Writer = require('../writer'); | ||
|
||
/** | ||
* @private | ||
* @class | ||
* @memberof module:composer-common | ||
*/ | ||
class JSONGenerator { | ||
|
||
/** | ||
* @param {Object} program - the program arguments | ||
* @param {Object} file - the file instance being processed | ||
* @param {Object[]} includes - the includes (require statements) within the file | ||
* @param {Object[]} classes - the classes within the file | ||
* @param {Object[]} functions - the functions within the file | ||
*/ | ||
generate(program, file, includes, classes, functions) { | ||
let data = classes[0]; | ||
if (data){ | ||
data.description = data.commentData.description.split('\n'); | ||
data.seeAlso=[]; | ||
data.visibility='public'; | ||
data.commentData.tags.forEach((e)=>{ | ||
if (e.title==='extends'){ | ||
data.extends=e.name; | ||
} else if (e.title === 'see'){ | ||
// "See [Registry]{@link module:composer-client.Registry}" | ||
let s1 = e.description.substring(0,e.description.indexOf('{')); | ||
let a = e.description.indexOf('}'); | ||
let b = e.description.lastIndexOf('.')+1; | ||
data.seeAlso.push(s1+'('+e.description.substring(a,b).toLowerCase()+')'); | ||
} else if (e.title === 'memberof'){ | ||
|
||
data.module=e.description.substr(e.description.indexOf('-')+1); | ||
|
||
} else if (e.title === 'private'){ | ||
data.visibility ='private'; | ||
} else if (e.title === 'protected'){ | ||
data.visibility='protected'; | ||
} | ||
}); | ||
delete data.tags; | ||
|
||
|
||
|
||
let listMethods = data.methods; | ||
listMethods | ||
.forEach((e)=>{ | ||
e.description = e.commentData.description.split('\n'); | ||
e.parameters = []; | ||
e.commentData.tags.forEach( (p)=>{ | ||
if (p.title==='param'){ | ||
let oneParam = {}; | ||
oneParam.description=p.description; | ||
if (p.type.type==='OptionalType'){ | ||
oneParam.type=p.type.expression.name; | ||
oneParam.name=p.name; | ||
oneParam.optional=true; | ||
} else { | ||
oneParam.type=p.type.name; | ||
oneParam.name=p.name; | ||
oneParam.optional=true; | ||
} | ||
e.parameters.push(oneParam); | ||
} else if (p.title.startsWith('return')) { | ||
e.return={description:p.description.split('\n'), | ||
type : p.type.name}; | ||
} | ||
}); | ||
}); | ||
|
||
let f = path.resolve(program.outputDir, path.parse(file).name+'.json'); | ||
fs.writeFileSync(f,JSON.stringify(data)); | ||
} | ||
// console.log(JSON.stringify(data)); | ||
} | ||
} | ||
|
||
|
||
module.exports = JSONGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
layout: default | ||
title: {{name}} ({{module | capitalize }} API) | ||
section: api | ||
sidebar: sidebars/accordion-toc0.md | ||
excerpt: The Client, Admin, and Runtime components of Hyperledger Composer . | ||
index-order: {{index}} | ||
--- | ||
# {{name}} | ||
|
||
{{commentData.description}} | ||
|
||
### Details | ||
- **Extends** {{extends}} | ||
- **Module** {{module}} | ||
|
||
### See also | ||
{% for sa in seeAlso -%} | ||
- {{sa}} | ||
{% endfor %} | ||
|
||
## Method Summary | ||
| Returns | Name | Description | | ||
| :-------- | :---- | :----------- | | ||
{% for method in methods | sort(attribute='name') %}| `{{method.returnType}}` | [{{method.name}}](#{{method.name | lower }}{% for args in method.methodArgs %}-{{args | lower }}{% endfor %}) | {{method.description[0]}} | | ||
{% endfor %} | ||
|
||
## Method Details | ||
{% for method in methods %} | ||
{% if method.name == 'constructor'%} | ||
## new {{name}}() | ||
{% else %} | ||
## {{method.name}}({% for args in method.methodArgs %}{{args | lower }}{% if not loop.last %},{% endif %}{% endfor %}) | ||
{% endif %} | ||
|
||
|
||
|
||
{% for l in method.description -%} | ||
{{l}} | ||
{% endfor %} | ||
|
||
{% if method.example %} | ||
### Example | ||
```javascript | ||
{{method.example}} | ||
``` | ||
{% endif %} | ||
|
||
{% if method.return %} | ||
|
||
### Returns | ||
`{{method.return.type}}` - {% for l in method.return.description -%} | ||
{{l}} | ||
{% endfor %} | ||
|
||
{% endif %} | ||
|
||
|
||
### Parameters | ||
{% if method.parameters | length != 0 -%} | ||
| Name | Type | Optional | Description | | ||
| :----------- | :----------- | :----------- | :----------- | | ||
{% for p in method.parameters -%} | ||
|**{{p.name}}**|`{{p.type}}`|{{p.optional}}|{{p.description}}| | ||
{% endfor %} | ||
{% else %} | ||
|
||
No parameters | ||
{% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env node | ||
|
||
const classopus = require('../lib/classopus'); | ||
const yargs = require('yargs'); | ||
|
||
// Standard Command yargs processing. | ||
let results = yargs | ||
.option('i', { | ||
alias: 'input', | ||
demandOption: false, | ||
describe: 'Input JSON', | ||
type: 'string' | ||
}) | ||
.option('o', { | ||
alias: 'outdir', | ||
demandOption: false, | ||
default: './out', | ||
describe: 'Output Directory', | ||
type: 'string' | ||
}).option('t', { | ||
alias: 'template', | ||
demandOption: false, | ||
default: 'default.njk', | ||
describe: 'Template file to use as basis for markdown', | ||
type: 'string' | ||
}).option('n', { | ||
alias: 'indexname', | ||
demandOption: false, | ||
default: 'bnd-opus.md', | ||
describe: 'Name of the generated markdown file', | ||
type: 'string' | ||
}).option('c',{ | ||
alias: 'context', | ||
default : '{}', | ||
describe: 'Additional options to pass to the template engine\'s context', | ||
type: 'string' | ||
}) | ||
.strict() | ||
.help().argv; | ||
|
||
classopus(results); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
const path = require("path"); | ||
const fs = require("fs"); | ||
const nunjucks = require("nunjucks"); | ||
const util = require("util"); | ||
const mkdirp = require("mkdirp"); | ||
|
||
// convience method | ||
let LOG = console.log; | ||
|
||
// main function | ||
function go(args) { | ||
|
||
mkdirp(args.outdir); | ||
|
||
// sort out template and target file | ||
const targetFile = path.resolve(args.outdir, path.parse(args.input).name + '.md'); | ||
const contextFile = path.resolve(args.input + '.json'); | ||
const templatePath = path.resolve(__dirname, "..", "_template"); | ||
|
||
// Note autoescape false - otherwise the --> in the cto file is replaced with --> | ||
let env = nunjucks.configure(templatePath, { autoescape: false }); | ||
|
||
|
||
let context = JSON.parse(args.context); | ||
|
||
Promise.resolve() | ||
// parse that | ||
.then((result) => { | ||
|
||
}).then(() => { | ||
let str = fs.readFileSync(contextFile); | ||
Object.assign(context,JSON.parse(str)); | ||
|
||
// render the model | ||
let renderedMarkown = env.render(args.template, context); | ||
|
||
// and write out the file | ||
fs.writeFileSync(targetFile, renderedMarkown, { encoding: "utf8" }); | ||
console.log("All written to " + targetFile); | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
}); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
module.exports = go; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.