@canonical/summon-application 0.29.0-experimental.0 → 0.30.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.
Files changed (127) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +75 -13
  3. package/dist/esm/application/react/index.js +347 -0
  4. package/dist/esm/application/react/index.js.map +1 -0
  5. package/dist/esm/application/react/templates/.browserslistrc +2 -0
  6. package/dist/esm/application/react/templates/.storybook/main.ts.ejs +10 -0
  7. package/{src → dist/esm}/application/react/templates/README.md.ejs +54 -0
  8. package/dist/esm/application/react/templates/biome.json.ejs +6 -0
  9. package/dist/esm/application/react/templates/gitignore +25 -0
  10. package/{src → dist/esm}/application/react/templates/package.json.ejs +36 -2
  11. package/dist/esm/application/react/templates/patches/react-relay@18.2.0.patch +52 -0
  12. package/dist/esm/application/react/templates/patches/relay-runtime-network@0.1.0.patch +46 -0
  13. package/dist/esm/application/react/templates/relay.config.json +8 -0
  14. package/{src/application/react/templates/src/client/entry.tsx → dist/esm/application/react/templates/src/client/entry.tsx.ejs} +23 -0
  15. package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx +50 -0
  16. package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tests.tsx +56 -0
  17. package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tsx +37 -0
  18. package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx +49 -0
  19. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.stories.tsx +103 -0
  20. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tests.tsx +80 -0
  21. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tsx +59 -0
  22. package/dist/esm/application/react/templates/src/domains/catalog/routes.ts +11 -0
  23. package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tests.tsx +35 -0
  24. package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tsx +31 -0
  25. package/dist/esm/application/react/templates/src/lib/ClientOnly/index.ts +1 -0
  26. package/{src → dist/esm}/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +3 -0
  27. package/{src/application/react/templates/src/lib/index.ts → dist/esm/application/react/templates/src/lib/index.ts.ejs} +3 -0
  28. package/dist/esm/application/react/templates/src/relay/__generated__/ProductCard_product.graphql.ts +82 -0
  29. package/dist/esm/application/react/templates/src/relay/__generated__/ProductListQuery.graphql.ts +272 -0
  30. package/dist/esm/application/react/templates/src/relay/environment.tests.ts +87 -0
  31. package/dist/esm/application/react/templates/src/relay/environment.ts +119 -0
  32. package/dist/esm/application/react/templates/src/relay/schema.graphql +111 -0
  33. package/dist/esm/application/react/templates/src/relay/schema.tests.ts +137 -0
  34. package/dist/esm/application/react/templates/src/relay/schema.ts +205 -0
  35. package/{src → dist/esm}/application/react/templates/src/routes.tsx.ejs +10 -0
  36. package/{src/application/react/templates/src/server/entry.tsx → dist/esm/application/react/templates/src/server/entry.tsx.ejs} +36 -0
  37. package/{src → dist/esm}/application/react/templates/src/sitemap/getSitemapItems.ts.ejs +3 -0
  38. package/{src/application/react/templates/tsconfig.json → dist/esm/application/react/templates/tsconfig.json.ejs} +3 -0
  39. package/dist/esm/application/react/templates/vite.config.ts.ejs +92 -0
  40. package/dist/esm/application/react/templates/vitest.setup.ts.ejs +22 -0
  41. package/dist/esm/domain/index.js +89 -0
  42. package/dist/esm/domain/index.js.map +1 -0
  43. package/{src/index.ts → dist/esm/index.js} +6 -8
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/route/index.js +115 -0
  46. package/dist/esm/route/index.js.map +1 -0
  47. package/dist/esm/route/insertRoute.js +178 -0
  48. package/dist/esm/route/insertRoute.js.map +1 -0
  49. package/dist/esm/shared/casing.js +15 -0
  50. package/dist/esm/shared/casing.js.map +1 -0
  51. package/dist/esm/shared/packageManager.js +38 -0
  52. package/dist/esm/shared/packageManager.js.map +1 -0
  53. package/dist/esm/shared/versions.js +88 -0
  54. package/dist/esm/shared/versions.js.map +1 -0
  55. package/dist/esm/wrapper/index.js +72 -0
  56. package/dist/esm/wrapper/index.js.map +1 -0
  57. package/dist/types/application/react/index.d.ts +12 -0
  58. package/dist/types/application/react/index.d.ts.map +1 -0
  59. package/dist/types/domain/index.d.ts +7 -0
  60. package/dist/types/domain/index.d.ts.map +1 -0
  61. package/dist/types/index.d.ts +8 -0
  62. package/dist/types/index.d.ts.map +1 -0
  63. package/dist/types/route/index.d.ts +7 -0
  64. package/dist/types/route/index.d.ts.map +1 -0
  65. package/dist/types/route/insertRoute.d.ts +34 -0
  66. package/dist/types/route/insertRoute.d.ts.map +1 -0
  67. package/{src/shared/casing.ts → dist/types/shared/casing.d.ts} +2 -7
  68. package/dist/types/shared/casing.d.ts.map +1 -0
  69. package/dist/types/shared/packageManager.d.ts +19 -0
  70. package/dist/types/shared/packageManager.d.ts.map +1 -0
  71. package/dist/types/shared/versions.d.ts +15 -0
  72. package/dist/types/shared/versions.d.ts.map +1 -0
  73. package/dist/types/wrapper/index.d.ts +7 -0
  74. package/dist/types/wrapper/index.d.ts.map +1 -0
  75. package/package.json +17 -15
  76. package/src/application/react/index.ts +0 -294
  77. package/src/application/react/templates/.storybook/main.ts +0 -5
  78. package/src/application/react/templates/biome.json.ejs +0 -6
  79. package/src/application/react/templates/vite.config.ts +0 -45
  80. package/src/application/react/templates/vitest.setup.ts +0 -9
  81. package/src/domain/index.ts +0 -119
  82. package/src/index.test.ts +0 -398
  83. package/src/route/index.ts +0 -154
  84. package/src/route/insertRoute.test.ts +0 -98
  85. package/src/route/insertRoute.ts +0 -236
  86. package/src/shared/versions.ts +0 -48
  87. package/src/wrapper/index.ts +0 -100
  88. /package/{src → dist/esm}/application/react/templates/.storybook/decorators/index.ts +0 -0
  89. /package/{src → dist/esm}/application/react/templates/.storybook/decorators/withRouter.tsx +0 -0
  90. /package/{src → dist/esm}/application/react/templates/.storybook/preview.ts +0 -0
  91. /package/{src → dist/esm}/application/react/templates/index.html.ejs +0 -0
  92. /package/{src → dist/esm}/application/react/templates/public/.gitkeep +0 -0
  93. /package/{src → dist/esm}/application/react/templates/public/robots.txt +0 -0
  94. /package/{src → dist/esm}/application/react/templates/src/assets/.gitkeep +0 -0
  95. /package/{src → dist/esm}/application/react/templates/src/domains/account/AccountPage.tsx +0 -0
  96. /package/{src → dist/esm}/application/react/templates/src/domains/account/LoginPage.tsx +0 -0
  97. /package/{src → dist/esm}/application/react/templates/src/domains/account/routes.ts +0 -0
  98. /package/{src → dist/esm}/application/react/templates/src/domains/contact/ContactPage.tsx +0 -0
  99. /package/{src → dist/esm}/application/react/templates/src/domains/contact/routes.ts +0 -0
  100. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/GuidePage.tsx +0 -0
  101. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/HomePage.tsx +0 -0
  102. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/routes.ts +0 -0
  103. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.stories.tsx +0 -0
  104. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tests.tsx +0 -0
  105. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tsx +0 -0
  106. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/index.ts +0 -0
  107. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/styles.css +0 -0
  108. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/types.ts +0 -0
  109. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.stories.tsx +0 -0
  110. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.tsx +0 -0
  111. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/index.ts +0 -0
  112. /package/{src → dist/esm}/application/react/templates/src/lib/Navigation/index.ts +0 -0
  113. /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx +0 -0
  114. /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/index.ts +0 -0
  115. /package/{src → dist/esm}/application/react/templates/src/server/preview.bun.ts +0 -0
  116. /package/{src → dist/esm}/application/react/templates/src/server/preview.express.ts +0 -0
  117. /package/{src → dist/esm}/application/react/templates/src/server/renderer.tsx +0 -0
  118. /package/{src → dist/esm}/application/react/templates/src/server/server.bun.ts +0 -0
  119. /package/{src → dist/esm}/application/react/templates/src/server/server.express.ts +0 -0
  120. /package/{src → dist/esm}/application/react/templates/src/sitemap/renderer.ts +0 -0
  121. /package/{src → dist/esm}/application/react/templates/src/styles/app.css +0 -0
  122. /package/{src → dist/esm}/application/react/templates/src/styles/index.css.ejs +0 -0
  123. /package/{src → dist/esm}/application/react/templates/src/vite-env.d.ts +0 -0
  124. /package/{src → dist/esm}/application/react/templates/test/e2e/serverHarness.ts +0 -0
  125. /package/{src → dist/esm}/application/react/templates/test/e2e/servers.e2e.ts +0 -0
  126. /package/{src → dist/esm}/application/react/templates/vitest.config.ts +0 -0
  127. /package/{src → dist/esm}/application/react/templates/vitest.e2e.config.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertRoute.d.ts","sourceRoot":"","sources":["../../../src/route/insertRoute.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kDAAkD;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2CAA2C;IAC3C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,MAAM,CA8FvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,UAAU,CAAC,GACjD,MAAM,CA2DR"}
@@ -5,10 +5,5 @@
5
5
  * This is generator-specific — it normalizes CLI input like
6
6
  * `" /billing/invoices/ "` → `"billing/invoices"`.
7
7
  */
8
- export function normalizeCommandPath(value: string): string {
9
- return value
10
- .trim()
11
- .replace(/\\/g, "/")
12
- .replace(/^\/+/, "")
13
- .replace(/\/+$/, "");
14
- }
8
+ export declare function normalizeCommandPath(value: string): string;
9
+ //# sourceMappingURL=casing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../../../src/shared/casing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM1D"}
@@ -0,0 +1,19 @@
1
+ /** Package managers we know how to run an install with, in preference order. */
2
+ declare const CANDIDATES: readonly ["bun", "npm", "pnpm", "yarn"];
3
+ export type PackageManager = (typeof CANDIDATES)[number];
4
+ /**
5
+ * Pick a package manager that is actually installed on this machine, probing
6
+ * candidates in preference order (bun → npm → pnpm → yarn) by looking each one
7
+ * up on PATH. Returns `null` if none are available.
8
+ *
9
+ * Synchronous and side-effect-free (a PATH lookup, no process spawn), so it can
10
+ * run while the generator builds its task tree. The previous code hard-coded
11
+ * `bun install`, which fails on a machine that only has Node/npm; probing keeps
12
+ * the scaffold's optional install step working regardless of which manager the
13
+ * user has.
14
+ *
15
+ * @note Impure — reads process.env.PATH and probes the filesystem.
16
+ */
17
+ export declare function pickPackageManager(): PackageManager | null;
18
+ export {};
19
+ //# sourceMappingURL=packageManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageManager.d.ts","sourceRoot":"","sources":["../../../src/shared/packageManager.ts"],"names":[],"mappings":"AAGA,gFAAgF;AAChF,QAAA,MAAM,UAAU,yCAA0C,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAiBzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,GAAG,IAAI,CAK1D"}
@@ -0,0 +1,15 @@
1
+ import type { Task } from "@canonical/task";
2
+ /**
3
+ * Resolve the version range as a Task, so the npm query participates in the
4
+ * generator pipeline (dry-run visible, cancellable) instead of firing on module
5
+ * import. Runs `npm view <pkg> version`; on any failure or unparseable output it
6
+ * yields the offline fallback range.
7
+ *
8
+ * @note Impure — spawns `npm` and reads the registry over the network.
9
+ */
10
+ export declare function resolvePragmaVersion(): Task<string>;
11
+ /**
12
+ * Print a version table for the current generator run.
13
+ */
14
+ export declare function printVersions(generatorName: string): Task<void>;
15
+ //# sourceMappingURL=versions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../src/shared/versions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,IAAI,EAAE,MAAM,iBAAiB,CAAC;AA4DxD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAAC,MAAM,CAAC,CA+BnD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAK/D"}
@@ -0,0 +1,7 @@
1
+ import type { GeneratorDefinition } from "@canonical/summon-core";
2
+ export interface WrapperAnswers {
3
+ readonly wrapperName: string;
4
+ }
5
+ export declare const generator: GeneratorDefinition<WrapperAnswers>;
6
+ export default generator;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wrapper/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAahC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAkCD,eAAO,MAAM,SAAS,EAAE,mBAAmB,CAAC,cAAc,CA4CzD,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@canonical/summon-application",
3
3
  "description": "Summon generators for application scaffolding: domain, route, and wrapper",
4
- "version": "0.29.0-experimental.0",
4
+ "version": "0.30.0",
5
5
  "type": "module",
6
- "main": "src/index.ts",
7
- "module": "src/index.ts",
8
- "types": "src/index.ts",
6
+ "main": "dist/esm/index.js",
7
+ "module": "dist/esm/index.js",
8
+ "types": "dist/types/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./src/index.ts",
12
- "import": "./src/index.ts"
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/esm/index.js"
13
13
  }
14
14
  },
15
15
  "files": [
16
- "src"
16
+ "dist"
17
17
  ],
18
18
  "author": {
19
19
  "email": "webteam@canonical.com",
@@ -25,9 +25,10 @@
25
25
  },
26
26
  "license": "GPL-3.0",
27
27
  "scripts": {
28
- "build": "echo 'No build needed - runs directly from TypeScript'",
28
+ "build": "tsc -p tsconfig.build.json && bun ../../../scripts/copy-templates.ts src dist/esm",
29
+ "build:all": "bun run build",
29
30
  "check": "bun run check:biome && bun run check:ts && bun run check:webarchitect",
30
- "check:webarchitect": "webarchitect tool-ts",
31
+ "check:webarchitect": "webarchitect library --license GPL-3.0",
31
32
  "check:fix": "bun run check:biome:fix && bun run check:ts",
32
33
  "check:biome": "biome check",
33
34
  "check:biome:fix": "biome check --write",
@@ -35,16 +36,17 @@
35
36
  "test": "vitest run"
36
37
  },
37
38
  "dependencies": {
38
- "@canonical/summon-core": "^0.29.0-experimental.0",
39
- "@canonical/task": "^0.29.0-experimental.0",
40
- "@canonical/utils": "^0.29.0-experimental.0",
39
+ "@canonical/summon-core": "^0.30.0",
40
+ "@canonical/task": "^0.30.0",
41
+ "@canonical/utils": "^0.30.0",
41
42
  "typescript": "^5.9.3"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@biomejs/biome": "2.4.9",
45
- "@canonical/biome-config": "^0.28.0",
46
- "@canonical/webarchitect": "^0.29.0-experimental.0",
46
+ "@canonical/biome-config": "^0.30.0",
47
+ "@canonical/webarchitect": "^0.30.0",
47
48
  "@types/node": "^24.12.0",
48
49
  "vitest": "^4.0.18"
49
- }
50
+ },
51
+ "gitHead": "40fe86ac955473536ac14f074812a9821f5b65c0"
50
52
  }
@@ -1,294 +0,0 @@
1
- import * as path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- import type {
4
- GeneratorDefinition,
5
- PromptDefinition,
6
- } from "@canonical/summon-core";
7
- import { template, withHelpers } from "@canonical/summon-core";
8
- import {
9
- copyFile,
10
- exec,
11
- exists,
12
- flatMap,
13
- info,
14
- sequence_,
15
- warn,
16
- when,
17
- } from "@canonical/task";
18
- import { PRAGMA_WORKSPACE_VERSION } from "../../shared/versions.js";
19
-
20
- interface ApplicationReactAnswers {
21
- readonly appPath: string;
22
- readonly ssr: boolean;
23
- readonly router: boolean;
24
- readonly forms: boolean;
25
- readonly runInstall: boolean;
26
- }
27
-
28
- const prompts: PromptDefinition[] = [
29
- {
30
- name: "appPath",
31
- type: "text",
32
- message: "Application directory name:",
33
- default: "my-app",
34
- positional: true,
35
- group: "Application",
36
- },
37
- {
38
- name: "ssr",
39
- type: "confirm",
40
- message: "Include SSR?",
41
- default: true,
42
- group: "Application",
43
- },
44
- {
45
- name: "router",
46
- type: "confirm",
47
- message: "Include router?",
48
- default: true,
49
- group: "Application",
50
- },
51
- {
52
- name: "forms",
53
- type: "confirm",
54
- message: "Include form components?",
55
- default: true,
56
- group: "Application",
57
- },
58
- {
59
- name: "runInstall",
60
- type: "confirm",
61
- message: "Run bun install?",
62
- default: true,
63
- group: "Application",
64
- },
65
- ];
66
-
67
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
68
- const templatesDir = path.join(__dirname, "templates");
69
-
70
- /** Resolve a path inside the templates directory. */
71
- const src = (templatePath: string) => path.join(templatesDir, templatePath);
72
-
73
- export const generator: GeneratorDefinition<ApplicationReactAnswers> = {
74
- meta: {
75
- name: "application/react",
76
- displayName: "@canonical/summon-application:application/react",
77
- description: "Scaffold a complete React application with SSR and routing",
78
- version: "0.1.0",
79
- help: `Creates a full React application with:
80
- - Vite build + dev server
81
- - Server-side rendering (Express + Bun dev servers)
82
- - Routing with @canonical/router-core
83
- - Head management with @canonical/react-head
84
- - Two domains (marketing + account) with pages
85
- - Contact domain with form components (when --forms is enabled)
86
- - Navigation, ThemeSelector, ExampleComponent
87
- - Storybook with router decorator
88
- - Biome + TypeScript configuration
89
-
90
- Requires both --ssr and --router flags.`,
91
- examples: [
92
- "summon application/react my-app",
93
- "summon application/react --forms my-app",
94
- "summon application/react --ssr --router --forms my-app",
95
- ],
96
- },
97
-
98
- prompts,
99
-
100
- generate: (answers) => {
101
- if (!answers.ssr || !answers.router) {
102
- throw new Error(
103
- "The application/react generator requires both --ssr and --router. " +
104
- "Standalone SPA mode is not supported.",
105
- );
106
- }
107
-
108
- // The app path is a directory path, not a route path — keep it as given
109
- // (absolute or relative), only trimming surrounding whitespace and any
110
- // trailing slash.
111
- const appPath =
112
- (answers.appPath || "my-app").trim().replace(/\/+$/, "") || "my-app";
113
-
114
- // The package name is the final path segment. For "." / "" / "/" (scaffold
115
- // into the current dir) basename gives "."/"" — resolve against the real
116
- // directory so the name is the actual folder name. Then slugify to an
117
- // npm-safe form (lowercase, safe chars).
118
- const rawName = path.basename(path.resolve(appPath));
119
- const name = rawName
120
- .toLowerCase()
121
- .replace(/[^a-z0-9._-]+/g, "-")
122
- .replace(/^[._-]+|[._-]+$/g, "");
123
-
124
- if (!name) {
125
- throw new Error(
126
- `Could not derive a valid application name from path "${appPath}". ` +
127
- "Pass an explicit directory name (lowercase letters/digits).",
128
- );
129
- }
130
-
131
- const vars = withHelpers({
132
- name,
133
- forms: answers.forms,
134
- pragmaVersion: PRAGMA_WORKSPACE_VERSION,
135
- });
136
- const dest = (...segments: string[]) => path.join(appPath, ...segments);
137
- const copy = (filePath: string) => copyFile(src(filePath), dest(filePath));
138
-
139
- return sequence_([
140
- // Warn (don't block) if the destination already exists — scaffolding
141
- // will overwrite files in place.
142
- flatMap(exists(appPath), (present) =>
143
- when(
144
- present,
145
- warn(
146
- `"${appPath}" already exists — existing files may be overwritten.`,
147
- ),
148
- ),
149
- ),
150
- info(`Scaffolding React application in "${appPath}"...`),
151
-
152
- // EJS templates (files needing interpolation)
153
- template({
154
- source: src("package.json.ejs"),
155
- dest: dest("package.json"),
156
- vars,
157
- }),
158
- template({ source: src("README.md.ejs"), dest: dest("README.md"), vars }),
159
- template({
160
- source: src("biome.json.ejs"),
161
- dest: dest("biome.json"),
162
- vars,
163
- }),
164
-
165
- // Root config
166
- copy("tsconfig.json"),
167
- copy("vite.config.ts"),
168
- copy("vitest.config.ts"),
169
- copy("vitest.setup.ts"),
170
- copy("vitest.e2e.config.ts"),
171
- // index.html (EJS — <title> uses the app name)
172
- template({
173
- source: src("index.html.ejs"),
174
- dest: dest("index.html"),
175
- vars,
176
- }),
177
- copy(".gitignore"),
178
-
179
- // E2e tests (the 2×3 server matrix + its spawn/teardown harness)
180
- copy("test/e2e/serverHarness.ts"),
181
- copy("test/e2e/servers.e2e.ts"),
182
-
183
- // Styles
184
- // styles (EJS — form stylesheet imported only when --forms)
185
- template({
186
- source: src("src/styles/index.css.ejs"),
187
- dest: dest("src/styles/index.css"),
188
- vars,
189
- }),
190
- copy("src/styles/app.css"),
191
-
192
- // Client
193
- copy("src/client/entry.tsx"),
194
-
195
- // Server — dev (Vite + HMR) and preview (compiled) servers each route
196
- // between the app + sitemap renderers; the renderers stay routing-agnostic.
197
- copy("src/server/entry.tsx"),
198
- copy("src/server/renderer.tsx"),
199
- copy("src/server/server.express.ts"),
200
- copy("src/server/server.bun.ts"),
201
- copy("src/server/preview.express.ts"),
202
- copy("src/server/preview.bun.ts"),
203
-
204
- // Sitemap (rendered route at /sitemap.xml)
205
- copy("src/sitemap/renderer.ts"),
206
- // sitemap getters (EJS — /contact entry only when --forms)
207
- template({
208
- source: src("src/sitemap/getSitemapItems.ts.ejs"),
209
- dest: dest("src/sitemap/getSitemapItems.ts"),
210
- vars,
211
- }),
212
-
213
- // Domain: marketing
214
- copy("src/domains/marketing/HomePage.tsx"),
215
- copy("src/domains/marketing/GuidePage.tsx"),
216
- copy("src/domains/marketing/routes.ts"),
217
-
218
- // Domain: account
219
- copy("src/domains/account/AccountPage.tsx"),
220
- copy("src/domains/account/LoginPage.tsx"),
221
- copy("src/domains/account/routes.ts"),
222
-
223
- // Domain: contact (when --forms is enabled)
224
- when(answers.forms, copy("src/domains/contact/ContactPage.tsx")),
225
- when(answers.forms, copy("src/domains/contact/routes.ts")),
226
-
227
- // Routes (EJS — conditionally includes contact domain)
228
- template({
229
- source: src("src/routes.tsx.ejs"),
230
- dest: dest("src/routes.tsx"),
231
- vars,
232
- }),
233
-
234
- // Lib: Navigation (EJS — contact link only when --forms)
235
- template({
236
- source: src("src/lib/Navigation/Navigation.tsx.ejs"),
237
- dest: dest("src/lib/Navigation/Navigation.tsx"),
238
- vars,
239
- }),
240
- copy("src/lib/Navigation/index.ts"),
241
-
242
- // Lib: ThemeSelector
243
- copy("src/lib/ThemeSelector/ThemeSelector.tsx"),
244
- copy("src/lib/ThemeSelector/index.ts"),
245
-
246
- // Lib: ExampleComponent
247
- copy("src/lib/ExampleComponent/ExampleComponent.tsx"),
248
- copy("src/lib/ExampleComponent/ExampleComponent.stories.tsx"),
249
- copy("src/lib/ExampleComponent/ExampleComponent.tests.tsx"),
250
- copy("src/lib/ExampleComponent/index.ts"),
251
- copy("src/lib/ExampleComponent/types.ts"),
252
- copy("src/lib/ExampleComponent/styles.css"),
253
-
254
- // Lib: LazyComponent
255
- copy("src/lib/LazyComponent/LazyComponent.tsx"),
256
- copy("src/lib/LazyComponent/LazyComponent.stories.tsx"),
257
- copy("src/lib/LazyComponent/index.ts"),
258
-
259
- // Lib barrel
260
- copy("src/lib/index.ts"),
261
-
262
- // Vite types
263
- copy("src/vite-env.d.ts"),
264
-
265
- // Storybook
266
- copy(".storybook/main.ts"),
267
- copy(".storybook/preview.ts"),
268
- copy(".storybook/decorators/withRouter.tsx"),
269
- copy(".storybook/decorators/index.ts"),
270
-
271
- // Static asset dirs (kept by placeholder; both wired into Storybook staticDirs)
272
- copy("src/assets/.gitkeep"),
273
- copy("public/.gitkeep"),
274
- copy("public/robots.txt"),
275
-
276
- // Install dependencies
277
- when(
278
- answers.runInstall,
279
- sequence_([
280
- info("Installing dependencies..."),
281
- exec("bun", ["install"], appPath),
282
- ]),
283
- ),
284
-
285
- info(
286
- answers.runInstall
287
- ? `Application "${appPath}" created. Run \`cd ${appPath} && bun run dev\` to start.`
288
- : `Application "${appPath}" created. Run \`cd ${appPath} && bun install && bun run dev\` to start.`,
289
- ),
290
- ]);
291
- },
292
- };
293
-
294
- export default generator;
@@ -1,5 +0,0 @@
1
- import { createConfig } from "@canonical/storybook-config";
2
-
3
- export default createConfig("react", {
4
- staticDirs: ["../src/assets", "../public"],
5
- });
@@ -1,6 +0,0 @@
1
- {
2
- "extends": ["@canonical/biome-config"],
3
- "files": {
4
- "includes": ["src", "*.json", "vite.config.ts"]
5
- }
6
- }
@@ -1,45 +0,0 @@
1
- import react from "@vitejs/plugin-react";
2
- import { defineConfig } from "vite";
3
-
4
- // Path aliases (#lib, #domains, #styles) are declared as Node subpath imports
5
- // in package.json "imports" and resolved natively by Vite — no resolver plugin.
6
- const PORT = Number(process.env.PORT) || undefined;
7
-
8
- // `build:server` runs `vite build --mode server` to compile the two server
9
- // renderers in a single pass. Each is a separate, individually-instantiated
10
- // Lego brick, so they are named Rollup inputs — the build emits
11
- // `dist/server/renderer.js` (the JSX app) + `dist/server/sitemap.js` (the XML
12
- // sitemap), which the preview servers import directly. Every other command
13
- // (`dev`, `build:client`, `preview`) uses the default mode and the SPA client
14
- // build (`--ssrManifest --outDir dist/client`).
15
- export default defineConfig(({ mode }) => ({
16
- plugins: [react()],
17
- // Honour the PORT env var for `dev` (SPA) and `preview` so all server scripts
18
- // — including the SSR ones, which already read PORT — respond to it uniformly.
19
- server: { port: PORT },
20
- preview: { port: PORT },
21
- build:
22
- mode === "server"
23
- ? {
24
- ssr: true,
25
- outDir: "dist/server",
26
- rollupOptions: {
27
- input: {
28
- renderer: "src/server/renderer.tsx",
29
- sitemap: "src/sitemap/renderer.ts",
30
- },
31
- },
32
- }
33
- : undefined,
34
- ssr: {
35
- // Bundle @canonical/* for SSR rather than externalising them, for two
36
- // reasons: (1) some packages declare only a "module" entry (no
37
- // "main"/"exports"), which Vite's SSR (Node-style) resolver ignores —
38
- // externalising them fails with ERR_RESOLVE_PACKAGE_ENTRY_FAIL; (2) their
39
- // built output imports CSS as a side effect (e.g. `import "./x.css"`),
40
- // which Node cannot load (ERR_UNKNOWN_FILE_EXTENSION) but Vite's SSR
41
- // transform no-ops. The regex covers the whole scope so any current or
42
- // future @canonical dependency is handled.
43
- noExternal: [/^@canonical\//],
44
- },
45
- }));
@@ -1,9 +0,0 @@
1
- import * as matchers from "@testing-library/jest-dom/matchers";
2
- import { cleanup } from "@testing-library/react";
3
- import { afterEach, expect } from "vitest";
4
-
5
- expect.extend(matchers as unknown as Parameters<typeof expect.extend>[0]);
6
-
7
- afterEach(() => {
8
- cleanup();
9
- });
@@ -1,119 +0,0 @@
1
- import * as path from "node:path";
2
- import type {
3
- GeneratorDefinition,
4
- PromptDefinition,
5
- } from "@canonical/summon-core";
6
- import {
7
- exists,
8
- fail,
9
- flatMap,
10
- info,
11
- mkdir,
12
- sequence_,
13
- writeFile,
14
- } from "@canonical/task";
15
- import { toCamelCase, toTitleCase } from "@canonical/utils";
16
- import { normalizeCommandPath } from "../shared/casing.js";
17
- import { printVersions } from "../shared/versions.js";
18
-
19
- interface DomainAnswers {
20
- readonly domainName: string;
21
- }
22
-
23
- const prompts: PromptDefinition[] = [
24
- {
25
- name: "domainName",
26
- type: "text",
27
- message: "Domain name (for example billing):",
28
- default: "example",
29
- positional: true,
30
- group: "Domain",
31
- },
32
- ];
33
-
34
- function buildMainPage(domainName: string): string {
35
- const title = toTitleCase(domainName);
36
-
37
- return `import { useHead } from "@canonical/react-head";
38
- import type { ReactElement } from "react";
39
-
40
- export default function MainPage(): ReactElement {
41
- useHead({ title: "${title}" });
42
-
43
- return (
44
- <section aria-labelledby="main-title">
45
- <h1 id="main-title">${title}</h1>
46
- <p>This is the main page for the ${domainName} domain.</p>
47
- </section>
48
- );
49
- }
50
- `;
51
- }
52
-
53
- function buildRoutesFile(domainName: string): string {
54
- const routeUrl = `/${normalizeCommandPath(domainName)}`;
55
-
56
- return `import { route } from "@canonical/router-core";
57
- import MainPage from "./MainPage.js";
58
-
59
- const routes = {
60
- ${toCamelCase(domainName)}: route({
61
- url: "${routeUrl}",
62
- content: MainPage,
63
- }),
64
- } as const;
65
-
66
- export default routes;
67
- `;
68
- }
69
-
70
- export const generator: GeneratorDefinition<DomainAnswers> = {
71
- meta: {
72
- name: "domain",
73
- displayName: "@canonical/summon-application:domain",
74
- description: "Create a domain folder with routes and a MainPage",
75
- version: "0.1.0",
76
- help: `Creates a domain directory under src/domains/ with:
77
- - MainPage.tsx — example page component with useHead()
78
- - routes.ts — route barrel exporting the domain's routes
79
-
80
- Add more routes with: summon route <domain>/<route-name>`,
81
- examples: [
82
- "summon domain billing",
83
- "summon domain user-settings",
84
- "summon domain --dry-run billing",
85
- ],
86
- },
87
-
88
- prompts,
89
-
90
- generate: (answers) => {
91
- const name = normalizeCommandPath(answers.domainName);
92
- const domainDir = path.join("src", "domains", name);
93
-
94
- const scaffold = sequence_([
95
- printVersions("domain"),
96
- info(`Creating domain "${name}"...`),
97
- mkdir(domainDir),
98
- writeFile(path.join(domainDir, "MainPage.tsx"), buildMainPage(name)),
99
- writeFile(path.join(domainDir, "routes.ts"), buildRoutesFile(name)),
100
- info(
101
- `Domain "${name}" created. Import its routes in src/routes.tsx and wire them with group().`,
102
- ),
103
- ]);
104
-
105
- // Refuse to run when the domain already exists — mkdir/writeFile undos are
106
- // destructive (DeleteDirectory / DeleteFile), so overwriting then `--undo`
107
- // could delete a pre-existing domain.
108
- return flatMap(exists(domainDir), (present) =>
109
- present
110
- ? fail({
111
- code: "DOMAIN_EXISTS",
112
- message: `Domain "${domainDir}" already exists. Choose a different name or remove it first.`,
113
- })
114
- : scaffold,
115
- );
116
- },
117
- };
118
-
119
- export default generator;