@canonical/summon-application 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -13
- package/dist/esm/application/react/index.js +347 -0
- package/dist/esm/application/react/index.js.map +1 -0
- package/dist/esm/application/react/templates/.browserslistrc +2 -0
- package/dist/esm/application/react/templates/.storybook/main.ts.ejs +10 -0
- package/{src → dist/esm}/application/react/templates/README.md.ejs +54 -0
- package/dist/esm/application/react/templates/biome.json.ejs +6 -0
- package/dist/esm/application/react/templates/gitignore +25 -0
- package/{src → dist/esm}/application/react/templates/package.json.ejs +36 -2
- package/dist/esm/application/react/templates/patches/react-relay@18.2.0.patch +52 -0
- package/dist/esm/application/react/templates/patches/relay-runtime-network@0.1.0.patch +46 -0
- package/dist/esm/application/react/templates/relay.config.json +8 -0
- package/{src/application/react/templates/src/client/entry.tsx → dist/esm/application/react/templates/src/client/entry.tsx.ejs} +23 -0
- package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx +50 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tests.tsx +56 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tsx +37 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx +49 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ProductList.stories.tsx +103 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tests.tsx +80 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tsx +59 -0
- package/dist/esm/application/react/templates/src/domains/catalog/routes.ts +11 -0
- package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tests.tsx +35 -0
- package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tsx +31 -0
- package/dist/esm/application/react/templates/src/lib/ClientOnly/index.ts +1 -0
- package/{src → dist/esm}/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +3 -0
- package/{src/application/react/templates/src/lib/index.ts → dist/esm/application/react/templates/src/lib/index.ts.ejs} +3 -0
- package/dist/esm/application/react/templates/src/relay/__generated__/ProductCard_product.graphql.ts +82 -0
- package/dist/esm/application/react/templates/src/relay/__generated__/ProductListQuery.graphql.ts +272 -0
- package/dist/esm/application/react/templates/src/relay/environment.tests.ts +87 -0
- package/dist/esm/application/react/templates/src/relay/environment.ts +119 -0
- package/dist/esm/application/react/templates/src/relay/schema.graphql +111 -0
- package/dist/esm/application/react/templates/src/relay/schema.tests.ts +137 -0
- package/dist/esm/application/react/templates/src/relay/schema.ts +205 -0
- package/{src → dist/esm}/application/react/templates/src/routes.tsx.ejs +10 -0
- package/{src/application/react/templates/src/server/entry.tsx → dist/esm/application/react/templates/src/server/entry.tsx.ejs} +36 -0
- package/{src → dist/esm}/application/react/templates/src/sitemap/getSitemapItems.ts.ejs +3 -0
- package/{src/application/react/templates/tsconfig.json → dist/esm/application/react/templates/tsconfig.json.ejs} +3 -0
- package/dist/esm/application/react/templates/vite.config.ts.ejs +92 -0
- package/dist/esm/application/react/templates/vitest.setup.ts.ejs +22 -0
- package/dist/esm/domain/index.js +89 -0
- package/dist/esm/domain/index.js.map +1 -0
- package/{src/index.ts → dist/esm/index.js} +6 -8
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/route/index.js +115 -0
- package/dist/esm/route/index.js.map +1 -0
- package/dist/esm/route/insertRoute.js +178 -0
- package/dist/esm/route/insertRoute.js.map +1 -0
- package/dist/esm/shared/casing.js +15 -0
- package/dist/esm/shared/casing.js.map +1 -0
- package/dist/esm/shared/packageManager.js +38 -0
- package/dist/esm/shared/packageManager.js.map +1 -0
- package/dist/esm/shared/versions.js +88 -0
- package/dist/esm/shared/versions.js.map +1 -0
- package/dist/esm/wrapper/index.js +72 -0
- package/dist/esm/wrapper/index.js.map +1 -0
- package/dist/types/application/react/index.d.ts +12 -0
- package/dist/types/application/react/index.d.ts.map +1 -0
- package/dist/types/domain/index.d.ts +7 -0
- package/dist/types/domain/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/route/index.d.ts +7 -0
- package/dist/types/route/index.d.ts.map +1 -0
- package/dist/types/route/insertRoute.d.ts +34 -0
- package/dist/types/route/insertRoute.d.ts.map +1 -0
- package/{src/shared/casing.ts → dist/types/shared/casing.d.ts} +2 -7
- package/dist/types/shared/casing.d.ts.map +1 -0
- package/dist/types/shared/packageManager.d.ts +19 -0
- package/dist/types/shared/packageManager.d.ts.map +1 -0
- package/dist/types/shared/versions.d.ts +15 -0
- package/dist/types/shared/versions.d.ts.map +1 -0
- package/dist/types/wrapper/index.d.ts +7 -0
- package/dist/types/wrapper/index.d.ts.map +1 -0
- package/package.json +16 -15
- package/src/application/react/index.ts +0 -294
- package/src/application/react/templates/.storybook/main.ts +0 -5
- package/src/application/react/templates/biome.json.ejs +0 -6
- package/src/application/react/templates/vite.config.ts +0 -45
- package/src/application/react/templates/vitest.setup.ts +0 -9
- package/src/domain/index.ts +0 -119
- package/src/index.test.ts +0 -398
- package/src/route/index.ts +0 -154
- package/src/route/insertRoute.test.ts +0 -98
- package/src/route/insertRoute.ts +0 -236
- package/src/shared/versions.ts +0 -48
- package/src/wrapper/index.ts +0 -100
- /package/{src → dist/esm}/application/react/templates/.storybook/decorators/index.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/.storybook/decorators/withRouter.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/.storybook/preview.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/index.html.ejs +0 -0
- /package/{src → dist/esm}/application/react/templates/public/.gitkeep +0 -0
- /package/{src → dist/esm}/application/react/templates/public/robots.txt +0 -0
- /package/{src → dist/esm}/application/react/templates/src/assets/.gitkeep +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/account/AccountPage.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/account/LoginPage.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/account/routes.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/contact/ContactPage.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/contact/routes.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/marketing/GuidePage.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/marketing/HomePage.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/domains/marketing/routes.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.stories.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tests.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/index.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/styles.css +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/types.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.stories.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/index.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/Navigation/index.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/index.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/server/preview.bun.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/server/preview.express.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/server/renderer.tsx +0 -0
- /package/{src → dist/esm}/application/react/templates/src/server/server.bun.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/server/server.express.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/sitemap/renderer.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/src/styles/app.css +0 -0
- /package/{src → dist/esm}/application/react/templates/src/styles/index.css.ejs +0 -0
- /package/{src → dist/esm}/application/react/templates/src/vite-env.d.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/test/e2e/serverHarness.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/test/e2e/servers.e2e.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/vitest.config.ts +0 -0
- /package/{src → dist/esm}/application/react/templates/vitest.e2e.config.ts +0 -0
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Scaffolds a complete React application with SSR, routing, Storybook, and two sta
|
|
|
11
11
|
```bash
|
|
12
12
|
summon application/react my-app
|
|
13
13
|
summon application/react --forms my-app
|
|
14
|
+
summon application/react --relay my-app
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
Produces:
|
|
@@ -23,6 +24,7 @@ my-app/
|
|
|
23
24
|
│ └── decorators/
|
|
24
25
|
│ ├── withRouter.tsx # Hash-based router decorator
|
|
25
26
|
│ └── index.ts
|
|
27
|
+
├── patches/ # bun dependency patches (--relay only)
|
|
26
28
|
├── src/
|
|
27
29
|
│ ├── client/entry.tsx # Client hydration
|
|
28
30
|
│ ├── server/
|
|
@@ -33,24 +35,73 @@ my-app/
|
|
|
33
35
|
│ ├── domains/
|
|
34
36
|
│ │ ├── marketing/ # HomePage, GuidePage, routes
|
|
35
37
|
│ │ ├── account/ # AccountPage, LoginPage, routes
|
|
36
|
-
│ │
|
|
38
|
+
│ │ ├── contact/ # ContactPage, routes (--forms only)
|
|
39
|
+
│ │ └── catalog/ # CatalogPage, ProductList, ProductCard (--relay only)
|
|
37
40
|
│ ├── lib/
|
|
38
41
|
│ │ ├── Navigation/
|
|
39
42
|
│ │ ├── ThemeSelector/
|
|
40
43
|
│ │ ├── ExampleComponent/
|
|
41
|
-
│ │
|
|
44
|
+
│ │ ├── LazyComponent/
|
|
45
|
+
│ │ └── ClientOnly/ # SSR query guard (--relay only)
|
|
46
|
+
│ ├── relay/ # Environment factory, mock schema, __generated__ (--relay only)
|
|
42
47
|
│ ├── styles/
|
|
43
48
|
│ ├── routes.tsx
|
|
44
49
|
│ └── vite-env.d.ts
|
|
45
50
|
├── biome.json
|
|
46
51
|
├── index.html
|
|
47
52
|
├── package.json
|
|
53
|
+
├── relay.config.json # (--relay only)
|
|
48
54
|
├── tsconfig.json
|
|
49
55
|
└── vite.config.ts
|
|
50
56
|
```
|
|
51
57
|
|
|
52
58
|
The `--forms` flag adds the contact domain with form components and wires `contactRoutes` into `routes.tsx`.
|
|
53
59
|
|
|
60
|
+
#### `--relay`: Relay (GraphQL) data layer
|
|
61
|
+
|
|
62
|
+
The `--relay` flag (off by default) mirrors the boilerplate's Relay data layer:
|
|
63
|
+
|
|
64
|
+
- **`src/relay/`** — a `createEnvironment` factory built on
|
|
65
|
+
`relay-runtime-network`'s middleware pipeline: by default a local executor
|
|
66
|
+
resolves every operation in-process against the executable mock catalog
|
|
67
|
+
schema (`schema.graphql` + `schema.ts`), so the app runs with zero backend;
|
|
68
|
+
setting `VITE_GRAPHQL_URL` (or passing `graphqlUrl`) switches to posting
|
|
69
|
+
operations to a real endpoint. The relay-compiler artifacts in
|
|
70
|
+
`src/relay/__generated__/` are committed — deterministic outputs of the
|
|
71
|
+
committed schema — and regenerated with `bun run relay` (or `relay:watch`)
|
|
72
|
+
after any schema or `graphql` tag edit.
|
|
73
|
+
- **`src/domains/catalog/`** — an example domain wiring `useLazyLoadQuery`
|
|
74
|
+
(`ProductList`) and a colocated `useFragment` (`ProductCard`) behind the
|
|
75
|
+
canonical Suspense + `ErrorBoundary` pairing, with Storybook stories mocked
|
|
76
|
+
via `@canonical/storybook-addon-relay` (`parameters.relay` mock resolvers +
|
|
77
|
+
play tests) and component tests against both the local schema and
|
|
78
|
+
`relay-test-utils`.
|
|
79
|
+
- **`src/lib/ClientOnly/`** — keeps queries off the server render path until
|
|
80
|
+
SSR data serialization/hydration is supported: the server streams the
|
|
81
|
+
fallback and the browser fetches after hydration. It is emitted only with
|
|
82
|
+
`--relay` because the catalog page is its only consumer today.
|
|
83
|
+
- **`patches/` + `"patchedDependencies"`** — a generated app is standalone and
|
|
84
|
+
cannot inherit the monorepo's `patches/`, so the two bun patches ship with
|
|
85
|
+
the scaffold: `react-relay@18.2.0` (cjs-module-lexer export hints so named
|
|
86
|
+
imports survive Node SSR externalisation) and `relay-runtime-network@0.1.0`
|
|
87
|
+
(fixes its broken package `imports` map — temporary until the fixed
|
|
88
|
+
upstream release lands, advl/lit-relay#32, after which the patch and its
|
|
89
|
+
`patchedDependencies` entry can be dropped).
|
|
90
|
+
- **Wiring** — `RelayEnvironmentProvider` in both entries (one environment
|
|
91
|
+
per browser session on the client, a fresh one per request on the server),
|
|
92
|
+
`vite-plugin-relay-lite` in `vite.config.ts` (`codegen: false`; artifacts
|
|
93
|
+
are committed), the `relay` / `relay:watch` scripts, catalog route, nav
|
|
94
|
+
link, and sitemap entries, and the relay addon via `extraAddons` in
|
|
95
|
+
`.storybook/main.ts`.
|
|
96
|
+
|
|
97
|
+
**Known caveats — not yet on npm.** `@canonical/storybook-addon-relay` and
|
|
98
|
+
the fixed `relay-runtime-network` release have not been published yet. A
|
|
99
|
+
scaffolded app's install currently fails to resolve
|
|
100
|
+
`@canonical/storybook-addon-relay` (404 from the registry), and the
|
|
101
|
+
`relay-runtime-network` patch remains necessary until the fixed upstream
|
|
102
|
+
release lands. The scaffold encodes the intended end state; a `--relay` app's
|
|
103
|
+
install will only fully resolve once those packages publish.
|
|
104
|
+
|
|
54
105
|
### `summon domain <name>`
|
|
55
106
|
|
|
56
107
|
Creates a domain folder under `src/domains/` with a `MainPage` and a `routes.ts` barrel.
|
|
@@ -145,12 +196,23 @@ src/
|
|
|
145
196
|
│ │ ├── AccountPage.tsx
|
|
146
197
|
│ │ ├── LoginPage.tsx
|
|
147
198
|
│ │ └── routes.ts
|
|
148
|
-
│
|
|
149
|
-
│
|
|
199
|
+
│ ├── contact/ # When --forms is enabled
|
|
200
|
+
│ │ ├── ContactPage.tsx
|
|
201
|
+
│ │ └── routes.ts
|
|
202
|
+
│ └── catalog/ # When --relay is enabled
|
|
203
|
+
│ ├── CatalogPage.tsx
|
|
204
|
+
│ ├── ProductList.tsx
|
|
205
|
+
│ ├── ProductCard.tsx
|
|
206
|
+
│ ├── ErrorBoundary.tsx
|
|
150
207
|
│ └── routes.ts
|
|
151
208
|
├── lib/ # Shared components
|
|
152
209
|
│ ├── Navigation/
|
|
153
210
|
│ └── SidebarLayout/
|
|
211
|
+
├── relay/ # When --relay is enabled
|
|
212
|
+
│ ├── environment.ts # Environment factory (local executor / HTTP)
|
|
213
|
+
│ ├── schema.graphql # Mock SDL (relay-compiler validates against it)
|
|
214
|
+
│ ├── schema.ts # Executable mock schema (graphql-js)
|
|
215
|
+
│ └── __generated__/ # Committed relay-compiler artifacts
|
|
154
216
|
├── styles/ # CSS
|
|
155
217
|
└── routes.tsx # Root route map, middleware, type registration
|
|
156
218
|
```
|
|
@@ -244,15 +306,15 @@ This enables typed `<Link to="invoices">`, `router.navigate("invoices")`, and `r
|
|
|
244
306
|
|
|
245
307
|
Design decisions about the generated output that are not yet settled:
|
|
246
308
|
|
|
247
|
-
- **Pinned pragma version is
|
|
248
|
-
workspace packages (`react-ds-global`, `router-core`, `styles`, …) at
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
309
|
+
- **Pinned pragma version is fetched at summon time.** Generated apps pin the pragma
|
|
310
|
+
workspace packages (`react-ds-global`, `router-core`, `styles`, …) at `^<latest>`, where
|
|
311
|
+
`<latest>` is queried from the npm registry when the app is scaffolded
|
|
312
|
+
(`resolvePragmaVersion` in `src/shared/versions.ts`, via `npm view`). If the registry is
|
|
313
|
+
unreachable it falls back to `^<installed generator version>` — safe because
|
|
314
|
+
`@canonical/summon-application` is released in lockstep with those packages. Note
|
|
315
|
+
`@canonical/design-tokens` is versioned separately and is *not* covered here (it arrives
|
|
316
|
+
transitively via `@canonical/styles`). **Open:** whether to cache the lookup or let users
|
|
317
|
+
pin explicitly for reproducible offline scaffolding.
|
|
256
318
|
|
|
257
319
|
- **Two static-asset folders (`src/assets/` + `public/`).** The generated app ships both,
|
|
258
320
|
and `.storybook/main.ts` lists `staticDirs: ["../src/assets", "../public"]` to match the
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { template, withHelpers } from "@canonical/summon-core";
|
|
4
|
+
import { copyFile, exec, exists, flatMap, info, pure, sequence_, warn, when, } from "@canonical/task";
|
|
5
|
+
import { pickPackageManager } from "../../shared/packageManager.js";
|
|
6
|
+
import { resolvePragmaVersion } from "../../shared/versions.js";
|
|
7
|
+
const prompts = [
|
|
8
|
+
{
|
|
9
|
+
name: "appPath",
|
|
10
|
+
type: "text",
|
|
11
|
+
message: "Application directory name:",
|
|
12
|
+
default: "my-app",
|
|
13
|
+
positional: true,
|
|
14
|
+
group: "Application",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "ssr",
|
|
18
|
+
type: "confirm",
|
|
19
|
+
message: "Include SSR?",
|
|
20
|
+
default: true,
|
|
21
|
+
group: "Application",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "router",
|
|
25
|
+
type: "confirm",
|
|
26
|
+
message: "Include router?",
|
|
27
|
+
default: true,
|
|
28
|
+
group: "Application",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "forms",
|
|
32
|
+
type: "confirm",
|
|
33
|
+
message: "Include form components?",
|
|
34
|
+
default: true,
|
|
35
|
+
group: "Application",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "relay",
|
|
39
|
+
type: "confirm",
|
|
40
|
+
message: "Include a Relay (GraphQL) data layer with a local mock schema?",
|
|
41
|
+
default: false,
|
|
42
|
+
group: "Application",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "runInstall",
|
|
46
|
+
type: "confirm",
|
|
47
|
+
message: "Install dependencies now?",
|
|
48
|
+
default: true,
|
|
49
|
+
group: "Application",
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
53
|
+
const templatesDir = path.join(__dirname, "templates");
|
|
54
|
+
/** Resolve a path inside the templates directory. */
|
|
55
|
+
const src = (templatePath) => path.join(templatesDir, templatePath);
|
|
56
|
+
export const generator = {
|
|
57
|
+
meta: {
|
|
58
|
+
name: "application/react",
|
|
59
|
+
displayName: "@canonical/summon-application:application/react",
|
|
60
|
+
description: "Scaffold a complete React application with SSR and routing",
|
|
61
|
+
version: "0.1.0",
|
|
62
|
+
help: `Creates a full React application with:
|
|
63
|
+
- Vite build + dev server
|
|
64
|
+
- Server-side rendering (Express + Bun dev servers)
|
|
65
|
+
- Routing with @canonical/router-core
|
|
66
|
+
- Head management with @canonical/react-head
|
|
67
|
+
- Two domains (marketing + account) with pages
|
|
68
|
+
- Contact domain with form components (when --forms is enabled)
|
|
69
|
+
- Relay (GraphQL) data layer with a local mock schema, catalog example
|
|
70
|
+
domain, and Storybook mocking (when --relay is enabled)
|
|
71
|
+
- Navigation, ThemeSelector, ExampleComponent
|
|
72
|
+
- Storybook with router decorator
|
|
73
|
+
- Biome + TypeScript configuration
|
|
74
|
+
|
|
75
|
+
Requires both --ssr and --router flags.`,
|
|
76
|
+
examples: [
|
|
77
|
+
"summon application/react my-app",
|
|
78
|
+
"summon application/react --forms my-app",
|
|
79
|
+
"summon application/react --relay my-app",
|
|
80
|
+
"summon application/react --ssr --router --forms --relay my-app",
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
prompts,
|
|
84
|
+
generate: (answers) => {
|
|
85
|
+
if (!answers.ssr || !answers.router) {
|
|
86
|
+
throw new Error("The application/react generator requires both --ssr and --router. " +
|
|
87
|
+
"Standalone SPA mode is not supported.");
|
|
88
|
+
}
|
|
89
|
+
// The app path is a directory path, not a route path — keep it as given
|
|
90
|
+
// (absolute or relative), only trimming surrounding whitespace and any
|
|
91
|
+
// trailing slash.
|
|
92
|
+
const appPath = (answers.appPath || "my-app").trim().replace(/\/+$/, "") || "my-app";
|
|
93
|
+
// The package name is the final path segment. For "." / "" / "/" (scaffold
|
|
94
|
+
// into the current dir) basename gives "."/"" — resolve against the real
|
|
95
|
+
// directory so the name is the actual folder name. Then slugify to an
|
|
96
|
+
// npm-safe form (lowercase, safe chars).
|
|
97
|
+
const rawName = path.basename(path.resolve(appPath));
|
|
98
|
+
const name = rawName
|
|
99
|
+
.toLowerCase()
|
|
100
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
101
|
+
.replace(/^[._-]+|[._-]+$/g, "");
|
|
102
|
+
if (!name) {
|
|
103
|
+
throw new Error(`Could not derive a valid application name from path "${appPath}". ` +
|
|
104
|
+
"Pass an explicit directory name (lowercase letters/digits).");
|
|
105
|
+
}
|
|
106
|
+
const dest = (...segments) => path.join(appPath, ...segments);
|
|
107
|
+
const copy = (filePath) => copyFile(src(filePath), dest(filePath));
|
|
108
|
+
// Resolve the @canonical/* version range first (latest from npm, with an
|
|
109
|
+
// offline fallback), then build the rest of the pipeline with it baked into
|
|
110
|
+
// the template vars.
|
|
111
|
+
return flatMap(resolvePragmaVersion(), (pragmaVersion) => {
|
|
112
|
+
const vars = withHelpers({
|
|
113
|
+
name,
|
|
114
|
+
forms: answers.forms,
|
|
115
|
+
relay: answers.relay,
|
|
116
|
+
pragmaVersion,
|
|
117
|
+
});
|
|
118
|
+
// Detect an available package manager for both the (optional) install
|
|
119
|
+
// step and the closing message, so the suggested commands reflect what's
|
|
120
|
+
// actually on the machine.
|
|
121
|
+
const pm = pickPackageManager();
|
|
122
|
+
// Build the install task only when a package manager was actually found —
|
|
123
|
+
// this narrows `pm` to non-null, so the install command never invents a
|
|
124
|
+
// manager. `null` when we won't (or can't) install.
|
|
125
|
+
const installTask = answers.runInstall && pm !== null
|
|
126
|
+
? sequence_([
|
|
127
|
+
info(`Installing dependencies with ${pm}...`),
|
|
128
|
+
exec(pm, ["install"], appPath),
|
|
129
|
+
])
|
|
130
|
+
: null;
|
|
131
|
+
// The closing command only names a package manager we actually found; if
|
|
132
|
+
// none was detected we don't invent one (previously this suggested `bun`
|
|
133
|
+
// even on a machine without bun), and instead point the user at the
|
|
134
|
+
// package-manager step.
|
|
135
|
+
const finalMessage = installTask
|
|
136
|
+
? `Application "${appPath}" created. Run \`cd ${appPath} && ${pm} run dev\` to start.`
|
|
137
|
+
: pm
|
|
138
|
+
? `Application "${appPath}" created. Run \`cd ${appPath} && ${pm} install && ${pm} run dev\` to start.`
|
|
139
|
+
: `Application "${appPath}" created. Install a package manager (bun, pnpm, npm, or yarn), then run \`cd ${appPath} && <pm> install && <pm> run dev\` to start.`;
|
|
140
|
+
return sequence_([
|
|
141
|
+
// Warn (don't block) if the destination already exists — scaffolding
|
|
142
|
+
// will overwrite files in place.
|
|
143
|
+
flatMap(exists(appPath), (present) => when(present, warn(`"${appPath}" already exists — existing files may be overwritten.`))),
|
|
144
|
+
info(`Scaffolding React application in "${appPath}"...`),
|
|
145
|
+
// EJS templates (files needing interpolation)
|
|
146
|
+
template({
|
|
147
|
+
source: src("package.json.ejs"),
|
|
148
|
+
dest: dest("package.json"),
|
|
149
|
+
vars,
|
|
150
|
+
}),
|
|
151
|
+
template({
|
|
152
|
+
source: src("README.md.ejs"),
|
|
153
|
+
dest: dest("README.md"),
|
|
154
|
+
vars,
|
|
155
|
+
}),
|
|
156
|
+
template({
|
|
157
|
+
source: src("biome.json.ejs"),
|
|
158
|
+
dest: dest("biome.json"),
|
|
159
|
+
vars,
|
|
160
|
+
}),
|
|
161
|
+
// Root config
|
|
162
|
+
// tsconfig (EJS — #relay path alias only when --relay)
|
|
163
|
+
template({
|
|
164
|
+
source: src("tsconfig.json.ejs"),
|
|
165
|
+
dest: dest("tsconfig.json"),
|
|
166
|
+
vars,
|
|
167
|
+
}),
|
|
168
|
+
// vite config (EJS — vite-plugin-relay-lite only when --relay)
|
|
169
|
+
template({
|
|
170
|
+
source: src("vite.config.ts.ejs"),
|
|
171
|
+
dest: dest("vite.config.ts"),
|
|
172
|
+
vars,
|
|
173
|
+
}),
|
|
174
|
+
copy("vitest.config.ts"),
|
|
175
|
+
// vitest setup (EJS — relay-test-utils' jest→vi alias only when --relay)
|
|
176
|
+
template({
|
|
177
|
+
source: src("vitest.setup.ts.ejs"),
|
|
178
|
+
dest: dest("vitest.setup.ts"),
|
|
179
|
+
vars,
|
|
180
|
+
}),
|
|
181
|
+
copy("vitest.e2e.config.ts"),
|
|
182
|
+
// Relay compiler config (validates queries against the mock SDL)
|
|
183
|
+
when(answers.relay, copy("relay.config.json")),
|
|
184
|
+
// index.html (EJS — <title> uses the app name)
|
|
185
|
+
template({
|
|
186
|
+
source: src("index.html.ejs"),
|
|
187
|
+
dest: dest("index.html"),
|
|
188
|
+
vars,
|
|
189
|
+
}),
|
|
190
|
+
// The template is stored as `gitignore` (no leading dot): npm strips a
|
|
191
|
+
// literal `.gitignore` from published tarballs, so we ship it dotless and
|
|
192
|
+
// restore the dot at write time.
|
|
193
|
+
copyFile(src("gitignore"), dest(".gitignore")),
|
|
194
|
+
// The app's browser floor, read by vite.config.ts to derive Lightning
|
|
195
|
+
// CSS targets. Unlike `.gitignore` above, npm does not strip
|
|
196
|
+
// `.browserslistrc` from tarballs, so the template keeps its dot.
|
|
197
|
+
copy(".browserslistrc"),
|
|
198
|
+
// E2e tests (the 2×3 server matrix + its spawn/teardown harness)
|
|
199
|
+
copy("test/e2e/serverHarness.ts"),
|
|
200
|
+
copy("test/e2e/servers.e2e.ts"),
|
|
201
|
+
// Styles
|
|
202
|
+
// styles (EJS — form stylesheet imported only when --forms)
|
|
203
|
+
template({
|
|
204
|
+
source: src("src/styles/index.css.ejs"),
|
|
205
|
+
dest: dest("src/styles/index.css"),
|
|
206
|
+
vars,
|
|
207
|
+
}),
|
|
208
|
+
copy("src/styles/app.css"),
|
|
209
|
+
// Client (EJS — RelayEnvironmentProvider only when --relay)
|
|
210
|
+
template({
|
|
211
|
+
source: src("src/client/entry.tsx.ejs"),
|
|
212
|
+
dest: dest("src/client/entry.tsx"),
|
|
213
|
+
vars,
|
|
214
|
+
}),
|
|
215
|
+
// Server — dev (Vite + HMR) and preview (compiled) servers each route
|
|
216
|
+
// between the app + sitemap renderers; the renderers stay routing-agnostic.
|
|
217
|
+
// Server entry (EJS — a per-request RelayEnvironmentProvider only when --relay)
|
|
218
|
+
template({
|
|
219
|
+
source: src("src/server/entry.tsx.ejs"),
|
|
220
|
+
dest: dest("src/server/entry.tsx"),
|
|
221
|
+
vars,
|
|
222
|
+
}),
|
|
223
|
+
copy("src/server/renderer.tsx"),
|
|
224
|
+
copy("src/server/server.express.ts"),
|
|
225
|
+
copy("src/server/server.bun.ts"),
|
|
226
|
+
copy("src/server/preview.express.ts"),
|
|
227
|
+
copy("src/server/preview.bun.ts"),
|
|
228
|
+
// Sitemap (rendered route at /sitemap.xml)
|
|
229
|
+
copy("src/sitemap/renderer.ts"),
|
|
230
|
+
// sitemap getters (EJS — /contact entry only when --forms, /catalog
|
|
231
|
+
// entry only when --relay)
|
|
232
|
+
template({
|
|
233
|
+
source: src("src/sitemap/getSitemapItems.ts.ejs"),
|
|
234
|
+
dest: dest("src/sitemap/getSitemapItems.ts"),
|
|
235
|
+
vars,
|
|
236
|
+
}),
|
|
237
|
+
// Domain: marketing
|
|
238
|
+
copy("src/domains/marketing/HomePage.tsx"),
|
|
239
|
+
copy("src/domains/marketing/GuidePage.tsx"),
|
|
240
|
+
copy("src/domains/marketing/routes.ts"),
|
|
241
|
+
// Domain: account
|
|
242
|
+
copy("src/domains/account/AccountPage.tsx"),
|
|
243
|
+
copy("src/domains/account/LoginPage.tsx"),
|
|
244
|
+
copy("src/domains/account/routes.ts"),
|
|
245
|
+
// Domain: contact (when --forms is enabled)
|
|
246
|
+
when(answers.forms, copy("src/domains/contact/ContactPage.tsx")),
|
|
247
|
+
when(answers.forms, copy("src/domains/contact/routes.ts")),
|
|
248
|
+
// Relay data layer (when --relay is enabled): environment factory +
|
|
249
|
+
// executable mock schema, the catalog example domain, and the
|
|
250
|
+
// ClientOnly SSR guard (whose only consumer today is the catalog page).
|
|
251
|
+
when(answers.relay, copy("src/relay/schema.graphql")),
|
|
252
|
+
when(answers.relay, copy("src/relay/schema.ts")),
|
|
253
|
+
when(answers.relay, copy("src/relay/schema.tests.ts")),
|
|
254
|
+
when(answers.relay, copy("src/relay/environment.ts")),
|
|
255
|
+
when(answers.relay, copy("src/relay/environment.tests.ts")),
|
|
256
|
+
// Committed relay-compiler artifacts — deterministic outputs of the
|
|
257
|
+
// committed schema + the catalog queries; `bun run relay` regenerates
|
|
258
|
+
// them in the scaffolded app after any schema or graphql-tag edit.
|
|
259
|
+
when(answers.relay, copy("src/relay/__generated__/ProductCard_product.graphql.ts")),
|
|
260
|
+
when(answers.relay, copy("src/relay/__generated__/ProductListQuery.graphql.ts")),
|
|
261
|
+
// Domain: catalog (when --relay is enabled)
|
|
262
|
+
when(answers.relay, copy("src/domains/catalog/CatalogPage.tsx")),
|
|
263
|
+
when(answers.relay, copy("src/domains/catalog/ProductList.tsx")),
|
|
264
|
+
when(answers.relay, copy("src/domains/catalog/ProductList.stories.tsx")),
|
|
265
|
+
when(answers.relay, copy("src/domains/catalog/ProductList.tests.tsx")),
|
|
266
|
+
when(answers.relay, copy("src/domains/catalog/ProductCard.tsx")),
|
|
267
|
+
when(answers.relay, copy("src/domains/catalog/ErrorBoundary.tsx")),
|
|
268
|
+
when(answers.relay, copy("src/domains/catalog/ErrorBoundary.tests.tsx")),
|
|
269
|
+
when(answers.relay, copy("src/domains/catalog/routes.ts")),
|
|
270
|
+
// Standalone dependency patches (when --relay is enabled): a generated
|
|
271
|
+
// app cannot inherit the monorepo's patches/, so they ship with the
|
|
272
|
+
// scaffold and are applied via "patchedDependencies" in package.json.
|
|
273
|
+
// react-relay: cjs-module-lexer export hints so named imports survive
|
|
274
|
+
// Node SSR externalisation.
|
|
275
|
+
when(answers.relay, copy("patches/react-relay@18.2.0.patch")),
|
|
276
|
+
// relay-runtime-network: fixes the broken package `imports` map.
|
|
277
|
+
// Temporary until the fixed upstream release lands (advl/lit-relay#32);
|
|
278
|
+
// then this patch and its patchedDependencies entry can be dropped.
|
|
279
|
+
when(answers.relay, copy("patches/relay-runtime-network@0.1.0.patch")),
|
|
280
|
+
// Routes (EJS — conditionally includes contact + catalog domains)
|
|
281
|
+
template({
|
|
282
|
+
source: src("src/routes.tsx.ejs"),
|
|
283
|
+
dest: dest("src/routes.tsx"),
|
|
284
|
+
vars,
|
|
285
|
+
}),
|
|
286
|
+
// Lib: Navigation (EJS — contact link only when --forms, catalog
|
|
287
|
+
// link only when --relay)
|
|
288
|
+
template({
|
|
289
|
+
source: src("src/lib/Navigation/Navigation.tsx.ejs"),
|
|
290
|
+
dest: dest("src/lib/Navigation/Navigation.tsx"),
|
|
291
|
+
vars,
|
|
292
|
+
}),
|
|
293
|
+
copy("src/lib/Navigation/index.ts"),
|
|
294
|
+
// Lib: ThemeSelector
|
|
295
|
+
copy("src/lib/ThemeSelector/ThemeSelector.tsx"),
|
|
296
|
+
copy("src/lib/ThemeSelector/index.ts"),
|
|
297
|
+
// Lib: ExampleComponent
|
|
298
|
+
copy("src/lib/ExampleComponent/ExampleComponent.tsx"),
|
|
299
|
+
copy("src/lib/ExampleComponent/ExampleComponent.stories.tsx"),
|
|
300
|
+
copy("src/lib/ExampleComponent/ExampleComponent.tests.tsx"),
|
|
301
|
+
copy("src/lib/ExampleComponent/index.ts"),
|
|
302
|
+
copy("src/lib/ExampleComponent/types.ts"),
|
|
303
|
+
copy("src/lib/ExampleComponent/styles.css"),
|
|
304
|
+
// Lib: LazyComponent
|
|
305
|
+
copy("src/lib/LazyComponent/LazyComponent.tsx"),
|
|
306
|
+
copy("src/lib/LazyComponent/LazyComponent.stories.tsx"),
|
|
307
|
+
copy("src/lib/LazyComponent/index.ts"),
|
|
308
|
+
// Lib: ClientOnly (when --relay is enabled — the catalog page is its
|
|
309
|
+
// only consumer, keeping Relay queries off the server render until
|
|
310
|
+
// SSR data serialization/hydration is supported)
|
|
311
|
+
when(answers.relay, copy("src/lib/ClientOnly/ClientOnly.tsx")),
|
|
312
|
+
when(answers.relay, copy("src/lib/ClientOnly/ClientOnly.tests.tsx")),
|
|
313
|
+
when(answers.relay, copy("src/lib/ClientOnly/index.ts")),
|
|
314
|
+
// Lib barrel (EJS — ClientOnly export only when --relay)
|
|
315
|
+
template({
|
|
316
|
+
source: src("src/lib/index.ts.ejs"),
|
|
317
|
+
dest: dest("src/lib/index.ts"),
|
|
318
|
+
vars,
|
|
319
|
+
}),
|
|
320
|
+
// Vite types
|
|
321
|
+
copy("src/vite-env.d.ts"),
|
|
322
|
+
// Storybook
|
|
323
|
+
// main config (EJS — the relay mocking addon only when --relay)
|
|
324
|
+
template({
|
|
325
|
+
source: src(".storybook/main.ts.ejs"),
|
|
326
|
+
dest: dest(".storybook/main.ts"),
|
|
327
|
+
vars,
|
|
328
|
+
}),
|
|
329
|
+
copy(".storybook/preview.ts"),
|
|
330
|
+
copy(".storybook/decorators/withRouter.tsx"),
|
|
331
|
+
copy(".storybook/decorators/index.ts"),
|
|
332
|
+
// Static asset dirs (kept by placeholder; both wired into Storybook staticDirs)
|
|
333
|
+
copy("src/assets/.gitkeep"),
|
|
334
|
+
copy("public/.gitkeep"),
|
|
335
|
+
copy("public/robots.txt"),
|
|
336
|
+
// Install dependencies with the detected package manager, or a no-op
|
|
337
|
+
// when none was found / the user declined. Built above where `pm` is
|
|
338
|
+
// narrowed to non-null, so the install command never invents a manager;
|
|
339
|
+
// the scaffold completes and the closing message says what to run.
|
|
340
|
+
installTask ?? pure(undefined),
|
|
341
|
+
info(finalMessage),
|
|
342
|
+
]);
|
|
343
|
+
});
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
export default generator;
|
|
347
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/application/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKzC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,IAAI,GACL,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAWhE,MAAM,OAAO,GAAuB;IAClC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,6BAA6B;QACtC,OAAO,EAAE,QAAQ;QACjB,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,iBAAiB;QAC1B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,0BAA0B;QACnC,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,gEAAgE;QACzE,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,aAAa;KACrB;IACD;QACE,IAAI,EAAE,Y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mB,CAAC;gBAEzB,YAAY;gBACZ,gEAAgE;gBAChE,QAAQ,CAAC;oBACP,MAAM,EAAE,GAAG,CAAC,wBAAwB,CAAC;oBACrC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC;oBAChC,IAAI;iBACL,CAAC;gBACF,IAAI,CAAC,uBAAuB,CAAC;gBAC7B,IAAI,CAAC,sCAAsC,CAAC;gBAC5C,IAAI,CAAC,gCAAgC,CAAC;gBAEtC,gFAAgF;gBAChF,IAAI,CAAC,qBAAqB,CAAC;gBAC3B,IAAI,CAAC,iBAAiB,CAAC;gBACvB,IAAI,CAAC,mBAAmB,CAAC;gBAEzB,qEAAqE;gBACrE,qEAAqE;gBACrE,wEAAwE;gBACxE,mEAAmE;gBACnE,WAAW,IAAI,IAAI,CAAC,SAAS,CAAC;gBAE9B,IAAI,CAAC,YAAY,CAAC;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createConfig } from "@canonical/storybook-config";
|
|
2
|
+
|
|
3
|
+
export default createConfig("react", {
|
|
4
|
+
staticDirs: ["../src/assets", "../public"],
|
|
5
|
+
<% if (relay) { -%>
|
|
6
|
+
// Wraps stories that declare `parameters.relay` in a relay-test-utils mock
|
|
7
|
+
// environment, so components using Relay hooks render without a server.
|
|
8
|
+
extraAddons: ["@canonical/storybook-addon-relay"],
|
|
9
|
+
<% } -%>
|
|
10
|
+
});
|
|
@@ -36,6 +36,15 @@ renderer over the built assets, the same artifact that deploys.
|
|
|
36
36
|
```bash
|
|
37
37
|
bun run storybook # component workshop
|
|
38
38
|
```
|
|
39
|
+
<% if (relay) { -%>
|
|
40
|
+
|
|
41
|
+
Relay's compiler artifacts are committed, not rebuilt on the fly:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bun run relay # regenerate src/relay/__generated__ after schema/query edits
|
|
45
|
+
bun run relay:watch # the same, re-running on change — pair with dev:*
|
|
46
|
+
```
|
|
47
|
+
<% } -%>
|
|
39
48
|
|
|
40
49
|
## Adding routes
|
|
41
50
|
|
|
@@ -69,6 +78,10 @@ src/
|
|
|
69
78
|
├── server/ Server entry, compiled renderer, dev servers, sitemap
|
|
70
79
|
├── domains/ Feature domains (each owns its routes and pages)
|
|
71
80
|
├── lib/ Shared components
|
|
81
|
+
<% if (relay) { -%>
|
|
82
|
+
├── relay/ Relay environment factory, executable mock schema,
|
|
83
|
+
│ and generated artifacts (__generated__/)
|
|
84
|
+
<% } -%>
|
|
72
85
|
├── styles/ Application CSS
|
|
73
86
|
├── assets/ Assets imported in code (bundled and hashed by Vite)
|
|
74
87
|
└── routes.tsx Root route map
|
|
@@ -80,3 +93,44 @@ Domains are the unit of feature organisation: each owns its routes and pages, so
|
|
|
80
93
|
adding a feature is adding a domain rather than threading changes through shared
|
|
81
94
|
files. This app ships both `src/assets/` (assets imported in code) and `public/`
|
|
82
95
|
(files served by fixed URL); either may be removed if the app uses only one.
|
|
96
|
+
<% if (relay) { -%>
|
|
97
|
+
|
|
98
|
+
## Data layer (Relay)
|
|
99
|
+
|
|
100
|
+
The `catalog` domain demonstrates the app's [Relay](https://relay.dev) data
|
|
101
|
+
layer: `ProductList` fetches a page of products with `useLazyLoadQuery`, and
|
|
102
|
+
each `ProductCard` reads its own colocated `useFragment` — the component owns
|
|
103
|
+
its field selection, the parent query just spreads it.
|
|
104
|
+
|
|
105
|
+
**By default the app needs no backend.** `createEnvironment`
|
|
106
|
+
(`src/relay/environment.ts`) resolves every GraphQL operation in-process
|
|
107
|
+
against an executable mock schema (`src/relay/schema.ts`, built from the SDL
|
|
108
|
+
in `src/relay/schema.graphql`) backed by a small deterministic catalog. Set
|
|
109
|
+
`VITE_GRAPHQL_URL` (or pass `graphqlUrl` to `createEnvironment`) to switch the
|
|
110
|
+
environment to posting operations to a real GraphQL endpoint instead — no code
|
|
111
|
+
changes needed.
|
|
112
|
+
|
|
113
|
+
**Generated artifacts are committed.** The Vite plugin runs with
|
|
114
|
+
`codegen: false`, so `src/relay/__generated__/` is not rebuilt on the fly:
|
|
115
|
+
after editing a `graphql` tag or the schema, run `bun run relay` (or keep
|
|
116
|
+
`bun run relay:watch` running) to regenerate the artifacts, and commit them.
|
|
117
|
+
|
|
118
|
+
**SSR ships no data yet.** `useLazyLoadQuery` fetches (and suspends) while
|
|
119
|
+
rendering, and the server cannot serialize the fetched store for the client
|
|
120
|
+
yet, so the catalog page wraps its query subtree in `ClientOnly`
|
|
121
|
+
(`src/lib/ClientOnly/`): the server streams the fallback and the browser
|
|
122
|
+
fetches after hydration.
|
|
123
|
+
|
|
124
|
+
**Patched dependencies.** `patches/` carries two package patches applied via
|
|
125
|
+
`patchedDependencies` in `package.json` (a bun feature — with another package
|
|
126
|
+
manager, apply the equivalent mechanism): `react-relay@18.2.0` needs a
|
|
127
|
+
cjs-module-lexer export hint so named imports survive Node SSR, and
|
|
128
|
+
`relay-runtime-network@0.1.0` ships a broken `imports` map. The latter patch
|
|
129
|
+
is temporary until the fixed upstream release lands
|
|
130
|
+
([advl/lit-relay#32](https://github.com/advl/lit-relay/pull/32)); drop it and
|
|
131
|
+
its `patchedDependencies` entry once a fixed version is published.
|
|
132
|
+
|
|
133
|
+
**Not yet on npm.** `@canonical/storybook-addon-relay` and the fixed
|
|
134
|
+
`relay-runtime-network` release have not been published yet, so a fresh
|
|
135
|
+
install of this app will not fully resolve until they land on npm.
|
|
136
|
+
<% } -%>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
*.tsbuildinfo
|
|
15
|
+
|
|
16
|
+
# Editor directories and files
|
|
17
|
+
.vscode/*
|
|
18
|
+
!.vscode/extensions.json
|
|
19
|
+
.idea
|
|
20
|
+
.DS_Store
|
|
21
|
+
*.suo
|
|
22
|
+
*.ntvs*
|
|
23
|
+
*.njsproj
|
|
24
|
+
*.sln
|
|
25
|
+
*.sw?
|