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

refactor(docs-page): to TS; split up file #360

Merged

Conversation

thiskevinwang
Copy link
Contributor

@thiskevinwang thiskevinwang commented Sep 28, 2021

asana

Description

  • ♻️ This splits docs-page/server.js into isolated TypeScript files.
    • 🧪 This adds tests per file, with at least some basic coverage, like snapshots
  • 🐛 This fixes some incorrect moize usage
  • ⚡️ This improves types

This is meant to merge into:

@vercel
Copy link

vercel bot commented Sep 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hashicorp/react-components/6miKUkyNtmdtK3bYeA2sgwHiLvj3
✅ Preview: https://react-components-git-kevin-versioned-docs-serv-b57f12-hashicorp.vercel.app

@changeset-bot
Copy link

changeset-bot bot commented Sep 28, 2021

⚠️ No Changeset found

Latest commit: cd07f61

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@thiskevinwang thiskevinwang requested a review from a team September 28, 2021 19:18
Copy link
Contributor

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

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

🥇

Comment on lines 1 to 2
export const ENABLE_VERSIONED_DOCS = process.env.ENABLE_VERSIONED_DOCS
export const VERCEL_ENV = process.env.VERCEL_ENV
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm not super crazy about re-assigning env vars in a separate file like this. I find it harder to grok for usage and it's just another layer of indirection.

That said, I'm not willing to die on this hill and if you feel this is a better structure I'm okay with that. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not tied to this! Happy to revert this change...

I'm more interested in lifting up environment variable usage into function args, so that the functions can be more pure. Didn't get to this part yet though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like

- import { ENABLE_VERSIONED_DOCS, VERCEL_ENV, DEFAULT_PARAM_ID } from './consts'
+ import { DEFAULT_PARAM_ID } from './consts' 

Then in a function

- function generateStaticPaths(context) { ... }

+ const options = {
+  VERCEL_ENV: process.env.VERCEL_ENV,
+  ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS,
+ }
+ 
+ function generateStaticPaths(context, { VERCEL_ENV, ENABLE_VERSIONED_DOCS } = options) { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating this now... and removing the env vars from consts.ts

packages/docs-page/server/generate-static-props.ts Outdated Show resolved Hide resolved
Comment on lines 59 to 71
versions = versionMetadataList.map((e) => {
const { isLatest, version, display } = e
if (isLatest) {
latestVersion = version
}

const displayValue = display ?? version

return {
name: isLatest ? 'latest' : version,
label: isLatest ? `${displayValue} (latest)` : displayValue,
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this could be a fair candidate to extract into a function that's easier to test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracted into mapVersionList

packages/docs-page/server/generate-static-props.ts Outdated Show resolved Hide resolved
Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
@thiskevinwang thiskevinwang changed the title refactor(docs-page): to TS; split up file 🚧 WIP - refactor(docs-page): to TS; split up file Sep 28, 2021
@BRKalow
Copy link
Contributor

BRKalow commented Sep 30, 2021

Looking good! Could you test this with a canary release in a site? That would be full validation that the refactor is good, apart from your tests 😄

@thiskevinwang thiskevinwang added the release:canary Triggers a canary release for commits to this pull request label Sep 30, 2021
@github-actions
Copy link
Contributor

📦 Canary Packages Published

Latest commit: cd07f61

Published 1 packages

@hashicorp/react-docs-page@14.2.4-canary-202183015355

npm install @hashicorp/react-docs-page@canary

thiskevinwang added a commit to hashicorp/waypoint that referenced this pull request Sep 30, 2021
@thiskevinwang thiskevinwang changed the title 🚧 WIP - refactor(docs-page): to TS; split up file refactor(docs-page): to TS; split up file Sep 30, 2021
@thiskevinwang
Copy link
Contributor Author

Merging into #354 — will continue UAT there!

@thiskevinwang thiskevinwang merged commit 2a8dded into kevin/versioned-docs Sep 30, 2021
@thiskevinwang thiskevinwang deleted the kevin/versioned-docs-server-refactor branch September 30, 2021 16:20
thiskevinwang added a commit that referenced this pull request Sep 30, 2021
* refactor(docs-page): to TS; split up file

* test: add at least snapshot tests for all files

* chore: fixtures

* chore: update snapshots

* chore: rename to moizeOpts

* Update packages/docs-page/server/generate-static-props.ts

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>

* chore: extract `mapVersionList`;
- refactor `generateStaticProps` logic

* chore: `generateStaticProps` snapshot

* chore: remove env vars from `consts.ts`

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
thiskevinwang added a commit that referenced this pull request Sep 30, 2021
* refactor(docs-page): to TS; split up file

* test: add at least snapshot tests for all files

* chore: fixtures

* chore: update snapshots

* chore: rename to moizeOpts

* Update packages/docs-page/server/generate-static-props.ts

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>

* chore: extract `mapVersionList`;
- refactor `generateStaticProps` logic

* chore: `generateStaticProps` snapshot

* chore: remove env vars from `consts.ts`

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
thiskevinwang added a commit that referenced this pull request Oct 1, 2021
* refactor(docs-page): to TS; split up file

* test: add at least snapshot tests for all files

* chore: fixtures

* chore: update snapshots

* chore: rename to moizeOpts

* Update packages/docs-page/server/generate-static-props.ts

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>

* chore: extract `mapVersionList`;
- refactor `generateStaticProps` logic

* chore: `generateStaticProps` snapshot

* chore: remove env vars from `consts.ts`

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
thiskevinwang added a commit that referenced this pull request Oct 2, 2021
* feat(docs-page): server.js calls content api

* chore: add logging to generateStaticPaths

* feat: use display attribute if available

* fix: only use display for option label

* feat: always fetch remote content in production

* fix: `moize` usage

* refactor(docs-page/server): to TS; split up files (#360)

* refactor(docs-page): to TS; split up file

* chore: extract `mapVersionList`;
  - refactor `generateStaticProps` logic

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
@github-actions github-actions bot mentioned this pull request Oct 2, 2021
thiskevinwang added a commit to hashicorp/waypoint that referenced this pull request Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:canary Triggers a canary release for commits to this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants