Skip to content

Commit 3442124

Browse files
committed
IS-11008: simplify folder structure and gitignore
1 parent 4c6bcd3 commit 3442124

10 files changed

Lines changed: 37 additions & 55 deletions

src/haapi-react-sdk/docs/.gitignore

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
/build
66
/.docusaurus
77

8-
# Generated by scripts/build-sandpack-sdk.mjs (npm run docs:gen)
8+
# Generated Sandpack/example data (npm run docs:gen)
99
/src/generated/
10-
/docs/_overview.mdx
1110

12-
# Generated by scripts/split-docs.mjs (npm run docs:split): one short page per `##` section
13-
/docs/overview/
14-
15-
# Generated by scripts/emit-api-reference.mjs (npm run docs:apiref) from api-reference.entries.mjs
16-
/docs/api-reference/
17-
18-
# Generated by scripts/emit-examples.mjs (npm run docs:examples) from examples.entries.mjs
19-
/docs/examples/
11+
# The entire Docusaurus content tree is generated (build-sandpack-sdk → split-docs →
12+
# emit-api-reference → emit-examples) from the SDK README, examples/*.tsx and TSDoc.
13+
/content/

src/haapi-react-sdk/docs/README.md

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# HAAPI React SDK docs
22

3-
Docusaurus site for the HAAPI React SDK. Most content is **generated** from the SDK source, so you rarely
4-
edit pages by hand — you edit the SDK (README + TSDoc) and the example files, and the build assembles the site.
3+
Docusaurus site for the HAAPI React SDK. Almost all content is **generated** from the SDK source: you
4+
edit the SDK (`README.md` + component TSDoc) and the example files, and the build assembles the site.
5+
You rarely touch pages by hand.
56

67
## Run it
78

@@ -11,49 +12,33 @@ npm run docs:build # production build (fails on broken links)
1112
```
1213

1314
Both run the generators first (`predocs`): `docs:gen → docs:split → docs:apiref → docs:examples`.
15+
Everything they emit lands in **`content/`**, which is gitignored — never edit it, change the source.
1416

1517
## Where content comes from
1618

1719
| Sidebar section | Source | How |
1820
|---|---|---|
19-
| **Overview** | SDK `README.md` | `docs:gen``_overview.mdx`, `docs:split` → one page per `##` |
20-
| **API Reference** | component **TSDoc** | `docs:apiref` extracts the TSDoc (`scripts/extract-tsdoc.mjs`) and emits a Markdown page per entry in `api-reference.entries.mjs` |
21+
| **Overview** | SDK `README.md` | `docs:gen``content/_overview.mdx`, `docs:split` → one page per `##` |
22+
| **API Reference** | component **TSDoc** | `docs:apiref` extracts the TSDoc and emits a Markdown page per entry in `api-reference.entries.mjs` |
2123
| **Examples** | `examples/*.tsx` | `docs:examples` emits a playground page per entry in `examples.entries.mjs` |
2224

23-
Generated folders (`docs/_overview.mdx`, `docs/overview/`, `docs/api-reference/`, `docs/examples/`) are
24-
**gitignored** — don't edit them; change the source instead.
25+
## Examples are live playgrounds
2526

26-
## Examples = live playgrounds
27+
Each `examples/<Name>.tsx` is a self-contained app (a default `App` wrapped in `<ExamplePreviewer>`) that
28+
runs **live** in the docs against a mocked HAAPI backend — readers can edit the code and see it update.
2729

28-
An example is a self-contained `examples/<Name>.tsx` (default `App`, wrapped in `<ExamplePreviewer>`).
29-
`docs:gen` bundles every example into `examples.json` (keyed by basename). You reference it by **name**
30-
(its filename, no `.tsx`) in one of two ways — both get rewritten, at generation time, into the same
31-
`<DocExample id="<Name>" />` runtime tag, which looks the source up in `examples.json` by that `id`:
30+
To show an example on a page, reference its file in any of these ways:
3231

33-
- **A markdown link to the file**`[label](…/examples/<Name>.tsx)`, in the SDK `README.md` (→ Overview).
34-
It stays a clickable link on GitHub; the build derives `<Name>` from the link and converts it to a
35-
playground (`build-sandpack-sdk.mjs`).
36-
- **A `{@see_example docs/examples/<Name>.tsx Label}` marker** — inside a component's TSDoc, so the
37-
playground renders inline on its API Reference page (`emit-api-reference.mjs`).
38-
39-
(The Examples section pages are emitted from `examples.entries.mjs`. You don't hand-write `<DocExample>`
40-
it's the generated tag underlying all of these.) Each mounts the example in Sandpack against the **mocked**
41-
HAAPI driver (no backend) using the shared closure in `src/sandpack/closure.ts`.
42-
43-
```
44-
examples/<Name>.tsx ──(docs:gen)──▶ examples.json[<Name>]
45-
46-
├─ [label](…/examples/<Name>.tsx) (README markdown) ─┐
47-
├─ {@see_example …<Name>.tsx Label} (component TSDoc) ─┤─(generate)─▶ <DocExample id="<Name>"/>
48-
└─ entry in examples.entries.mjs (Examples section) ─┘ │
49-
▼ ▼
50-
examples.json[<Name>] ──▶ SandpackPlayer( SDK + mocked driver + <Name>.tsx ) ──▶ live playground
51-
```
32+
- **A markdown link** in the SDK `README.md``[label](…/examples/<Name>.tsx)`. Renders as a playground
33+
on the Overview section, and stays a normal clickable link on GitHub.
34+
- **A `{@see_example docs/examples/<Name>.tsx Label}` marker** in a component's TSDoc — renders the
35+
playground inline on that component's API Reference page.
36+
- **An entry in `examples.entries.mjs`** — gives the example its own page in the Examples section.
5237

5338
## Add an example
5439

5540
1. Create `examples/MyExample.tsx` — a default `App`, wrapped in `<ExamplePreviewer>`.
56-
2. Surface it by **name**: a markdown link `[label](…/examples/MyExample.tsx)` in the README, **or** an
57-
entry in `examples.entries.mjs` (Examples section), **or** a `{@see_example …MyExample.tsx Label}`
58-
marker in a component's TSDoc.
59-
3. `npm run docs` — it's picked up automatically; no registry edit needed for `examples.json`.
41+
2. Reference it one of the three ways above (markdown link, `{@see_example}` marker, or an
42+
`examples.entries.mjs` entry).
43+
3. `npm run docs` — it's picked up automatically.
44+

src/haapi-react-sdk/docs/docusaurus.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const config: Config = {
3838
'classic',
3939
{
4040
docs: {
41+
// `content/` is fully generated (build-sandpack-sdk, split-docs, emit-api-reference,
42+
// emit-examples) — kept out of the default `docs/` to avoid a confusing `docs/docs` nesting.
43+
path: 'content',
4144
routeBasePath: '/',
4245
sidebarPath: './sidebars.ts',
4346
},

src/haapi-react-sdk/docs/api-reference.entries.mjs renamed to src/haapi-react-sdk/docs/scripts/api-reference.entries.mjs

File renamed without changes.

src/haapi-react-sdk/docs/scripts/build-sandpack-sdk.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ const catalogOutFile = join(scriptDir, '../src/generated/catalog.json');
6060
// The SDK's own README, surfaced as the docs landing/first page (as MDX, so `{@see_example}` markers
6161
// can become live `<DocExample>` playgrounds). Front matter is prepended — single source of truth.
6262
const readmeFile = join(sdkRoot, 'README.md');
63-
// Underscore prefix → Docusaurus ignores this long source; `split-docs.mjs` splits it into `docs/overview/`.
64-
const readmeOutFile = join(scriptDir, '../docs/_overview.mdx');
63+
// Underscore prefix → Docusaurus ignores this long source; `split-docs.mjs` splits it into `content/overview/`.
64+
const readmeOutFile = join(scriptDir, '../content/_overview.mdx');
6565

6666
// Every docs example file (examples/*.tsx) as { <basename>: <source> }, so MDX pages (the
6767
// README/overview) can mount any of them as a live playground via `<DocExample id="…">`, and the closure

src/haapi-react-sdk/docs/scripts/emit-api-reference.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
/*
13-
* Generates the API Reference docs tree (`docs/api-reference/**`) from the single layout declaration in
13+
* Generates the API Reference docs tree (`content/api-reference/**`) from the single layout declaration in
1414
* `api-reference.entries.mjs`. Each leaf entry → one MDX page whose body is the export's TSDoc, extracted
1515
* here and written as real Markdown (+ `<DocExample>` playgrounds); each group → a subfolder with its own
1616
* `_category_.json`. `sidebar_position` follows declaration order.
@@ -29,7 +29,7 @@ import { apiReferenceStructure, isApiReferenceGroup } from '../api-reference.ent
2929
import { extractDocBlocks, blocksToMdx, hasExamples } from './extract-tsdoc.mjs';
3030

3131
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
32-
const DOCS_DIR = path.resolve(SCRIPT_DIR, '../docs');
32+
const DOCS_DIR = path.resolve(SCRIPT_DIR, '../content');
3333
const OUT_DIR = path.join(DOCS_DIR, 'api-reference');
3434
// The SDK package root, where entry `file` paths (`haapi-stepper/<file>`) are resolved from.
3535
const SDK_ROOT = path.resolve(SCRIPT_DIR, '../..');
@@ -121,4 +121,4 @@ writeCategory(OUT_DIR, 'API Reference', 2);
121121
const pages = emitItems(apiReferenceStructure, OUT_DIR);
122122

123123
// eslint-disable-next-line no-console
124-
console.log(`[emit-api-reference] wrote ${pages} pages to docs/api-reference/`);
124+
console.log(`[emit-api-reference] wrote ${pages} pages to content/api-reference/`);

src/haapi-react-sdk/docs/scripts/emit-examples.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
/*
13-
* Generates the "Examples" docs section (`docs/examples/**`) from the single layout declaration in
13+
* Generates the "Examples" docs section (`content/examples/**`) from the single layout declaration in
1414
* `examples.entries.mjs`. Each leaf → one short MDX shell that mounts `<DocExample id=…/>` (a live
1515
* Sandpack playground for `examples/<id>.tsx`); each group → a subfolder with its own
1616
* `_category_.json`. `sidebar_position` follows declaration order.
@@ -24,7 +24,7 @@ import path from 'node:path';
2424
import { fileURLToPath } from 'node:url';
2525
import { examplesStructure, isExamplesGroup } from '../examples.entries.mjs';
2626

27-
const DOCS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../docs');
27+
const DOCS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../content');
2828
const OUT_DIR = path.join(DOCS_DIR, 'examples');
2929
const GENERATED_NOTE = '{/* AUTO-GENERATED by scripts/emit-examples.mjs from examples.entries.mjs — do not edit. */}';
3030
const DOC_EXAMPLE_IMPORT = "import DocExample from '@site/src/components/DocExample';";
@@ -75,4 +75,4 @@ writeCategory(OUT_DIR, 'Examples', 3);
7575
const pages = emitItems(examplesStructure, OUT_DIR);
7676

7777
// eslint-disable-next-line no-console
78-
console.log(`[emit-examples] wrote ${pages} pages to docs/examples/`);
78+
console.log(`[emit-examples] wrote ${pages} pages to content/examples/`);
File renamed without changes.

src/haapi-react-sdk/docs/scripts/extract-tsdoc.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* `{@see_example <path> <label>}` markers) — and renders them to MDX: prose verbatim, each marker as a
1616
* `<DocExample id=… />` (resolved at runtime from the generated examples map) in the snippet's place.
1717
*
18-
* `emit-api-reference.mjs` writes the result straight into `docs/api-reference/**`, so the pages are
18+
* `emit-api-reference.mjs` writes the result straight into `content/api-reference/**`, so the pages are
1919
* real Markdown — Docusaurus builds the right-hand table of contents and heading anchors natively.
2020
*/
2121

src/haapi-react-sdk/docs/scripts/split-docs.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import path from 'node:path';
2323
import { fileURLToPath } from 'node:url';
2424
import GithubSlugger from 'github-slugger';
2525

26-
const DOCS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../docs');
26+
const DOCS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../content');
2727
const GENERATED_NOTE = '{/* AUTO-GENERATED by scripts/split-docs.mjs from the sibling _<name>.mdx — do not edit. */}';
2828

2929
/** Split `---\n…\n---` frontmatter off the top → `{ data, body }` (values kept as raw strings). */
@@ -171,5 +171,5 @@ const sources = fs.readdirSync(DOCS_DIR).filter(f => /^_.+\.mdx?$/.test(f));
171171
for (const source of sources) {
172172
const { name, sections } = splitFile(path.join(DOCS_DIR, source));
173173
// eslint-disable-next-line no-console
174-
console.log(`[split-docs] ${source}docs/${name}/ (index + ${sections} sections)`);
174+
console.log(`[split-docs] ${source}content/${name}/ (index + ${sections} sections)`);
175175
}

0 commit comments

Comments
 (0)