Skip to content

Commit

Permalink
Migrate website to astro [Step 1] (#4587)
Browse files Browse the repository at this point in the history
Progress for #2564 
Changes: 
- Decided to cut versioning for now. Starlight doesn't support well now
and would be a decent amount of work. Our doc have been quite stable and
this slows down the build significantly.\


The plan is as follow
1. Merge this as a parallel build to the docusaurus website
2. Add blog back
3. Cleanup things (like migrate more things out of fluentui react
components)
4. Switch the website to use this one
5. If we are happy delete docusaurus
  • Loading branch information
timotheeguerin authored Oct 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3f7204c commit 0c3cd36
Showing 126 changed files with 8,528 additions and 1,643 deletions.
6 changes: 6 additions & 0 deletions .chronus/changes/website-astro-try2-2024-9-2-18-16-8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/http"
---
8 changes: 8 additions & 0 deletions .chronus/changes/website-astro-try2-2024-9-2-22-23-42.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: feature
packages:
- "@typespec/playground"
---

Expose state storage helper via its own exports
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -199,9 +199,13 @@ developer/
*.vsix
*.zip

# Astro
.astro/

# Api extractor
packages/*/etc/
docs/**/js-api/
packages/website-astro/src/content/docs/current/**/js-api/

# VS Code test web temp files
.vscode-test-web/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ packages/website/versioned_docs/**/standard-library/built-in-data-types.md

# Auto generated version list
packages/website/playground-versions.json
packages/website-astro/playground-versions.json

# Auto generated built-in template list
packages/compiler/templates/scaffolding.json
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"astro-build.astro-vscode",
"vitest.explorer"
]
}
19 changes: 12 additions & 7 deletions cspell.yaml
Original file line number Diff line number Diff line change
@@ -10,7 +10,10 @@ words:
- alzimmer
- amqp
- AQID
- arraya
- astimezone
- astro
- astrojs
- asyncio
- atrule
- atteo
@@ -72,16 +75,18 @@ words:
- giacamo
- globby
- graalvm
- Gson
- Hdvcmxk
- headasbooleanfalse
- headasbooleantrue
- Gson
- imple
- Infima
- inlines
- inmemory
- instanceid
- interner
- intrinsics
- ints
- IOHTTP
- isdigit
- isinstance
@@ -119,6 +124,7 @@ words:
- multis
- munge
- mylib
- myname
- mypy
- nanos
- nexted
@@ -145,6 +151,7 @@ words:
- Perfolizer
- picocolors
- posargs
- primitivea
- prismjs
- proto
- protobuf
@@ -163,7 +170,9 @@ words:
- rcfile
- reactivex
- recase
- recorda
- regen
- rehype
- repr
- respecify
- rjust
@@ -177,6 +186,7 @@ words:
- segmentof
- serde
- sfixed
- shiki
- sint
- snakeyaml
- srnagar
@@ -191,6 +201,7 @@ words:
- tomli
- triaging
- TRYIT
- tsconfigs
- tsdoc
- TSES
- tspd
@@ -234,12 +245,6 @@ words:
- xplat
- xxsubtype
- yamls
- arraya
- primitivea
- recorda
- Hdvcmxk
- ints
- myname
ignorePaths:
- "**/node_modules/**"
- "**/dist/**"
1 change: 0 additions & 1 deletion docs/extending-typespec/emitters-basics.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
id: emitters
title: Emitters
---

2 changes: 1 addition & 1 deletion docs/introduction/installation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: installation
title: Installation
slug: /
slug: docs
---

## Requirements
1 change: 0 additions & 1 deletion docs/language-basics/alias.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
id: aliases
title: Aliases
---

3 changes: 2 additions & 1 deletion eng/tsp-core/pipelines/pr-tools.yml
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ extends:
persistCredentials: true

- template: /eng/tsp-core/pipelines/templates/install.yml
- template: /eng/tsp-core/pipelines/templates/install-browsers.yml

- template: /eng/tsp-core/pipelines/templates/build.yml

@@ -61,7 +62,7 @@ extends:
--destination \$web \
--account-name "tspwebsitepr" \
--destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \
--source "./packages/website/build/" \
--source "./packages/website-astro/dist/" \
--overwrite
- script: npx tsx eng/tsp-core/scripts/create-tryit-comment.ts
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -142,7 +142,9 @@ export default tsEslint.config(
"**/temp/**/*",
"**/generated-defs/*",
"**/website/build/**/*",
"**/.astro/**/*",
"**/.docusaurus/**/*",
"packages/website-astro/src/assets/**/*",
"packages/compiler/templates/**/*", // Ignore the templates which might have invalid code and not follow exactly our rules.
"**/venv/**/*", // Ignore python virtual env
"**/.vscode-test-web/**/*", // Ignore VSCode test web project
2 changes: 2 additions & 0 deletions packages/http/src/decorators.ts
Original file line number Diff line number Diff line change
@@ -708,6 +708,8 @@ export const $sharedRoute: SharedRouteDecorator = (
* exclude it.
*
* @see isApplicableMetadata
*
* @ignore Cause issue with conflicting function of same name for now
*/
export function $includeInapplicableMetadataInPayload(
context: DecoratorContext,
4 changes: 4 additions & 0 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@
"types": "./dist/src/index.d.ts",
"default": "./dist/index.js"
},
"./state-storage": {
"types": "./dist/src/state-storage.d.ts",
"default": "./dist/state-storage.js"
},
"./vite": {
"types": "./dist/src/vite/index.d.ts",
"default": "./dist/vite/index.js"
1 change: 1 addition & 0 deletions packages/playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ export default defineConfig({
lib: {
entry: {
index: "src/index.ts",
"state-storage": "src/state-storage.ts",
"react/index": "src/react/index.ts",
"react/viewers/index": "src/react/viewers/index.tsx",
"tooling/index": "src/tooling/index.ts",
6 changes: 6 additions & 0 deletions packages/website-astro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Temporary to help with migration
src/content/docs/docs/
src/content/docs/docs/next/
src/assets/
public/

9 changes: 9 additions & 0 deletions packages/website-astro/.scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
import { runOrExit } from "@typespec/internal-build-utils";

if (process.env.TYPESPEC_SKIP_DOCUSAURUS_BUILD?.toLowerCase() === "true") {
console.log("Skipping docusaurus build: TYPESPEC_SKIP_DOCUSAURUS_BUILD=true");
process.exit(0);
}

await runOrExit("npm", ["run", "build:web"]);
55 changes: 55 additions & 0 deletions packages/website-astro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Starlight Starter Kit: Basics

[![Built with Starlight](https://astro.badg.es/v2/built-with-starlight/tiny.svg)](https://starlight.astro.build)

```
npm create astro@latest -- --template starlight
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/basics)
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/withastro/starlight&create_from_path=examples/basics)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fwithastro%2Fstarlight%2Ftree%2Fmain%2Fexamples%2Fbasics&project-name=my-starlight-docs&repository-name=my-starlight-docs)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
## 🚀 Project Structure

Inside of your Astro + Starlight project, you'll see the following folders and files:

```
.
├── public/
├── src/
│ ├── assets/
│ ├── content/
│ │ ├── docs/
│ │ └── config.ts
│ └── env.d.ts
├── astro.config.mjs
├── package.json
└── tsconfig.json
```

Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name.

Images can be added to `src/assets/` and embedded in Markdown with a relative link.

Static assets, like favicons, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat).
7 changes: 7 additions & 0 deletions packages/website-astro/algolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
// cspell:disable-next-line
appId: "V3T9EUVLJR",
// This is the search API KEY this can be public https://support.algolia.com/hc/en-us/articles/18966776061329-Can-the-search-API-key-be-public
apiKey: "bae16ae67ddbe24e700ac20d192ad20f",
indexName: "typespec",
};
74 changes: 74 additions & 0 deletions packages/website-astro/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-check
import react from "@astrojs/react";
import starlight from "@astrojs/starlight";
import { defineConfig } from "astro/config";
import { readFile } from "fs/promises";
import { resolve } from "path";
import rehypeMermaid from "rehype-mermaid";
import remarkHeadingID from "remark-heading-id";
import { resolveSideBars } from "./sidebars";
import tspTryitCode from "./src/plugins/tsp-tryit-code";

const base = process.env.TYPESPEC_WEBSITE_BASE_PATH ?? "/";

const grammarPath = resolve(import.meta.dirname, "../../grammars/typespec.json");
const tspGrammar = JSON.parse((await readFile(grammarPath)).toString());

const typespecLang = {
...tspGrammar,
id: "typespec",
scopeName: "source.tsp",
path: grammarPath,
aliases: ["typespec", "tsp"],
};

// https://astro.build/config
export default defineConfig({
base,
trailingSlash: "always",
integrations: [
starlight({
title: "TypeSpec",
sidebar: await resolveSideBars(),
customCss: ["./src/css/custom.css"],
components: {
Header: "./src/components/header/header.astro",
},
expressiveCode: {
themes: ["one-light", "one-dark-pro"],
styleOverrides: {
frames: {
frameBoxShadowCssValue: "",
},
},
plugins: [tspTryitCode(base + "playground/")],
},
head: [
{
tag: "script",
attrs: {
src: "https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js",
},
},
{
tag: "script",
attrs: {
type: "module",
async: true,
src: "1ds-init.js",
},
},
],
plugins: [],
}),
react(),
],
markdown: {
// @ts-expect-error wrong type
remarkPlugins: [remarkHeadingID],
rehypePlugins: [rehypeMermaid],
shikiConfig: {
langs: [typespecLang],
},
},
});
Loading

0 comments on commit 0c3cd36

Please sign in to comment.