Skip to content

copy docs from README to code #1096

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

Merged
merged 2 commits into from
Oct 24, 2022
Merged

copy docs from README to code #1096

merged 2 commits into from
Oct 24, 2022

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Oct 22, 2022

Rather than copy docs from source code into our README, this does the reverse, copying docs from the README into generated source files (that are not checked in). This offers several advantages:

  • The docs are no longer hard-wrapped. 😌
  • There’s only one copy of the docs, avoiding potential drift and errant edits.
  • The README can continue to use relative links (important for versioning).
  • We don’t need ts-morph or to declare a “prefix” (e.g., ##); we simply reference a given doc by name.

In addition, I added some stricter checks:

  • We disallow unterminated jsdoc directives, requiring a matching jsdocEnd for each jsdoc.
  • We validate jsdoc directives more strictly, catching errors such as <!-- jsdoc stack ->.
  • We require each jsdoc directive in the README to be consumed exactly once in the source code.

@mbostock mbostock requested review from Fil and duaneatat October 22, 2022 19:46
@mbostock
Copy link
Member Author

mbostock commented Oct 22, 2022

If it helps, you can review the changes to the README by diffing against the version prior to #1034

9d9ba91...mbostock/one-docs#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5

@Fil
Copy link
Contributor

Fil commented Oct 23, 2022

👍

Shouldn't we rmdir the build/ directory as the last step (as well as as the first step)? I got a bit confused at first.

@mbostock
Copy link
Member Author

Shouldn't we rmdir the build/ directory as the last step (as well as as the first step)?

Usually it is typical to preserve intermediate build artifacts for debugging purposes (and for incremental rebuilds if needed).

@duaneatat
Copy link
Contributor

duaneatat commented Oct 24, 2022

This is nice, but perhaps we should discuss #1055 since these approaches appear to be incompatible?

@mbostock
Copy link
Member Author

@duaneatat A quick addition to this approach would be to support JSDoc type delcarations like so:

/**
 * @jsdoc area
 * @param {Data} data
 * @param {Options=} options
 */

So, I don’t see this approach as being incompatible, and it would still mean there’s only one copy of everything. The type declarations would live with the code and the documentation would live in the README.

@duaneatat
Copy link
Contributor

So, I don’t see this approach as being incompatible, and it would still mean there’s only one copy of everything. The type declarations would live with the code and the documentation would live in the README.

Ahh, yes that's quite nice!

@mbostock mbostock merged commit 977e011 into main Oct 24, 2022
@mbostock mbostock deleted the mbostock/one-docs branch October 24, 2022 23:08
@meetamit
Copy link

meetamit commented Dec 2, 2022

Heads up: When readme-to-jsdoc.ts runs on a Windows machine, unfortunately, the script throws a malformed jsdoc directive error. The cause is that readme.split("\n") leaves a \r at the end of each line, and the RegExps, which rely on $ don't match the directives. I've confirmed that modifying the split to be readme.split("\r\n") fixes the issue.

@Fil
Copy link
Contributor

Fil commented Dec 2, 2022

can you confirm is readme.split(/\r?\n/) works for you?

@meetamit
Copy link

meetamit commented Dec 2, 2022

Hi @Fil.
Yes -- that works.

Fil added a commit that referenced this pull request Dec 5, 2022
Fil added a commit that referenced this pull request Dec 5, 2022
frontend-provider pushed a commit to frontend-provider/plot that referenced this pull request Sep 20, 2023
backend-devloper pushed a commit to backend-devloper/plot that referenced this pull request Nov 24, 2023
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
tigrevol8888 added a commit to tigrevol8888/plot that referenced this pull request Jul 5, 2024
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

Successfully merging this pull request may close these issues.

4 participants