Skip to content

feat: Refine api reference docs generation process #8229

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 15 commits into from
Mar 11, 2025

Conversation

stocaaro
Copy link
Member

@stocaaro stocaaro commented Jan 31, 2025

Description of changes:

This change is process/automation only and contains no docs site changes.

Changes:

  • Add a command so that a user may call yarn clean-references -- -p amplify-js in the docs repo.
  • Make process support multiple packages
  • Move all needed automation into one step/process

This command will:

  • Look for ../amplify-js/docs/references.json
  • Transform the references.json file to optimize it for docs use and write the result to ./src/directory/apiReferences/amplify-js.json

This process will allow library package owners to add a workflow that:

Which product(s) are affected by this PR (if applicable)?

  • amplify-cli
  • amplify-ui
  • amplify-studio
  • amplify-hosting
  • amplify-libraries

Which platform(s) are affected by this PR (if applicable)?

  • JS
  • Swift
  • Android
  • Flutter
  • React Native

Please add the product(s)/platform(s) affected to the PR title

Checks

  • Does this PR conform to the styleguide?

  • Does this PR include filetypes other than markdown or images? Please add or update unit tests accordingly.

  • Are any files being deleted with this PR? If so, have the needed redirects been created?

  • Are all links in MDX files using the MDX link syntax rather than HTML link syntax?

    ref: MDX: [link](https://docs.amplify.aws/)
    HTML: <a href="https://docs.amplify.aws/">link</a>

When this PR is ready to merge, please check the box below

  • Ready to merge

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change moves the config without updating it. We're moving it so that other repo's can be extracted into a reasonable structure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raw file is an intermediate transformation artifact that isn't directly used. This change removes it as it serves no purpose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing that! Imagine the CO2 produced when cloning and copying this file. Should it be added to the gitignore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it, however this dir location isn't used in the new process since the file is read from the neighboring package, then the complete product is written directly into the directories, skipping over all the interstitial steps the original process had.

@@ -135,13 +155,84 @@ function recursivelyPopulateNodes(node) {
}
}

function processReferences(references, rootPackage) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is taken directly from the working branch that was used to generate the original references process https://github.com/aws-amplify/amplify-js/blob/feat/inline-api-docs/scripts/process-typedoc.mjs#L31-L108

This change proposes having a single transformation from the generated references.json file to the transformed / optimized apiReferences/*.json file where all of the transform logic is here in this file.

Comment on lines -1 to -15
name: Receive repository dispatch event

on:
# Listen to a repository dispatch event by the name of `dispatch-event`
repository_dispatch:
types: [update-references]
workflow_dispatch:
permissions:
contents: write # Used to commit updated references PR
pull-requests: write # Used to create updated references PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
create-pull-request:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am removing this workflow. Instead of having a trigger-able process to on the docs repo, I propose each repo have a workflow to push a PR against the docs repo as can be seen in the draft js change

@stocaaro stocaaro changed the title feat: Refactor api generation feat: Refine api generation process Mar 4, 2025
@stocaaro stocaaro marked this pull request as ready for review March 4, 2025 20:06
@stocaaro stocaaro requested a review from a team as a code owner March 4, 2025 20:06
@stocaaro stocaaro changed the title feat: Refine api generation process feat: Refine api reference docs generation process Mar 4, 2025
AllanZhengYP
AllanZhengYP previously approved these changes Mar 6, 2025
Copy link
Member

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach makes sense to me. Thank you for doing it!
I think clean-references script needs a lot of work to make the API reference in docs look better. It seems like the node walker logic misses a lot of doc nodes, and make the page misses a lot examples we wrote in source code.

But I think we can make it a follow-up task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing that! Imagine the CO2 produced when cloning and copying this file. Should it be added to the gitignore?

@@ -1,4 +1,4 @@
import { API_CATEGORIES, API_SUB_CATEGORIES } from '@/data/api-categories';
import { API_CATEGORIES, API_SUB_CATEGORIES } from '@/data/api-categories.mjs';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. If I remove the file type, then I get an error

src/utils/getApiStaticPath.ts

There wasn't a *.d.ts file there before so I'm not sure why the prior version worked :-/

Copy link
Member Author

@stocaaro stocaaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree that the clean-references could use a good refactor. Looking at the result, I think a lot of content is being skipped over in the display logic, so there are some quick wins to add comments into the doc without retooling the transformation.

From what I grox of this transformation logic, its there to:

    1. Prune a bunch of exports that aren't referenced to make the file smaller.
    1. Reindex the references so that access is constant time vs linear when looking up related code/type references

AllanZhengYP
AllanZhengYP previously approved these changes Mar 6, 2025
@calebpollman
Copy link
Member

Love seeing so much red here! With the size of the diff here being so large, how are we validating there is no impact to the existing documentation

cshfang
cshfang previously approved these changes Mar 10, 2025
@@ -1,8 +1,8 @@
import references from '../src/references/raw-references.json' assert { type: 'json' };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebpollman The original process proposed have the JS repo generate and check in this raw file, which the docs repo would then transform into the apiReferences.json file, which I have moved to scop by package name.

My update process proposes that the JS repo (and other repos) should generate their api docs json files, then use the docs repo transformation logic proposed here to transform the file directly into the finished product instead of having multiple interstitial json files checked in along the way.

I had originally included updating the amplify-js file with this change, but it seems better to do this using the automated process and leave this change a no-op for the docs.

@stocaaro stocaaro dismissed stale reviews from cshfang and AllanZhengYP via 3be1a7f March 11, 2025 16:21
@stocaaro stocaaro merged commit a1d9d81 into main Mar 11, 2025
12 checks passed
@stocaaro stocaaro deleted the stocaaro/api-reference-refactor/main branch March 11, 2025 19:32
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