@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.
Files changed (126) hide show
  1. package/README.md +75 -13
  2. package/dist/esm/application/react/index.js +347 -0
  3. package/dist/esm/application/react/index.js.map +1 -0
  4. package/dist/esm/application/react/templates/.browserslistrc +2 -0
  5. package/dist/esm/application/react/templates/.storybook/main.ts.ejs +10 -0
  6. package/{src → dist/esm}/application/react/templates/README.md.ejs +54 -0
  7. package/dist/esm/application/react/templates/biome.json.ejs +6 -0
  8. package/dist/esm/application/react/templates/gitignore +25 -0
  9. package/{src → dist/esm}/application/react/templates/package.json.ejs +36 -2
  10. package/dist/esm/application/react/templates/patches/react-relay@18.2.0.patch +52 -0
  11. package/dist/esm/application/react/templates/patches/relay-runtime-network@0.1.0.patch +46 -0
  12. package/dist/esm/application/react/templates/relay.config.json +8 -0
  13. package/{src/application/react/templates/src/client/entry.tsx → dist/esm/application/react/templates/src/client/entry.tsx.ejs} +23 -0
  14. package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx +50 -0
  15. package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tests.tsx +56 -0
  16. package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tsx +37 -0
  17. package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx +49 -0
  18. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.stories.tsx +103 -0
  19. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tests.tsx +80 -0
  20. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tsx +59 -0
  21. package/dist/esm/application/react/templates/src/domains/catalog/routes.ts +11 -0
  22. package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tests.tsx +35 -0
  23. package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tsx +31 -0
  24. package/dist/esm/application/react/templates/src/lib/ClientOnly/index.ts +1 -0
  25. package/{src → dist/esm}/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +3 -0
  26. package/{src/application/react/templates/src/lib/index.ts → dist/esm/application/react/templates/src/lib/index.ts.ejs} +3 -0
  27. package/dist/esm/application/react/templates/src/relay/__generated__/ProductCard_product.graphql.ts +82 -0
  28. package/dist/esm/application/react/templates/src/relay/__generated__/ProductListQuery.graphql.ts +272 -0
  29. package/dist/esm/application/react/templates/src/relay/environment.tests.ts +87 -0
  30. package/dist/esm/application/react/templates/src/relay/environment.ts +119 -0
  31. package/dist/esm/application/react/templates/src/relay/schema.graphql +111 -0
  32. package/dist/esm/application/react/templates/src/relay/schema.tests.ts +137 -0
  33. package/dist/esm/application/react/templates/src/relay/schema.ts +205 -0
  34. package/{src → dist/esm}/application/react/templates/src/routes.tsx.ejs +10 -0
  35. package/{src/application/react/templates/src/server/entry.tsx → dist/esm/application/react/templates/src/server/entry.tsx.ejs} +36 -0
  36. package/{src → dist/esm}/application/react/templates/src/sitemap/getSitemapItems.ts.ejs +3 -0
  37. package/{src/application/react/templates/tsconfig.json → dist/esm/application/react/templates/tsconfig.json.ejs} +3 -0
  38. package/dist/esm/application/react/templates/vite.config.ts.ejs +92 -0
  39. package/dist/esm/application/react/templates/vitest.setup.ts.ejs +22 -0
  40. package/dist/esm/domain/index.js +89 -0
  41. package/dist/esm/domain/index.js.map +1 -0
  42. package/{src/index.ts → dist/esm/index.js} +6 -8
  43. package/dist/esm/index.js.map +1 -0
  44. package/dist/esm/route/index.js +115 -0
  45. package/dist/esm/route/index.js.map +1 -0
  46. package/dist/esm/route/insertRoute.js +178 -0
  47. package/dist/esm/route/insertRoute.js.map +1 -0
  48. package/dist/esm/shared/casing.js +15 -0
  49. package/dist/esm/shared/casing.js.map +1 -0
  50. package/dist/esm/shared/packageManager.js +38 -0
  51. package/dist/esm/shared/packageManager.js.map +1 -0
  52. package/dist/esm/shared/versions.js +88 -0
  53. package/dist/esm/shared/versions.js.map +1 -0
  54. package/dist/esm/wrapper/index.js +72 -0
  55. package/dist/esm/wrapper/index.js.map +1 -0
  56. package/dist/types/application/react/index.d.ts +12 -0
  57. package/dist/types/application/react/index.d.ts.map +1 -0
  58. package/dist/types/domain/index.d.ts +7 -0
  59. package/dist/types/domain/index.d.ts.map +1 -0
  60. package/dist/types/index.d.ts +8 -0
  61. package/dist/types/index.d.ts.map +1 -0
  62. package/dist/types/route/index.d.ts +7 -0
  63. package/dist/types/route/index.d.ts.map +1 -0
  64. package/dist/types/route/insertRoute.d.ts +34 -0
  65. package/dist/types/route/insertRoute.d.ts.map +1 -0
  66. package/{src/shared/casing.ts → dist/types/shared/casing.d.ts} +2 -7
  67. package/dist/types/shared/casing.d.ts.map +1 -0
  68. package/dist/types/shared/packageManager.d.ts +19 -0
  69. package/dist/types/shared/packageManager.d.ts.map +1 -0
  70. package/dist/types/shared/versions.d.ts +15 -0
  71. package/dist/types/shared/versions.d.ts.map +1 -0
  72. package/dist/types/wrapper/index.d.ts +7 -0
  73. package/dist/types/wrapper/index.d.ts.map +1 -0
  74. package/package.json +16 -15
  75. package/src/application/react/index.ts +0 -294
  76. package/src/application/react/templates/.storybook/main.ts +0 -5
  77. package/src/application/react/templates/biome.json.ejs +0 -6
  78. package/src/application/react/templates/vite.config.ts +0 -45
  79. package/src/application/react/templates/vitest.setup.ts +0 -9
  80. package/src/domain/index.ts +0 -119
  81. package/src/index.test.ts +0 -398
  82. package/src/route/index.ts +0 -154
  83. package/src/route/insertRoute.test.ts +0 -98
  84. package/src/route/insertRoute.ts +0 -236
  85. package/src/shared/versions.ts +0 -48
  86. package/src/wrapper/index.ts +0 -100
  87. /package/{src → dist/esm}/application/react/templates/.storybook/decorators/index.ts +0 -0
  88. /package/{src → dist/esm}/application/react/templates/.storybook/decorators/withRouter.tsx +0 -0
  89. /package/{src → dist/esm}/application/react/templates/.storybook/preview.ts +0 -0
  90. /package/{src → dist/esm}/application/react/templates/index.html.ejs +0 -0
  91. /package/{src → dist/esm}/application/react/templates/public/.gitkeep +0 -0
  92. /package/{src → dist/esm}/application/react/templates/public/robots.txt +0 -0
  93. /package/{src → dist/esm}/application/react/templates/src/assets/.gitkeep +0 -0
  94. /package/{src → dist/esm}/application/react/templates/src/domains/account/AccountPage.tsx +0 -0
  95. /package/{src → dist/esm}/application/react/templates/src/domains/account/LoginPage.tsx +0 -0
  96. /package/{src → dist/esm}/application/react/templates/src/domains/account/routes.ts +0 -0
  97. /package/{src → dist/esm}/application/react/templates/src/domains/contact/ContactPage.tsx +0 -0
  98. /package/{src → dist/esm}/application/react/templates/src/domains/contact/routes.ts +0 -0
  99. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/GuidePage.tsx +0 -0
  100. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/HomePage.tsx +0 -0
  101. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/routes.ts +0 -0
  102. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.stories.tsx +0 -0
  103. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tests.tsx +0 -0
  104. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tsx +0 -0
  105. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/index.ts +0 -0
  106. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/styles.css +0 -0
  107. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/types.ts +0 -0
  108. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.stories.tsx +0 -0
  109. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.tsx +0 -0
  110. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/index.ts +0 -0
  111. /package/{src → dist/esm}/application/react/templates/src/lib/Navigation/index.ts +0 -0
  112. /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx +0 -0
  113. /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/index.ts +0 -0
  114. /package/{src → dist/esm}/application/react/templates/src/server/preview.bun.ts +0 -0
  115. /package/{src → dist/esm}/application/react/templates/src/server/preview.express.ts +0 -0
  116. /package/{src → dist/esm}/application/react/templates/src/server/renderer.tsx +0 -0
  117. /package/{src → dist/esm}/application/react/templates/src/server/server.bun.ts +0 -0
  118. /package/{src → dist/esm}/application/react/templates/src/server/server.express.ts +0 -0
  119. /package/{src → dist/esm}/application/react/templates/src/sitemap/renderer.ts +0 -0
  120. /package/{src → dist/esm}/application/react/templates/src/styles/app.css +0 -0
  121. /package/{src → dist/esm}/application/react/templates/src/styles/index.css.ejs +0 -0
  122. /package/{src → dist/esm}/application/react/templates/src/vite-env.d.ts +0 -0
  123. /package/{src → dist/esm}/application/react/templates/test/e2e/serverHarness.ts +0 -0
  124. /package/{src → dist/esm}/application/react/templates/test/e2e/servers.e2e.ts +0 -0
  125. /package/{src → dist/esm}/application/react/templates/vitest.config.ts +0 -0
  126. /package/{src → dist/esm}/application/react/templates/vitest.e2e.config.ts +0 -0
@@ -0,0 +1,72 @@
1
+ import * as path from "node:path";
2
+ import { exists, fail, flatMap, info, mkdir, sequence_, writeFile, } from "@canonical/task";
3
+ import { toKebabCase, toPascalCase } from "@canonical/utils";
4
+ import { normalizeCommandPath } from "../shared/casing.js";
5
+ const prompts = [
6
+ {
7
+ name: "wrapperName",
8
+ type: "text",
9
+ message: "Wrapper name (for example settings):",
10
+ default: "example",
11
+ positional: true,
12
+ group: "Wrapper",
13
+ },
14
+ ];
15
+ function buildLayout(wrapperName) {
16
+ const layoutName = `${toPascalCase(wrapperName)}Layout`;
17
+ const className = `${toKebabCase(wrapperName)}-layout`;
18
+ return `import type { ReactNode, ReactElement } from "react";
19
+
20
+ export default function ${layoutName}({
21
+ children,
22
+ }: { children: ReactNode }): ReactElement {
23
+ return <div className="${className}">{children}</div>;
24
+ }
25
+ `;
26
+ }
27
+ function buildBarrel(wrapperName) {
28
+ const layoutName = `${toPascalCase(wrapperName)}Layout`;
29
+ return `export { default } from "./${layoutName}.js";
30
+ `;
31
+ }
32
+ export const generator = {
33
+ meta: {
34
+ name: "wrapper",
35
+ displayName: "@canonical/summon-application:wrapper",
36
+ description: "Create a layout wrapper component",
37
+ version: "0.1.0",
38
+ help: `Creates a layout wrapper component under src/lib/.
39
+
40
+ Given a name like "settings", creates:
41
+ - src/lib/SettingsLayout/SettingsLayout.tsx
42
+ - src/lib/SettingsLayout/index.ts (barrel export)`,
43
+ examples: [
44
+ "summon wrapper settings",
45
+ "summon wrapper sidebar",
46
+ "summon wrapper --dry-run dashboard",
47
+ ],
48
+ },
49
+ prompts,
50
+ generate: (answers) => {
51
+ const name = normalizeCommandPath(answers.wrapperName);
52
+ const layoutName = `${toPascalCase(name)}Layout`;
53
+ const layoutDir = path.join("src", "lib", layoutName);
54
+ const scaffold = sequence_([
55
+ info(`Creating wrapper "${layoutName}"...`),
56
+ mkdir(layoutDir),
57
+ writeFile(path.join(layoutDir, `${layoutName}.tsx`), buildLayout(name)),
58
+ writeFile(path.join(layoutDir, "index.ts"), buildBarrel(name)),
59
+ info(`Wrapper "${layoutName}" created at ${layoutDir}.`),
60
+ ]);
61
+ // Refuse to run when the layout already exists — mkdir/writeFile undos are
62
+ // destructive, so overwriting then `--undo` could delete a pre-existing one.
63
+ return flatMap(exists(layoutDir), (present) => present
64
+ ? fail({
65
+ code: "WRAPPER_EXISTS",
66
+ message: `Wrapper "${layoutDir}" already exists. Choose a different name or remove it first.`,
67
+ })
68
+ : scaffold);
69
+ },
70
+ };
71
+ export default generator;
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wrapper/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAKlC,OAAO,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,KAAK,EACL,SAAS,EACT,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAM3D,MAAM,OAAO,GAAuB;IAClC;QACE,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,sCAAsC;QAC/C,OAAO,EAAE,SAAS;QAClB,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,SAAS,WAAW,CAAC,WAAmB;IACtC,MAAM,UAAU,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC;IACxD,MAAM,SAAS,GAAG,GAAG,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC;IAEvD,OAAO;;0BAEiB,UAAU;;;2BAGT,SAAS;;CAEnC,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,WAAmB;IACtC,MAAM,UAAU,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC;IAExD,OAAO,8BAA8B,UAAU;CAChD,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAwC;IAC5D,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,uCAAuC;QACpD,WAAW,EAAE,mCAAmC;QAChD,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE;;;;oDAI0C;QAChD,QAAQ,EAAE;YACR,yBAAyB;YACzB,wBAAwB;YACxB,oCAAoC;SACrC;KACF;IAED,OAAO;IAEP,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE;QACpB,MAAM,IAAI,GAAG,oBAAoB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvD,MAAM,UAAU,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC;QACjD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG,SAAS,CAAC;YACzB,IAAI,CAAC,qBAAqB,UAAU,MAAM,CAAC;YAC3C,KAAK,CAAC,SAAS,CAAC;YAChB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,UAAU,MAAM,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YACvE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YAC9D,IAAI,CAAC,YAAY,UAAU,gBAAgB,SAAS,GAAG,CAAC;SACzD,CAAC,CAAC;QAEH,2EAA2E;QAC3E,6EAA6E;QAC7E,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAC5C,OAAO;YACL,CAAC,CAAC,IAAI,CAAC;gBACH,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,YAAY,SAAS,+DAA+D;aAC9F,CAAC;YACJ,CAAC,CAAC,QAAQ,CACb,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { GeneratorDefinition } from "@canonical/summon-core";
2
+ export interface ApplicationReactAnswers {
3
+ readonly appPath: string;
4
+ readonly ssr: boolean;
5
+ readonly router: boolean;
6
+ readonly forms: boolean;
7
+ readonly relay: boolean;
8
+ readonly runInstall: boolean;
9
+ }
10
+ export declare const generator: GeneratorDefinition<ApplicationReactAnswers>;
11
+ export default generator;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/application/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAgBhC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAsDD,eAAO,MAAM,SAAS,EAAE,mBAAmB,CAAC,uBAAuB,CA4VlE,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { GeneratorDefinition } from "@canonical/summon-core";
2
+ export interface DomainAnswers {
3
+ readonly domainName: string;
4
+ }
5
+ export declare const generator: GeneratorDefinition<DomainAnswers>;
6
+ export default generator;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAchC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAiDD,eAAO,MAAM,SAAS,EAAE,mBAAmB,CAAC,aAAa,CA+CxD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const generators: {
2
+ readonly "application/react": import("@canonical/summon-core").GeneratorDefinition<import("./application/react/index.js").ApplicationReactAnswers>;
3
+ readonly domain: import("@canonical/summon-core").GeneratorDefinition<import("./domain/index.js").DomainAnswers>;
4
+ readonly route: import("@canonical/summon-core").GeneratorDefinition<import("./route/index.js").RouteAnswers>;
5
+ readonly wrapper: import("@canonical/summon-core").GeneratorDefinition<import("./wrapper/index.js").WrapperAnswers>;
6
+ };
7
+ export default generators;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU;;;;;CAK0B,CAAC;AAElD,eAAe,UAAU,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { GeneratorDefinition } from "@canonical/summon-core";
2
+ export interface RouteAnswers {
3
+ readonly routePath: string;
4
+ }
5
+ export declare const generator: GeneratorDefinition<RouteAnswers>;
6
+ export default generator;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/route/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAchC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAiCD,eAAO,MAAM,SAAS,EAAE,mBAAmB,CAAC,YAAY,CAkGvD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,34 @@
1
+ export interface RouteInsertion {
2
+ /** Imported page component, e.g. "InvoicesPage". */
3
+ readonly pageName: string;
4
+ /** Import specifier, e.g. "./InvoicesPage.js". */
5
+ readonly importPath: string;
6
+ /** Route key in the routes object, e.g. "invoices". */
7
+ readonly routeKey: string;
8
+ /** Route URL, e.g. "/billing/invoices". */
9
+ readonly url: string;
10
+ }
11
+ /**
12
+ * Insert a route into a domain `routes.ts` source.
13
+ *
14
+ * Uses the TypeScript compiler API only to *locate* the insertion points (the
15
+ * last import declaration and the `routes` object literal), then splices text
16
+ * at those offsets. Locating with the AST is robust to formatting; editing by
17
+ * string keeps the rest of the file byte-for-byte unchanged (no full re-print,
18
+ * so it doesn't fight the formatter).
19
+ *
20
+ * Idempotent: if `routeKey` already exists in the routes object, the source is
21
+ * returned unchanged. Throws if the `routes` object literal cannot be found.
22
+ */
23
+ export declare function insertRoute(source: string, ins: RouteInsertion): string;
24
+ /**
25
+ * Inverse of {@link insertRoute}: remove the route entry and its import.
26
+ *
27
+ * Used as the route generator's undo. Rather than restoring a stored copy of
28
+ * the file, it deletes exactly the lines that {@link insertRoute} added — the
29
+ * `routeKey` property in the `routes` object and the `import <pageName> ...`
30
+ * line. Idempotent: returns the source unchanged if neither is present, and
31
+ * leaves any other content (including manual edits) intact.
32
+ */
33
+ export declare function removeRoute(source: string, ins: Pick<RouteInsertion, "pageName" | "routeKey">): string;
34
+ //# sourceMappingURL=insertRoute.d.ts.map
@@ -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",
4
+ "version": "0.31.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,17 +36,17 @@
35
36
  "test": "vitest run"
36
37
  },
37
38
  "dependencies": {
38
- "@canonical/summon-core": "^0.29.0",
39
- "@canonical/task": "^0.29.0",
40
- "@canonical/utils": "^0.29.0",
39
+ "@canonical/summon-core": "^0.31.0",
40
+ "@canonical/task": "^0.31.0",
41
+ "@canonical/utils": "^0.31.0",
41
42
  "typescript": "^5.9.3"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@biomejs/biome": "2.4.9",
45
- "@canonical/biome-config": "^0.29.0",
46
- "@canonical/webarchitect": "^0.29.0",
46
+ "@canonical/biome-config": "^0.31.0",
47
+ "@canonical/webarchitect": "^0.31.0",
47
48
  "@types/node": "^24.12.0",
48
49
  "vitest": "^4.0.18"
49
50
  },
50
- "gitHead": "535302c1e1e5dd8fa9bc2da4144de57ec4e63005"
51
+ "gitHead": "d4a67ebe42e62b8cf3de77f42f537309ca88d672"
51
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
- }