-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Update readme API automatically #823
Conversation
The new api index document seems great. However I feel this template is some how too complicated for the readme, will think about it later. |
Trying to make it simpler:
If user want to modify README file,one just modify the root directory file
|
Thank you for trying to make it simple. It's good to embed the jsdoc TOC to the readme. But after thought a while, what I want to do is to keep the README.md as it is. Could we update README.md by an npm script, instead of totally replace it by a template? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better, but still too complicated.
Please make it easier by removing dependencies and useless files.
docs/partials/link.hbs
Outdated
|
||
{{~#link to~}} | ||
{{#if url~}} | ||
<a href="http://www.baidu.com/{{{url}}}">{{#if ../../caption}}{{../../../caption}}{{else}}{{name}}{{/if}}</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baidu? WTF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o, it's just a test file... I remembered I deleted...
package.json
Outdated
"express": "4.15.2", | ||
"markdown-include": "^0.4.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to do not add markdown-include
dependence because it seems the job could be done without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nop, this dependence is necessary. Or I have to write something like this.
markdown.json
Outdated
{ | ||
"build" : "README.md", | ||
"files" : ["README.md"], | ||
"tableOfContents": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we do the job without this file?
Thanks to @binsee 's idea. I add markdown comment in README.md as follows:
and change the code between the comment automatically using a script. For the developer, if he wants to sync API, just run About the script description:
|
package.json
Outdated
@@ -18,7 +18,10 @@ | |||
"ava": "ava --verbose --extension ts", | |||
"ts-node": "ts-node", | |||
"dist": "npm run clean && tsc && jq \"del (.files)\" < package.json > dist/package.json && shx cp src/puppet-web/*.js dist/src/puppet-web/", | |||
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && jsdoc2md dist/src/{wechaty,room,contact,friend-request,message}.js dist/src/puppet-web/friend-request.js>> docs/index.md", | |||
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && npm run doc-api && npm run doc-readme", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run npm run doc
, output:
E:\CodeWork\fork\wechaty>npm run doc
> wechaty@0.8.231 doc E:\CodeWork\fork\wechaty
> npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation
' > docs/index.md && npm run doc-api && npm run doc-readme
> wechaty@0.8.231 dist E:\CodeWork\fork\wechaty
> npm run clean && tsc && jq "del (.files)" < package.json > dist/package.json && shx cp src/puppet-web/*.js dist/src/puppet-web/
> wechaty@0.8.231 clean E:\CodeWork\fork\wechaty
> shx rm -fr dist/*
'# Wechaty v'$(jq -r .version package.json)' Documentation
Under Windows, \n will parse the error, causing the execution to be interrupted
In addition, echo command in the windows and linux system implementation of the results are different 😂
E:\CodeWork\fork\wechaty>echo '# Wechaty v'$(jq -r .version package.json)' Documentation'
'# Wechaty v'$(jq -r .version package.json)' Documentation'
E:\CodeWork\fork\wechaty>bash
li@BinWork:/mnt/e/CodeWork/fork/wechaty$ echo '# Wechaty v'$(jq -r .version package.json)' Documentation'
# Wechaty v0.8.231 Documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System differences, there is no way
Generating readme very well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better now.
I have some reviews for making this file struct and names to be clearer.
package.json
Outdated
@@ -18,7 +18,10 @@ | |||
"ava": "ava --verbose --extension ts", | |||
"ts-node": "ts-node", | |||
"dist": "npm run clean && tsc && jq \"del (.files)\" < package.json > dist/package.json && shx cp src/puppet-web/*.js dist/src/puppet-web/", | |||
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && jsdoc2md dist/src/{wechaty,room,contact,friend-request,message}.js dist/src/puppet-web/friend-request.js>> docs/index.md", | |||
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && npm run doc-api && npm run doc-readme", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm run doc:api
and
npm run doc:readme
package.json
Outdated
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && jsdoc2md dist/src/{wechaty,room,contact,friend-request,message}.js dist/src/puppet-web/friend-request.js>> docs/index.md", | ||
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && npm run doc-api && npm run doc-readme", | ||
"doc-readme": "npm run doc-index && ts-node docs/update-readme.ts && shx rm -rf docs/doc-index.md", | ||
"doc-index": "jsdoc2md --partial docs/partials/*.hbs --template docs/api-index.hbs dist/src/{wechaty,room,contact,friend-request,message}.js dist/src/puppet-web/friend-request.js>> docs/doc-index.md", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please:
- rename
doc-index
todoc:toc
- output
doc:toc
tostdout
instead of writing it to file, because its output is for temporary usage.
docs/update-readme.ts
Outdated
const endIndex = readme.toString().search(/\[comment\]\: # \(JSDOC SYNC END\)/) | ||
const docString = readme.toString().substring(beginIndex, endIndex) | ||
|
||
const docIndex = await fs.readFileSync('docs/doc-index.md') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use stdin
to read the TOC content at here.
docs/api-index.hbs
Outdated
@@ -0,0 +1,25 @@ | |||
{{#class name="Wechaty"~}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move all *.hbs
file to docs/config/
directory, to give them a more clear location to self-document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this hbs
is not official part. So I suggest to seperate api-index.hbs
with the other two
docs/partials/sig-link-parent.hbs
Outdated
@@ -0,0 +1,13 @@ | |||
{{#if name}}{{#sig~}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this file for? Please explain it(and better to document it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is the jsdoc2md official partials: https://github.com/jsdoc2md/dmd/blob/master/partials/shared/signature/sig-link-parent.hbs
I add link chatie.io/wechaty
here to custom the linkable toc
Also, link.hbs
come from jsdoc2md official partials:
https://github.com/jsdoc2md/dmd/blob/master/partials/shared/value/link.hbs
I add link chatie.io/wechaty
here to custom the linkable toc
And use the following command to override the partials.
jsdoc2md --partial *.hbs a.js > a.md
docs/update-readme.ts
Outdated
const insertToReadme = readme.toString().replace(docString, '[comment]: # (JSDOC SYNC BEGIN) \n\n' + docIndex + '\n') | ||
await fs.writeFileSync('README.md', insertToReadme, 'utf8') | ||
} | ||
updateReadme() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this file to /script/
because it should not under the docs directory.
Or to make it better: could you get rid of this file, and do this job by npm script? If you could, that would be great.
About this commit 1. using
|
I still feel there's something not very right in this PR:
However, I would like to merge this PR if you could get three approvements from the contributors. Good job, thanks. |
commit description
In order to sync
README.md
API doc with code, I create a README template indocs/partials/REAMDE.hbs
, see more in jsdoc-to-markdown-wiki-create-readme-templateThen I got a problem: we cannot sync all of wechaty API in README file because it is so big.
So I picked all of class & function name in README and their links.
And then I got another problem: the function link generated by jsdoc automatically is anchor link (
#
), it means I cannot link it to other pages(http://chatie.io/wechaty), this is very inconvenient for readers, so I override the following templates indocs/partials/overrides
, adding http://chatie.io/wechaty in the link:scripts in package.json description
It will generate two docs:
npm run readme-doc
will generate README.md usingREADME.hbs
template and using the override filelink.hbs
&sig-link-parent.hbs
to addhttp://chatie.io/wechaty
in the doc link.npm run api-doc
will generateindex.md
as we used before.