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(init): share common files between templates #5315

Merged
merged 10 commits into from Aug 10, 2021

Conversation

Josh-Cena
Copy link
Collaborator

@Josh-Cena Josh-Cena commented Aug 7, 2021

Motivation

  1. NPM doesn't support packaging symlinks, so the classic-typescript template doesn't work.
  2. Share more resources between templates to deduplicate & unify content.

FS structure:

Before After
.
├── README.MD
├── bootstrap
│   ├── README.md
│   ├── babel.config.js
│   ├── blog
│   │   ├── 2019-05-28-hola.md
│   │   ├── 2019-05-29-hello-world.md
│   │   ├── 2019-05-30-welcome.md
│   │   ├── 2020-04-14-blog-plugin.md
│   │   └── 2020-04-14-large-blog-post.md
│   ├── docs
│   │   ├── doc1.md
│   │   ├── doc2.md
│   │   ├── doc3.md
│   │   └── interactiveDoc.mdx
│   ├── docusaurus.config.js
│   ├── package.json
│   ├── sidebars.js
│   ├── src
│   │   └── pages
│   │       ├── index.js
│   │       ├── markdown-page.md
│   │       └── styles.module.css
│   └── static
│       └── img
│           ├── favicon.ico
│           ├── logo.svg
│           ├── undraw_docusaurus_mountain.svg
│           ├── undraw_docusaurus_react.svg
│           └── undraw_docusaurus_tree.svg
├── classic
│   ├── README.md
│   ├── babel.config.js
│   ├── blog
│   │   ├── 2019-05-28-hola.md
│   │   ├── 2019-05-29-hello-world.md
│   │   └── 2019-05-30-welcome.md
│   ├── docs
│   │   ├── intro.md
│   │   ├── tutorial-basics
│   │   │   ├── _category_.json
│   │   │   ├── congratulations.md
│   │   │   ├── create-a-blog-post.md
│   │   │   ├── create-a-document.md
│   │   │   ├── create-a-page.md
│   │   │   ├── deploy-your-site.md
│   │   │   └── markdown-features.mdx
│   │   └── tutorial-extras
│   │       ├── _category_.json
│   │       ├── manage-docs-versions.md
│   │       └── translate-your-site.md
│   ├── docusaurus.config.js
│   ├── gitignore
│   ├── package.json
│   ├── sidebars.js
│   ├── src
│   │   ├── components
│   │   │   ├── HomepageFeatures.js
│   │   │   └── HomepageFeatures.module.css
│   │   ├── css
│   │   │   └── custom.css
│   │   └── pages
│   │       ├── index.js
│   │       ├── index.module.css
│   │       └── markdown-page.md
│   └── static
│       └── img
│           ├── docusaurus.png
│           ├── favicon.ico
│           ├── logo.svg
│           ├── tutorial
│           │   ├── docsVersionDropdown.png
│           │   └── localeDropdown.png
│           ├── undraw_docusaurus_mountain.svg
│           ├── undraw_docusaurus_react.svg
│           └── undraw_docusaurus_tree.svg
├── classic-typescript
│   ├── README.md (link)
│   ├── babel.config.js (link)
│   ├── blog
│   │   ├── 2019-05-28-hola.md (link)
│   │   ├── 2019-05-29-hello-world.md (link)
│   │   └── 2019-05-30-welcome.md (link)
│   ├── docs
│   │   ├── intro.md (link)
│   │   ├── tutorial-basics
│   │   │   ├── _category_.json (link)
│   │   │   ├── congratulations.md (link)
│   │   │   ├── create-a-blog-post.md (link)
│   │   │   ├── create-a-document.md (link)
│   │   │   ├── create-a-page.md (link)
│   │   │   ├── deploy-your-site.md (link)
│   │   │   └── markdown-features.mdx (link)
│   │   └── tutorial-extras
│   │       ├── _category_.json (link)
│   │       ├── manage-docs-versions.md (link)
│   │       └── translate-your-site.md (link)
│   ├── docusaurus.config.js (link)
│   ├── gitignore (link)
│   ├── package.json
│   ├── sidebars.js (link)
│   ├── src
│   │   ├── components
│   │   │   ├── HomepageFeatures.module.css (link)
│   │   │   └── HomepageFeatures.tsx
│   │   ├── css
│   │   │   └── custom.css (link)
│   │   └── pages
│   │       ├── index.module.css (link)
│   │       ├── index.tsx
│   │       └── markdown-page.md (link)
│   ├── static
│   │   └── img
│   │       ├── docusaurus.png (link)
│   │       ├── favicon.ico (link)
│   │       ├── logo.svg (link)
│   │       ├── tutorial
│   │       │   ├── docsVersionDropdown.png (link)
│   │       │   └── localeDropdown.png (link)
│   │       ├── undraw_docusaurus_mountain.svg (link)
│   │       ├── undraw_docusaurus_react.svg (link)
│   │       └── undraw_docusaurus_tree.svg (link)
│   └── tsconfig.json
└── facebook
    ├── README.md
    ├── babel.config.js
    ├── blog
    │   ├── 2019-05-28-hola.md
    │   ├── 2019-05-29-hello-world.md
    │   └── 2019-05-30-welcome.md
    ├── docs
    │   ├── doc1.md
    │   ├── doc2.md
    │   ├── doc3.md
    │   └── interactiveDoc.mdx
    ├── docusaurus.config.js
    ├── gitignore
    ├── package.json
    ├── sidebars.js
    ├── src
    │   ├── css
    │   │   └── custom.css
    │   └── pages
    │       ├── index.js
    │       ├── markdown-page.md
    │       └── styles.module.css
    └── static
        └── img
            ├── favicon.ico
            ├── logo.svg
            ├── oss_logo.png
            ├── undraw_docusaurus_mountain.svg
            ├── undraw_docusaurus_react.svg
            └── undraw_docusaurus_tree.svg
.
├── README.MD
├── bootstrap
│   ├── docusaurus.config.js
│   ├── package.json
│   └── src
│       └── pages
│           ├── index.js
│           └── styles.module.css
├── classic
│   ├── docusaurus.config.js
│   ├── package.json
│   └── src
│       ├── components
│       │   ├── HomepageFeatures.js
│       │   └── HomepageFeatures.module.css
│       ├── css
│       │   └── custom.css
│       └── pages
│           ├── index.js
│           └── index.module.css
├── classic-typescript
│   ├── package.json
│   ├── src
│   │   ├── components
│   │   │   ├── HomepageFeatures.module.css (link)
│   │   │   └── HomepageFeatures.tsx
│   │   └── pages
│   │       ├── index.module.css (link)
│   │       └── index.tsx
│   └── tsconfig.json
├── facebook
│   ├── README.md
│   ├── babel.config.js
│   ├── docusaurus.config.js
│   ├── gitignore
│   ├── package.json
│   ├── sidebars.js
│   └── src
│       ├── css
│       │   └── custom.css
│       └── pages
│           ├── index.js
│           └── styles.module.css
└── shared
    ├── README.md
    ├── babel.config.js
    ├── blog
    │   ├── 2019-05-28-hola.md
    │   ├── 2019-05-29-hello-world.md
    │   └── 2019-05-30-welcome.md
    ├── docs
    │   ├── intro.md
    │   ├── tutorial-basics
    │   │   ├── _category_.json
    │   │   ├── congratulations.md
    │   │   ├── create-a-blog-post.md
    │   │   ├── create-a-document.md
    │   │   ├── create-a-page.md
    │   │   ├── deploy-your-site.md
    │   │   └── markdown-features.mdx
    │   └── tutorial-extras
    │       ├── _category_.json
    │       ├── manage-docs-versions.md
    │       └── translate-your-site.md
    ├── gitignore
    ├── sidebars.js
    ├── src
    │   └── pages
    │       └── markdown-page.md
    └── static
        └── img
            ├── docusaurus.png
            ├── favicon.ico
            ├── logo.svg
            ├── tutorial
            │   ├── docsVersionDropdown.png
            │   └── localeDropdown.png
            ├── undraw_docusaurus_mountain.svg
            ├── undraw_docusaurus_react.svg
            └── undraw_docusaurus_tree.svg

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

$ yarn docusaurus-init init test-website classic --typescript --skip-install

Related PRs

Followup of #5233.

Considerations

This may lead to more confusions for potential contributors. Should we symlink all the files still, so that contributors can edit the files in the most straightforward location?

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 7, 2021
@netlify
Copy link

netlify bot commented Aug 7, 2021

✔️ [V2]

🔨 Explore the source changes: 524357c

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/611289da9655350007574b60

😎 Browse the preview: https://deploy-preview-5315--docusaurus-2.netlify.app

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@github-actions
Copy link

github-actions bot commented Aug 7, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 96
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5315--docusaurus-2.netlify.app/

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks, that looks fine.

You should also share the static folder because FB template can't run without some images used in the tutorial:

image

"paths": {
"@site/*": ["./*"]
}
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, looks like another thing we could add to the base config 🤪

Opened a PR here: tsconfig/bases#71

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, let's hold on till that's merged

@slorber
Copy link
Collaborator

slorber commented Aug 10, 2021

Thanks 👍 Going to merge this.

I think we'll want in the future t only have a TS classic template folder, and maybe generate the JS template automatically with TSC targeting esnext? (like we do for the theme js/ts swizzling). That feels a bit odd to have to maintain the js/ts homepage separately. Not a priority though.

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Aug 10, 2021
@Josh-Cena
Copy link
Collaborator Author

Errr—Shouldn't we wait for the new TS base config?

@slorber slorber added pr: maintenance This PR does not produce any behavior differences to end users when upgrading. and removed pr: bug fix This PR fixes a bug in a past release. labels Aug 10, 2021
@slorber slorber merged commit 4c24649 into facebook:master Aug 10, 2021
@slorber
Copy link
Collaborator

slorber commented Aug 10, 2021

@Josh-Cena no worry we'll make another PR if needed. We'll need to update our website's ts config too anyway

@Josh-Cena
Copy link
Collaborator Author

Josh-Cena commented Aug 10, 2021

I think we'll want in the future t only have a TS classic template folder, and maybe generate the JS template automatically with TSC targeting esnext? (like we do for the theme js/ts swizzling).

I thought about that as well. Don't know exactly how Sam did it back then, but definitely worth looking into

One thing to consider: the JS template right now is not simply TS with all the types stripped. For example, they have different approaches to how feature images are imported (partly because I don't know how to type the require('.svg').default result)

@Josh-Cena Josh-Cena deleted the fix-ts-init branch August 10, 2021 14:28
@slorber
Copy link
Collaborator

slorber commented Aug 10, 2021

I thought about that as well. Don't know exactly how Sam did it back then, but definitely worth looking into

We transpile the theme with 2 different babel configs (check babel.config.js), leading to 2 distinct output folders used as sources for swizzled comps:

image

One thing to consider: the JS template right now is not simply TS with all the types stripped. For example, they have different approaches to how feature images are imported (partly because I don't know how to type the require('.svg').default result)

Oh yeah didn't notice. That type should be React.ComponentType<React.ComponentProps<'svg'>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants