Skip to content
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

Spike how we can integrate information from Typedoc in our own docs #5157

Closed
2 of 3 tasks
Tracked by #5144
romaricpascal opened this issue Jul 19, 2024 · 4 comments
Closed
2 of 3 tasks
Tracked by #5144
Labels
documentation User requests new documentation or improvements to existing documentation javascript

Comments

@romaricpascal
Copy link
Member

romaricpascal commented Jul 19, 2024

What

Spike to discover:

  • which informations on our API Typedoc can provide us in a format we can then integrate in our docs (hopefully JSON or similar machine parseable format)
  • how we can integrate that information in the frontend docs
  • what this automation would mean for authoring/reviewing the content of the API docs

Why

So we can automatically generate part of our API documentation in our docs

Who needs to work on this

Developers, Tech Writers

Who needs to review this

Developers, Tech Writers

Done when

We've identified:

  • Information Typedoc gives us access to
  • How we could integrate it in the frontend docs
  • The impact on authoring/reviewing the API docs
@romaricpascal romaricpascal added documentation User requests new documentation or improvements to existing documentation javascript labels Jul 19, 2024
@romaricpascal
Copy link
Member Author

We currently integrate our Sass API doc automatically, so there may be interesting bits to take away from there (thinking of the authoring/reviewing).

@owenatgov
Copy link
Contributor

I looked at this very briefly today. The hope is that we can export our js API via typedoc the same way we do with sassdoc.

How our sass API is generated via sassdoc

This is mainly driven by the build:sassdoc and build:sassdocv4 commands which are both run by the postinstall command. These can all be found in the package.json. The build commands are just running sassdoc but specifying the entry point as within the govuk-frontend package and the output as a json file.

In the index for the Sass API reference page
it interprets this json data, with the help of the sassdocs_helpers module. At this stage it's data interpolation and feels very possible.

How we might generate our JS API via typedoc

Typedoc has similar functions for specifying an entry point and an output location as json. It looks like it might be a bit more involved though. The cli won't run without a valid config and we don't distribute our one in govuk-frontend. We can either replicate it in the frontend docs or try exporting it. There may be a need to redo some of our paths so the former option might be better, if a bit of a drag.

@owenatgov
Copy link
Contributor

Update

After spending all this week tweeking and trying stuff, we managed to finally get a typedoc of govuk-frontend produced from within the frontend docs 🎉 Click here to see the test branch.

The main takeaway is that there are a few things we don't export in govuk-frontend that result in typescript raising type errors. Notably we have comments in our code where we ask ts not to emit an error, but these aren't being read in the package because we don't include comments for methods marked as private. Because of this, we were only able to produce a typedoc using typedoc's --skipErrorChecking flag.

Additionally, because we don't include which methods are private in our built package, typedoc isn't able to distinguish between public and private methods.

Next steps

We're going to take the following into a more final implementation:

  • Maintain the tsconfig built during the spike
  • Update govuk-frontend's output on package build to keep methods marked as @private and @ts-expect-error comments in the package module files (but not the bundles)
  • Continue using the --skipErrorChecking flag in any future build commands

In addition, we're going to further investigate the following:

  • Why our methods are listed as 'external' by typedoc and what this means for us
  • How to mitigate risks of the frontend docs not building when a new version of govuk-frontend is published in case an unforseen ts error is flagged

@romaricpascal romaricpascal added epic Epics are used in planning project boards to group related stories and removed epic Epics are used in planning project boards to group related stories labels Sep 10, 2024
@romaricpascal
Copy link
Member Author

Going to close this spike as the work on it is over. We can look further into this as we tackle #5227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation User requests new documentation or improvements to existing documentation javascript
Projects
Status: In progress 📝
Development

No branches or pull requests

3 participants