-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Move to Electron's docs-parser tooling for Node.js documentation #32206
Comments
I'm generally in favour of auto-generation from docs, but Node.js doc structure might be a bit further from Electron's than is workable. Perhaps a POC should look at the harder edges. From a quick look at the style guilde, this seems a bit restrictive: https://github.com/electron/electron/blob/master/docs/styleguide.md#page-title Not all APIs need requiring: And then there are things that aren't "API"s in the js API sense, CLI options, C++ Addons, etc. |
@sam-github did you take a look at the POC I linked? Here it is again: bnb/node-docs-parser ❤️ It is worth noting that my POC runs a multi-module mode that @MarshallOfSound implemented that addresses Node.js's needs around certain headings and multiple classes - this mode is not currently reflected in the Style Guide. As noted in the Current Challenges and Potential Blockers section, there's an open PR to decouple Electron-specific bits. In my POC, that specific require requirement you pointed to was not a problem as far as I could tell. |
Yes, which is why I pointed out both APIs are "nice" js APIs, with a well-defined require, but not all Node APIs are like that. |
@sam-github i see that but also i'm curious how you feel that relates to the above goal? As an native C++ API there wouldn't need to be types for it, would there? It would to my knowledge be exempted from docs-parser's style requirements, as they only apply to APIs for which type definitions would need to be created. I also think that styleguide definitely isn't hard and fast and would accept alterations to fit different needs, so I don't think js APIs would need to be "nice" in order to fit into the end-product :) |
Not c++:
|
Again, I'm not trying to discourage trying this, but I'm trying to point out that as a POC goes, choosing well-formed simple APIs like query_string, workers, and v8 isn't likely to find the stuff that's hard to work with. APIs like the two I mentioned, globals and timers, or Fwiw, I personally think the mapping of .md to .html to single .json is not necessary to maintain, if all the api json was one single file, that'd be fine (though perhaps a breaking change, to someone, somewhere). |
@sam-github for Errors and Globals I have a much clearer idea of how they could be implemented in the POC - theoretically could be straightforward, but would be different than how it looks now. It would likely make use of the |
@bnb how much help does the parser give in terms of what you need to update. Maybe you have it in the above but an example of the output on an existing Node.js file and what is reported by the parser might help illustrate the process of doing a conversion. |
@mhdawson at present, the way I figured things out was by just peeking at the JSON to see if it output what was expected. There are a few errors it will throw if something goes really wrong, but currently AFAIK there is not direct error reporting on syntax errors. Personally, I found it relatively straightforward to convert the docs I did since the required structure is extremely consistent. One of the things that I've had some light discussions about lately with the Electron folks is a markdown linter that enforces the style guide. Theoretically this can be implemented using existing markdown tooling and leveraging their custom rules engines - using something like Additionally, it's worth noting that we could begin to implement the required style without implementing the tooling, and then implement the tooling. |
My initial thought after reading through the first time is that linting - as well as hinting in VS Code - could reasonably be implemented as one or more custom rules in markdownlint. (The header structure in particular has a lot in common with rule MD043.) This project might choose to turn off some of the other rules that aren't relevant, but may find value in enforcing maximum line lengths, etc.. It seems like there's a bigger discussion about whether the broader effort is practical and worthwhile, but the linting aspects appear to be something we could get working. |
@bnb ... where are things at with this? Should this remain open? |
I'm happy to continue working on it. I've honestly not had a ton of time to continue working on it since some other commitments came up, but those literally ended yesterday. Happy to spend time next week fleshing out more examples outside of the basic ones I provided. Also more than happy to have other folks help if they're interested - I can pair anytime on it, or help provide additional context. |
As a note: I met with @Ethan-Arrowood yesterday and we discussed how to begin approaching this. We roughly agreed on the best path to adoption in Node.js would be to start with stripping out the styleguide parsing from docs-parser, making it an independent module, and introduce it as a linter to get all our docs uniform. This is based on a recommendation from this thread. Electron's docs-parser could just consume that module (there likely won't be a barrier to consuming it from the electron side, presuming we build it in the Electron org which should be straightforward), making the linter and docs-parser uniform in their parsing. From there, we can begin to adapt the Node.js docs to use docs-parser's JSON output both as our own source of truth for docs and to generate types if that's something we want to do. |
As a note: help is appreciated if folks are interested in working on this with @Ethan-Arrowood and myself. |
Over the past four months, I've gotten more and more involved in Electron as a project. Generally, they are extremely forward on automation and tooling intended to reduce maintainer burden since they are such a small team maintaining such a large project.
One of the tools they created, docs-parser, is especially interesting and I think Node.js could benefit from adopting it as a fundamental piece of our documentation tooling.
Why
I see quite significant benefits to adopting docs-parser:
getHeapStatistics()
have an empty "description" property. This emptiness is extremely useful in finding places where additional context can be added. For example, it's trivial to write a tool that checks for empty "description" properties. This provides an excellent path forward to enriching our documentation with context that's useful to users who don't have the same understanding that we do.master
. This provides a way for maintainers to parse out the changes to APIs in code in addition to just personally reading the docs themselves.How does docs-parser differ from what we currently have?
Document Structure
docs-parser requires a specific document structure that is currently documented in the Electron Styleguide API Reference section.
This structure has specific expectations about titles, descriptions, modules, methods, events, classes (undocumented here: multi-class mode, which would be needed in Node.js and is currently supported by docs-parser), static properties, instance methods, and instance properties.
I've worked on converting Node.js's
querystring
,v8
, andworker-threads
docs in a personal repo which you can find here in the docs/api directory: bnb/node-docs-parser. Please take a look if you're interested in what the differences are - the first commit on each file was the state I started with and the final commit in each is the docs-parser version. Additionally, there's a directory with the original versions that you can compare side-by-side if you'd prefer to approach it that way.In doing this I found that - while a few things did need to be shuffled around to correctly parse - the overall updated structure was more clear and approachable with minimal additional effort.
Actual Markdown
docs-parser requires a comparatively strict structure around markdown input, since it directly parses markdown.
Here's an example from Node.js:
And here's the current equivalent in docs-parser:
They seem nearly identical, and indeed they basically are. This is a good example of how minor some of the necessary changes are. Here's another slightly more complicated example:
Node.js version:
docs-parser version:
However, docs-parser has an interesting technical benefit. Like our current setup, it outputs JSON. Compare the two following JSON outputs:
Node.js JSON output:
docs-parser JSON output:
The latter output has a significantly larger amount of useful context extracted from the same Markdown.
Current Challenges and Potential Blockers
I would like to get a feeling for how folks feel about these potential technical/functional blockers.
The text was updated successfully, but these errors were encountered: