Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate README Doc #200

Closed
grant opened this issue May 30, 2018 · 4 comments
Closed

Generate README Doc #200

grant opened this issue May 30, 2018 · 4 comments

Comments

@grant
Copy link
Contributor

grant commented May 30, 2018

Expected Behavior

The README methods should be generated from the TypeScript file.

Actual Behavior

The README is slightly out of date, duplicates jsdoc comments, and must be hand edited.

Solution

  • Create a file called generateDocs.ts.
  • Running tsc generateDocs.ts && node generateDocs.js should build the README without modifications needed.
    • This script should use the TS Compiler API over index.ts. A header and footer would be added to the README.
  • A test should check that the current README file matches the latest generated README file.
@grant grant changed the title Generate README Docs Generate README Doc May 30, 2018
@grant
Copy link
Contributor Author

grant commented May 30, 2018

This npm module (esprima) looks promising.

Example:

var esprima = require('esprima');
var program = `
const answer = 42
console.log('hi');

commander
  .command('create [scriptTitle] [scriptParentId]')
  .description('Create a script')
  .action(create);

/**
 * Fetches a project and saves the script id locally.
 */
commander
  .command('clone [scriptId] [versionNumber]')
  .description('Clone a project')
  .action(clone);
`;

var p = esprima.parse(program);
console.log(JSON.stringify(p, null, 2));

But it does not parse comments.

@campionfellin
Copy link
Collaborator

jsdoc might be nice, since we write our comments using their format already. Looks like there is jsdoc2md to generate the ReadMe.

@grant
Copy link
Contributor Author

grant commented May 30, 2018

The problem is most tools assume js, not ts.
For jsdoc2md, the parser only detects functions and not the commander.command syntax (it is blank).

@grant
Copy link
Contributor Author

grant commented May 30, 2018

OK, so I think we can generate a README if we just parse the ts comments in one file.
We can use this library that doesn't care about the actual filetype or syntax, it just looks at the comments and provides a nice AST:

https://github.com/jonschlinkert/parse-comments

Example:

const str = `
/**
 * Read in source files from file paths or glob patterns. 
 *
 * js
 * verb.src('src/*.hbs', {layout: 'default'});
 * 
 *
 * **Example usage**
 *
 * js
 * verb.task('site', function() {
 *   verb.src('src/*.hbs', {layout: 'default'})
 *     verb.dest('dist');
 * });
 * 
 *
 * @param {String|Array} \`glob\` Glob patterns or file paths to source files.
 * @param {Object} \`options\` Options or locals to merge into the context and/or pass to \`src\` plugins
 * @api public
 */
function foo() {
  
}
/**
 * Bat bat
 */
`;
var comments = require('parse-comments');
var s = comments(str);
console.log(s);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants