chore: add command to generate reference docs#6506
Merged
maribethb merged 8 commits intoRaspberryPiFoundation:developfrom Nov 9, 2022
Merged
chore: add command to generate reference docs#6506maribethb merged 8 commits intoRaspberryPiFoundation:developfrom
maribethb merged 8 commits intoRaspberryPiFoundation:developfrom
Conversation
8 tasks
8 tasks
cpcallen
requested changes
Oct 14, 2022
Collaborator
cpcallen
left a comment
There was a problem hiding this comment.
This is a "Request changes" but, the only strictly mandatory changes are that you fix the indenting to agree with our style guide (+2 instead of +4) and use CONSTANT_CASE where applicable. The rest are please-considers (but please do actually consider).
cpcallen
reviewed
Oct 14, 2022
cpcallen
approved these changes
Oct 26, 2022
Collaborator
|
Would you like me to push a merge commit to resolve the conflicts in this PR? |
Contributor
Author
I was pushing the commit as you were typing this probably :D I have no explanation for the CI failures though, other than I'm sure we've seen this before but I don't know why it keeps happening. |
1 task
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The basics
npm run formatandnpm run lintThe details
Resolves
fixes #5854
Proposed Changes
Adds an npm script that will generate the reference docs using API Extractor.
Behavior Before Change
No reference docs because the old tool does not support TS.
Behavior After Change
https://developers.google.com/blockly/reference/js/blockly
Reason for Changes
History of Reference Documentation
Before the introduction of TypeScript, Blockly used JsDoc comments in the code both for documentation and for Closure Compiler. In fact, Blockly was one of the examples in the google-internal documentation about how to generate reference documentation for devsite (I have emailed the team that maintains this and suggested they find a new example). The tool that we used for that is very specific to Closure-compiler style code and JsDoc annotations, and it isn't compatible with our current codebase, so we had to find a new tool.
Comparison of reference documentation generators
We considered using TypeDoc or API Extractor.
In a comparison between the two tools, the team preferred the look and feel of the API Extractor output. Also, we plan to use the additional functionality of API Extractor in the future to monitor for unintended changes in our public API. Therefore we chose to use API Extractor.
Changes needed for API Extractor to work
Previously, we used JsDoc-style comments, which are similar but not identical to TsDoc comments. Therefore we needed to change the style and contents of many comments. That work was done mostly in #6388 and included things like fixing syntax in comments, escaping special characters, using TsDoc-specific tags in place of JsDoc analogs, etc.
I also added configuration for the tool which had it ignore certain tags that are not part of the TsDoc spec that we currently use, and ignored some warnings that are not applicable to us or we don't want to fix.
I also added linting rules for TsDoc comments in #6353. The old linting rules did not adequately lint the TsDoc style comments. This process also involved comparing multiple available tools, which you can read about in that PR description.
Problems with API Extractor
_2to some names._2from the generated intermediate json file. This may be a bug in API Extractor and may occur when the class shadows the name of a browser global variable.Block, and only the documentation for the namespace would be accessible.block_classblockly.mdindex file.Using patch-package
API Extractor had to be patched for two reasons, shown above. This is accomplished by using the npm package
patch-package. We now have a directory calledpatches/and there is a script that runs oninstallthat will automatically apply any patches in that directory to the relevant npm module.To create a patch, you just modify the contents of a module in
node_modulesthen runpatch-package package-nameand the patch will be added to thepatches/directory. To apply all the patches, you runpatch-packagewith no arguments, and this is configured to be done automatically after runningnpm installthanks to a postinstall script.It is unfortunate to have to patch random npm modules, yes. I commented on the patch with links to the underlying issues, and the format of the patch includes a git diff so it's easy to see what has changed.
Actually using these scripts
Just run
npm run docsand the entire pipeline will be run. You do need to have already runnpm run buildandnpm run packageas the script will not automatically run them. The output will be located in adocs/directory, and you can get the contents of that directory uploaded to devsite however you want. The missing link here (and good future work) is a script that can be run from google-internal to automatically upload this content to devsite.Documentation
Will add information to our team site.
Additional Information