Skip to content

Commit 0ddf4dd

Browse files
authored
Separate react package (#83)
* Moved React files out of compiler folder * Got compiler building * Shared now lints itself * Removed redundant actions tasks * Unified package commands * Cleaned up scripts * Don't double install * Explicit build order of packages * Got react compiling * Fixed formatting * Cleaned up compiler * Got examples working * Fixed more scripts * Build script fixes * CI fix * Another fix * Import fixes * Small fix * package fixes * Implemented much easier to extend mechanism * Bug fixes * Updated examples * Build fixes * README updates * Explicitly list swc as a dep
1 parent ea1d35e commit 0ddf4dd

File tree

244 files changed

+4589
-5493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+4589
-5493
lines changed

.github/workflows/examples.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Example Builds
1+
name: Examples
22

33
on:
44
push:
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
build-and-test:
12-
name: Example Build and Test
12+
name: Example Build Verification
1313
runs-on: ubuntu-latest
1414

1515
steps:
@@ -22,11 +22,10 @@ jobs:
2222
with:
2323
node-version: "24"
2424
- name: Install dependencies
25-
run: npm ci && npm install --workspaces
26-
- name: Build Docs MD
27-
working-directory: ./packages/docs-md
28-
run: npm run build
29-
# We have to run npm install again to link the newly built docs-md binary
25+
run: npm ci
26+
- name: Build Packages
27+
run: make build-packages
28+
# We have to run npm install again to link the newly built compiler binary
3029
- name: Link workspace binaries
3130
run: npm install --workspaces
3231
- name: Verify example builds
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docs MD
1+
name: Packages
22

33
on:
44
push:
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
build-and-test:
12-
name: Docs MD Build and Test
12+
name: Packages Build and Lint
1313
runs-on: ubuntu-latest
1414

1515
steps:
@@ -23,15 +23,11 @@ jobs:
2323
node-version: "24"
2424
- name: Install dependencies
2525
run: npm ci
26-
- name: Lint
27-
working-directory: ./packages/docs-md
28-
run: npm run lint
26+
- name: Build packages
27+
run: make build-packages
2928
- name: Type check
30-
working-directory: ./packages/docs-md
31-
run: npm run type-check
32-
- name: Test
33-
working-directory: ./packages/docs-md
34-
run: npm run test
35-
- name: Build
36-
working-directory: ./packages/docs-md
37-
run: npm run build
29+
run: make type-check-packages
30+
- name: Lint
31+
run: make lint-packages
32+
- name: Check formatting
33+
run: make check-formatting-packages

.vscode/launch.json

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"skipFiles": [
1212
"<node_internals>/**"
1313
],
14-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
14+
"program": "${workspaceFolder}/packages/compiler/src/cli/cli.ts",
1515
"runtimeArgs": ["--experimental-strip-types"],
1616
"args": ["--verbose"],
1717
"cwd": "${workspaceFolder}/examples/docusaurus/mistral"
@@ -23,7 +23,7 @@
2323
"skipFiles": [
2424
"<node_internals>/**"
2525
],
26-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
26+
"program": "${workspaceFolder}/packages/compiler/src/cli/cli.ts",
2727
"runtimeArgs": ["--experimental-strip-types"],
2828
"args": ["--verbose"],
2929
"cwd": "${workspaceFolder}/examples/docusaurus/pokeapi"
@@ -35,7 +35,7 @@
3535
"skipFiles": [
3636
"<node_internals>/**"
3737
],
38-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
38+
"program": "${workspaceFolder}/packages/compiler/src/cli/cli.ts",
3939
"runtimeArgs": ["--experimental-strip-types"],
4040
"args": ["--verbose"],
4141
"cwd": "${workspaceFolder}/examples/nextra/mistral"
@@ -47,46 +47,34 @@
4747
"skipFiles": [
4848
"<node_internals>/**"
4949
],
50-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
50+
"program": "${workspaceFolder}/packages/compiler/src/cli/cli.ts",
5151
"runtimeArgs": ["--experimental-strip-types"],
5252
"args": ["--verbose"],
5353
"cwd": "${workspaceFolder}/examples/nextra/pokeapi"
5454
},
5555
{
5656
"type": "node",
5757
"request": "launch",
58-
"name": "Mistral (External)",
58+
"name": "Mistral (Custom)",
5959
"skipFiles": [
6060
"<node_internals>/**"
6161
],
62-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
62+
"program": "${workspaceFolder}/packages/compiler/src/cli/cli.ts",
6363
"runtimeArgs": ["--experimental-strip-types"],
6464
"args": ["--verbose"],
65-
"cwd": "${workspaceFolder}/../mistral-docs"
65+
"cwd": "${workspaceFolder}/examples/custom/mistral"
6666
},
6767
{
6868
"type": "node",
6969
"request": "launch",
70-
"name": "Redis",
70+
"name": "PokeAPI (Custom)",
7171
"skipFiles": [
7272
"<node_internals>/**"
7373
],
74-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
74+
"program": "${workspaceFolder}/packages/compiler/src/cli/cli.ts",
7575
"runtimeArgs": ["--experimental-strip-types"],
7676
"args": ["--verbose"],
77-
"cwd": "${workspaceFolder}/../redis-demo-docs"
78-
},
79-
{
80-
"type": "node",
81-
"request": "launch",
82-
"name": "Castle",
83-
"skipFiles": [
84-
"<node_internals>/**"
85-
],
86-
"program": "${workspaceFolder}/packages/docs-md/src/compiler/cli/cli.ts",
87-
"runtimeArgs": ["--experimental-strip-types"],
88-
"args": ["--verbose"],
89-
"cwd": "${workspaceFolder}/../castle-docs-demo"
77+
"cwd": "${workspaceFolder}/examples/custom/pokeapi"
9078
}
9179
]
9280
}

Makefile

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
1-
type-check:
2-
npm run type-check --workspaces
1+
EXAMPLES_WORKSPACES = --workspace examples/docusaurus --workspace examples/custom --workspace examples/nextra
32

4-
lint:
5-
npm run lint --workspaces
3+
install:
4+
npm install
65

7-
test: type-check lint
8-
npm test --workspaces
6+
type-check: type-check-packages type-check-examples
97

10-
format:
11-
npm run format --workspaces
8+
type-check-packages:
9+
npm run type-check --workspace packages
1210

13-
install:
14-
npm install
15-
npm install --workspaces
11+
type-check-examples:
12+
npm run type-check $(EXAMPLES_WORKSPACES)
13+
14+
lint: lint-packages lint-examples
15+
16+
lint-packages:
17+
npm run lint --workspace packages
18+
19+
lint-examples:
20+
npm run lint $(EXAMPLES_WORKSPACES)
21+
22+
format: format-packages format-examples
23+
24+
format-packages:
25+
npm run format --workspace packages
26+
27+
format-examples:
28+
npm run format $(EXAMPLES_WORKSPACES)
29+
30+
check-formatting: check-formatting-packages check-formatting-examples
31+
32+
check-formatting-packages:
33+
npm run check-formatting --workspace packages
34+
35+
check-formatting-examples:
36+
npm run check-formatting $(EXAMPLES_WORKSPACES)
37+
38+
build: build-packages build-examples
39+
40+
build-packages:
41+
npm run build --workspace packages/react
42+
npm run build --workspace packages/compiler
43+
44+
build-examples:
45+
npm run build $(EXAMPLES_WORKSPACES)
1646

1747
build-api-docs:
18-
npm run build-api-docs --workspaces -- --clean
48+
npm run build-api-docs $(EXAMPLES_WORKSPACES) -- --clean
1949

2050
verify-api-docs: build-api-docs
2151
@if ! (git diff --exit-code --quiet examples/ && git diff --cached --exit-code --quiet examples/); then \
2252
git status examples/; \
2353
echo "Example build out of date. Please run make build-api-docs and commit the results"; \
2454
exit 1; \
2555
fi
26-
27-
build: install
28-
npm run build --workspaces
29-
30-
start:
31-
npx concurrently \
32-
"npm run dev --workspace=server" \
33-
"npm run dev --workspace=client/web" \
34-
"npm run dev --workspace=demos" \
35-
"npm run dev --workspace=asset-proxy"
36-
37-
add-demo:
38-
npm run add-demo --workspace="@speakeasy-api/codewords-demos"
39-
40-
.PHONY: interactive
41-
42-
interactive:
43-
npm run interactive --workspace=server -- --spec=$(spec) --lang=$(lang) --token=$(token) --command=$(command)

eslint.config.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { resolve } from "node:path";
2+
3+
import { getDirname } from "cross-dirname";
4+
5+
// Import workspace-specific configs
6+
import compilerConfig from "./packages/compiler/eslint.config.mjs";
7+
import reactConfig from "./packages/react/eslint.config.mjs";
8+
import sharedConfig from "./packages/shared/eslint.config.mjs";
9+
10+
const rootDir = getDirname();
11+
const gitignorePath = resolve(rootDir, ".gitignore");
12+
13+
export default [
14+
// Global ignores for the entire monorepo
15+
{
16+
ignores: [
17+
"**/node_modules/**",
18+
"**/dist/**",
19+
"**/build/**",
20+
"**/.next/**",
21+
"scaffold-templates/**",
22+
"examples/**",
23+
],
24+
},
25+
26+
// Apply compiler config to compiler package
27+
...compilerConfig.map(config => ({
28+
...config,
29+
files: config.files ? config.files.map(f => `packages/compiler/${f}`) : ["packages/compiler/**/*"],
30+
})),
31+
32+
// Apply react config to react package
33+
...reactConfig.map(config => ({
34+
...config,
35+
files: config.files ? config.files.map(f => `packages/react/${f}`) : ["packages/react/**/*"],
36+
})),
37+
38+
// Apply shared config to shared package
39+
...sharedConfig.map(config => ({
40+
...config,
41+
files: config.files ? config.files.map(f => `packages/shared/${f}`) : ["packages/shared/**/*"],
42+
})),
43+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

examples/custom/mistral/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "next dev -p 3005",
77
"build-api-docs": "docs-md",
8-
"prebuild": "cd ../../../packages/docs-md && npm run build",
8+
"prebuild": "cd ../../../ && make build-packages",
99
"build": "next build",
1010
"start": "next start",
1111
"lint": "next lint",
@@ -16,13 +16,14 @@
1616
"@mdx-js/react": "^3.1.0",
1717
"@next/mdx": "^15.4.5",
1818
"@speakeasy-api/docs-md": "*",
19+
"@speakeasy-api/docs-md-react": "*",
1920
"@types/mdx": "^2.0.13",
2021
"http-server": "^14.1.1",
21-
"next": "15.4.5",
22+
"next": "^15.5.3",
2223
"nextra": "^4.3.0",
2324
"nextra-theme-docs": "^4.3.0",
24-
"react": "19.1.0",
25-
"react-dom": "19.1.0",
25+
"react": "^19.1.0",
26+
"react-dom": "^19.1.0",
2627
"rehype-slug": "^6.0.0",
2728
"remark-gfm": "^4.0.1",
2829
"remark-heading-id": "^1.0.1"

examples/custom/mistral/speakeasy.config.mjs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,41 @@
11
import { join, resolve } from "node:path";
22
import { writeFileSync } from "node:fs";
33

4-
import {
5-
getSettings,
6-
MdxRenderer,
7-
MdxSite,
8-
} from "@speakeasy-api/docs-md/compiler";
4+
import { getSettings } from "@speakeasy-api/docs-md";
5+
6+
/**
7+
* @type {import("@speakeasy-api/docs-md").FrameworkConfig}
8+
*/
9+
const framework = {
10+
rendererType: "mdx",
11+
componentPackageName: "@/components/speakeasy-custom",
12+
elementIdSeparator: "_",
913

10-
export class MistralSite extends MdxSite {
1114
buildPagePath(slug) {
1215
const settings = getSettings();
1316
return resolve(join(settings.output.pageOutDir, `${slug}/page.mdx`));
14-
}
17+
},
1518

16-
getRenderer(options) {
17-
return new MistralRenderer({ ...options });
18-
}
19+
buildPagePreamble() {
20+
return `import "@/app/speakeasy.css";`;
21+
},
1922

20-
// This method is called after all pages have been rendered. It contains
21-
// metadata about the pages that were rendered and can be used to construct a
22-
// left navigation sidebar.
23-
processPageMetadata(metadata) {
23+
postProcess(metadata) {
2424
// Note: the format for this data is very much a quick and dirty
2525
// implementation. It's shape will almost certainly change and become easier
2626
// to work with in the future.
2727
writeFileSync(
2828
"./src/components/sidebarMetadata.json",
2929
JSON.stringify(metadata, null, " ")
3030
);
31-
}
32-
}
33-
34-
class MistralRenderer extends MdxRenderer {
35-
constructor(args) {
36-
super(args);
37-
this.insertPackageImport("@/app/speakeasy.css");
38-
}
39-
40-
insertComponentImport(symbol) {
41-
this.insertNamedImport("@/components/speakeasy-custom", symbol);
42-
}
43-
44-
getIdSeparator() {
45-
return "_";
46-
}
47-
}
31+
},
32+
};
4833

4934
export default {
5035
spec: "../../specs/mistral.yaml",
5136
output: {
5237
pageOutDir: "./src/app/api",
53-
framework: "custom",
54-
createSite() {
55-
return new MistralSite();
56-
},
38+
framework,
5739
singlePage: true,
5840
},
5941
display: {

0 commit comments

Comments
 (0)