@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":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACtF,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,mBAAmB,EAAE,yBAAyB;IAC9C,MAAM,EAAE,eAAe;IACvB,KAAK,EAAE,cAAc;IACrB,OAAO,EAAE,gBAAgB;CACsB,CAAC;AAElD,eAAe,UAAU,CAAC"}
@@ -0,0 +1,115 @@
1
+ import * as path from "node:path";
2
+ import { exists, fail, flatMap, info, sequence_, transformFile, writeFile, } from "@canonical/task";
3
+ import { toCamelCase, toPascalCase, toTitleCase } from "@canonical/utils";
4
+ import { normalizeCommandPath } from "../shared/casing.js";
5
+ import { insertRoute, removeRoute } from "./insertRoute.js";
6
+ const prompts = [
7
+ {
8
+ name: "routePath",
9
+ type: "text",
10
+ message: "Route path (for example account/settings):",
11
+ default: "example/page",
12
+ positional: true,
13
+ group: "Route",
14
+ },
15
+ ];
16
+ function buildPage(routeName) {
17
+ const pageName = `${toPascalCase(routeName)}Page`;
18
+ const title = toTitleCase(routeName);
19
+ const slugId = toCamelCase(routeName);
20
+ return `import { useHead } from "@canonical/react-head";
21
+ import type { ReactElement } from "react";
22
+
23
+ export default function ${pageName}(): ReactElement {
24
+ useHead({ title: "${title}" });
25
+
26
+ return (
27
+ <section aria-labelledby="${slugId}-title">
28
+ <h1 id="${slugId}-title">${title}</h1>
29
+ </section>
30
+ );
31
+ }
32
+ `;
33
+ }
34
+ export const generator = {
35
+ meta: {
36
+ name: "route",
37
+ displayName: "@canonical/summon-application:route",
38
+ description: "Add a route page to an existing domain",
39
+ version: "0.1.0",
40
+ help: `Creates a page component inside an existing domain directory.
41
+
42
+ Given a path like "account/settings":
43
+ - Domain = first segment ("account")
44
+ - Route = last segment ("settings")
45
+
46
+ Creates:
47
+ - src/domains/<domain>/<RouteName>Page.tsx
48
+ - Inserts the import + route entry into src/domains/<domain>/routes.ts
49
+
50
+ Refuses to overwrite an existing page file.
51
+
52
+ Create the domain first with: summon domain <name>
53
+
54
+ Note on --undo: undo removes the route entry and import it added. It assumes the
55
+ route was newly created — running --undo after an insert that was a no-op (the
56
+ route key already existed) would remove a route you already had.`,
57
+ examples: [
58
+ "summon route account/settings",
59
+ "summon route billing/invoices",
60
+ "summon route --dry-run user/profile",
61
+ ],
62
+ },
63
+ prompts,
64
+ generate: (answers) => {
65
+ const normalized = normalizeCommandPath(answers.routePath);
66
+ const segments = normalized.split("/");
67
+ if (segments.length < 2) {
68
+ throw new Error(`Route path must include a domain and route name (e.g. "account/settings"), got "${normalized}"`);
69
+ }
70
+ const domainName = segments[0];
71
+ const routeName = segments[segments.length - 1];
72
+ const pageName = `${toPascalCase(routeName)}Page`;
73
+ const domainDir = path.join("src", "domains", domainName);
74
+ const pageFile = path.join(domainDir, `${pageName}.tsx`);
75
+ const routesFile = path.join(domainDir, "routes.ts");
76
+ const url = `/${normalized}`;
77
+ const routeKey = toCamelCase(routeName);
78
+ const scaffold = sequence_([
79
+ info(`Adding route "${routeName}" to domain "${domainName}"...`),
80
+ // No mkdir: this generator targets an *existing* domain (guarded below).
81
+ // mkdir's default undo is DeleteDirectory, which on `--undo` could remove
82
+ // a pre-existing domain folder.
83
+ writeFile(pageFile, buildPage(routeName)),
84
+ // Insert the import + route entry into the domain's routes object via a
85
+ // pure AST-located transform (no manual edit needed afterwards). Undo
86
+ // removes exactly the lines we added, rather than restoring a snapshot.
87
+ transformFile(routesFile, (source) => insertRoute(source, {
88
+ pageName,
89
+ importPath: `./${pageName}.js`,
90
+ routeKey,
91
+ url,
92
+ }), {
93
+ undo: transformFile(routesFile, (source) => removeRoute(source, { pageName, routeKey })),
94
+ }),
95
+ info(`Route "${routeName}" wired into ${routesFile}.`),
96
+ ]);
97
+ // Guard before touching anything:
98
+ // - the domain must exist (this generator adds to an existing domain);
99
+ // - the page must NOT exist (its write's undo is a delete, so overwriting a
100
+ // hand-authored page then `--undo` would destroy the original).
101
+ return flatMap(exists(routesFile), (domainPresent) => !domainPresent
102
+ ? fail({
103
+ code: "ROUTE_DOMAIN_MISSING",
104
+ message: `Domain "${domainName}" not found (${routesFile} missing). Create it first with: summon domain ${domainName}`,
105
+ })
106
+ : flatMap(exists(pageFile), (pagePresent) => pagePresent
107
+ ? fail({
108
+ code: "ROUTE_PAGE_EXISTS",
109
+ message: `Page "${pageFile}" already exists. Choose a different route name or remove the file first.`,
110
+ })
111
+ : scaffold));
112
+ },
113
+ };
114
+ export default generator;
115
+ //# sourceMappingURL=index.js.map
@@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U,EAAE,KAAK,QAAQ,KAAK;gBAC9B,QAAQ;gBACR,GAAG;aACJ,CAAC,EACJ;gBACE,IAAI,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CACzC,WAAW,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAC5C;aACF,CACF;YACD,IAAI,CAAC,UAAU,SAAS,gBAAgB,UAAU,GAAG,CAAC;SACvD,CAAC,CAAC;QAEH,kCAAkC;QAClC,uEAAuE;QACvE,4EAA4E;QAC5E,kEAAkE;QAClE,OAAO,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,EAAE,EAAE,CACnD,CAAC,aAAa;YACZ,CAAC,CAAC,IAAI,CAAC;gBACH,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE,WAAW,UAAU,gBAAgB,UAAU,kDAAkD,UAAU,EAAE;aACvH,CAAC;YACJ,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CACxC,WAAW;gBACT,CAAC,CAAC,IAAI,CAAC;oBACH,IAAI,EAAE,mBAAmB;oBACzB,OAAO,EAAE,SAAS,QAAQ,2EAA2E;iBACtG,CAAC;gBACJ,CAAC,CAAC,QAAQ,CACb,CACN,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,178 @@
1
+ import ts from "typescript";
2
+ /**
3
+ * Peel `as const` / type assertions / parentheses off an initializer to reach
4
+ * the underlying object literal (e.g. `{ ... } as const`), if any.
5
+ */
6
+ function unwrapObjectLiteral(expr) {
7
+ let node = expr;
8
+ while (ts.isAsExpression(node) ||
9
+ ts.isParenthesizedExpression(node) ||
10
+ ts.isTypeAssertionExpression(node) ||
11
+ ts.isSatisfiesExpression(node)) {
12
+ node = node.expression;
13
+ }
14
+ return ts.isObjectLiteralExpression(node) ? node : undefined;
15
+ }
16
+ /**
17
+ * Insert a route into a domain `routes.ts` source.
18
+ *
19
+ * Uses the TypeScript compiler API only to *locate* the insertion points (the
20
+ * last import declaration and the `routes` object literal), then splices text
21
+ * at those offsets. Locating with the AST is robust to formatting; editing by
22
+ * string keeps the rest of the file byte-for-byte unchanged (no full re-print,
23
+ * so it doesn't fight the formatter).
24
+ *
25
+ * Idempotent: if `routeKey` already exists in the routes object, the source is
26
+ * returned unchanged. Throws if the `routes` object literal cannot be found.
27
+ */
28
+ export function insertRoute(source, ins) {
29
+ const sf = ts.createSourceFile("routes.ts", source, ts.ScriptTarget.Latest,
30
+ /* setParentNodes */ true);
31
+ // Locate the `routes` object literal and the last import declaration.
32
+ let routesObject;
33
+ let lastImportEnd;
34
+ for (const stmt of sf.statements) {
35
+ if (ts.isImportDeclaration(stmt)) {
36
+ lastImportEnd = stmt.end;
37
+ continue;
38
+ }
39
+ if (ts.isVariableStatement(stmt)) {
40
+ for (const decl of stmt.declarationList.declarations) {
41
+ if (ts.isIdentifier(decl.name) &&
42
+ decl.name.text === "routes" &&
43
+ decl.initializer) {
44
+ const obj = unwrapObjectLiteral(decl.initializer);
45
+ if (obj)
46
+ routesObject = obj;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ if (!routesObject) {
52
+ throw new Error("insertRoute: could not find a `const routes = { ... }` object literal");
53
+ }
54
+ // Idempotency: skip if the key is already present.
55
+ const exists = routesObject.properties.some((p) => p.name &&
56
+ (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)) &&
57
+ p.name.text === ins.routeKey);
58
+ if (exists)
59
+ return source;
60
+ // Indentation of the existing properties (fall back to two spaces).
61
+ const indent = detectIndent(source, routesObject) ?? " ";
62
+ const importLine = `import ${ins.pageName} from "${ins.importPath}";\n`;
63
+ const entry = `${indent}${ins.routeKey}: route({\n` +
64
+ `${indent}${indent}url: "${ins.url}",\n` +
65
+ `${indent}${indent}content: ${ins.pageName},\n` +
66
+ `${indent}}),\n`;
67
+ // Insert after the last existing property, or — for an empty object — just
68
+ // inside the braces. Use AST node bounds, never a brace text-scan (which can
69
+ // match a nested `route({ ... })` brace on a single-line object).
70
+ const props = routesObject.properties;
71
+ let out;
72
+ if (props.length > 0) {
73
+ const last = props[props.length - 1];
74
+ // Find the insertion point: just after the last property, including its
75
+ // trailing comma if it has one (so the existing comma stays attached to the
76
+ // existing property). If there's no trailing comma, add one.
77
+ let at = last.end;
78
+ let prefix = ",\n";
79
+ if (source[at] === ",") {
80
+ at += 1; // step past the existing comma
81
+ prefix = "\n";
82
+ }
83
+ out = `${source.slice(0, at)}${prefix}${entry.replace(/\n$/, "")}${source.slice(at)}`;
84
+ }
85
+ else {
86
+ // Empty object: insert between the braces.
87
+ const openBrace = routesObject.getStart(sf) +
88
+ source.slice(routesObject.getStart(sf)).indexOf("{") +
89
+ 1;
90
+ out = `${source.slice(0, openBrace)}\n${entry}${source.slice(openBrace)}`;
91
+ }
92
+ // Insert the import after the last existing import (offsets in the original
93
+ // source are still valid because the route entry was added later in the file).
94
+ if (lastImportEnd !== undefined) {
95
+ out =
96
+ out.slice(0, lastImportEnd) +
97
+ `\n${importLine.trimEnd()}` +
98
+ out.slice(lastImportEnd);
99
+ }
100
+ else {
101
+ out = importLine + out;
102
+ }
103
+ return out;
104
+ }
105
+ /**
106
+ * Inverse of {@link insertRoute}: remove the route entry and its import.
107
+ *
108
+ * Used as the route generator's undo. Rather than restoring a stored copy of
109
+ * the file, it deletes exactly the lines that {@link insertRoute} added — the
110
+ * `routeKey` property in the `routes` object and the `import <pageName> ...`
111
+ * line. Idempotent: returns the source unchanged if neither is present, and
112
+ * leaves any other content (including manual edits) intact.
113
+ */
114
+ export function removeRoute(source, ins) {
115
+ const sf = ts.createSourceFile("routes.ts", source, ts.ScriptTarget.Latest,
116
+ /* setParentNodes */ true);
117
+ let result = source;
118
+ // 1. Remove the route entry (the property whose name === routeKey).
119
+ for (const stmt of sf.statements) {
120
+ if (!ts.isVariableStatement(stmt))
121
+ continue;
122
+ for (const decl of stmt.declarationList.declarations) {
123
+ if (!ts.isIdentifier(decl.name) ||
124
+ decl.name.text !== "routes" ||
125
+ !decl.initializer) {
126
+ continue;
127
+ }
128
+ const obj = unwrapObjectLiteral(decl.initializer);
129
+ if (!obj)
130
+ continue;
131
+ const prop = obj.properties.find((p) => p.name &&
132
+ (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)) &&
133
+ p.name.text === ins.routeKey);
134
+ if (prop) {
135
+ result = removeFullLines(result, prop.getStart(sf), prop.end);
136
+ }
137
+ }
138
+ }
139
+ // 2. Remove the import line for the page component.
140
+ // Re-parse because offsets shifted after the entry removal.
141
+ const sf2 = ts.createSourceFile("routes.ts", result, ts.ScriptTarget.Latest, true);
142
+ for (const stmt of sf2.statements) {
143
+ if (ts.isImportDeclaration(stmt) &&
144
+ stmt.importClause?.name?.text === ins.pageName &&
145
+ // Only remove a pure default import (`import Page from "..."`), which is
146
+ // exactly what insertRoute creates. If a user merged named bindings into
147
+ // it (`import Page, { x } from "..."`), leave it — removing the whole line
148
+ // would discard their bindings.
149
+ !stmt.importClause.namedBindings) {
150
+ result = removeFullLines(result, stmt.getStart(sf2), stmt.end);
151
+ break;
152
+ }
153
+ }
154
+ return result;
155
+ }
156
+ /**
157
+ * Remove the whole-line span covering [start, end), including the node's
158
+ * leading indentation and its trailing newline, so no blank line is left behind.
159
+ */
160
+ function removeFullLines(source, start, end) {
161
+ const lineStart = source.lastIndexOf("\n", start - 1) + 1;
162
+ let lineEnd = source.indexOf("\n", end);
163
+ if (lineEnd === -1)
164
+ lineEnd = source.length;
165
+ else
166
+ lineEnd += 1; // include the newline
167
+ return source.slice(0, lineStart) + source.slice(lineEnd);
168
+ }
169
+ /** Detect the indentation used by the first property of the object literal. */
170
+ function detectIndent(source, obj) {
171
+ const first = obj.properties[0];
172
+ if (!first)
173
+ return undefined;
174
+ const lineStart = source.lastIndexOf("\n", first.getStart()) + 1;
175
+ const ws = source.slice(lineStart, first.getStart());
176
+ return /^\s+$/.test(ws) ? ws : undefined;
177
+ }
178
+ //# sourceMappingURL=insertRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertRoute.js","sourceRoot":"","sources":["../../../src/route/insertRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,IAAmB;IAEnB,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,OACE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC;QACvB,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC;QAClC,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC;QAClC,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAC9B,CAAC;QACD,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IACD,OAAO,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC;AAaD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,GAAmB;IAC7D,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAC5B,WAAW,EACX,MAAM,EACN,EAAE,CAAC,YAAY,CAAC,MAAM;IACtB,oBAAoB,CAAC,IAAI,CAC1B,CAAC;IAEF,sEAAsE;IACtE,IAAI,YAAoD,CAAC;IACzD,IAAI,aAAiC,CAAC;IAEtC,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC;QACjC,IAAI,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC;YACzB,SAAS;QACX,CAAC;QACD,IAAI,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;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AK,CAAC,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED,+EAA+E;AAC/E,SAAS,YAAY,CACnB,MAAc,EACd,GAA+B;IAE/B,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IACjE,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrD,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Normalize a command path argument: trim, remove leading/trailing slashes,
3
+ * convert backslashes to forward slashes.
4
+ *
5
+ * This is generator-specific — it normalizes CLI input like
6
+ * `" /billing/invoices/ "` → `"billing/invoices"`.
7
+ */
8
+ export function normalizeCommandPath(value) {
9
+ return value
10
+ .trim()
11
+ .replace(/\\/g, "/")
12
+ .replace(/^\/+/, "")
13
+ .replace(/\/+$/, "");
14
+ }
15
+ //# sourceMappingURL=casing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"casing.js","sourceRoot":"","sources":["../../../src/shared/casing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,KAAK;SACT,IAAI,EAAE;SACN,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;SACnB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { existsSync } from "node:fs";
2
+ import * as path from "node:path";
3
+ /** Package managers we know how to run an install with, in preference order. */
4
+ const CANDIDATES = ["bun", "npm", "pnpm", "yarn"];
5
+ /** Executable extensions to check on Windows; empty string covers POSIX. */
6
+ const EXECUTABLE_EXTENSIONS = process.platform === "win32" ? ["", ".cmd", ".exe", ".bat"] : [""];
7
+ /** Whether `bin` is found on any PATH entry. */
8
+ function onPath(bin) {
9
+ const dirs = (process.env.PATH ?? "").split(path.delimiter).filter(Boolean);
10
+ for (const dir of dirs) {
11
+ for (const ext of EXECUTABLE_EXTENSIONS) {
12
+ if (existsSync(path.join(dir, bin + ext)))
13
+ return true;
14
+ }
15
+ }
16
+ return false;
17
+ }
18
+ /**
19
+ * Pick a package manager that is actually installed on this machine, probing
20
+ * candidates in preference order (bun → npm → pnpm → yarn) by looking each one
21
+ * up on PATH. Returns `null` if none are available.
22
+ *
23
+ * Synchronous and side-effect-free (a PATH lookup, no process spawn), so it can
24
+ * run while the generator builds its task tree. The previous code hard-coded
25
+ * `bun install`, which fails on a machine that only has Node/npm; probing keeps
26
+ * the scaffold's optional install step working regardless of which manager the
27
+ * user has.
28
+ *
29
+ * @note Impure — reads process.env.PATH and probes the filesystem.
30
+ */
31
+ export function pickPackageManager() {
32
+ for (const pm of CANDIDATES) {
33
+ if (onPath(pm))
34
+ return pm;
35
+ }
36
+ return null;
37
+ }
38
+ //# sourceMappingURL=packageManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageManager.js","sourceRoot":"","sources":["../../../src/shared/packageManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,gFAAgF;AAChF,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAG3D,4EAA4E;AAC5E,MAAM,qBAAqB,GACzB,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAErE,gDAAgD;AAChD,SAAS,MAAM,CAAC,GAAW;IACzB,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5E,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,KAAK,MAAM,GAAG,IAAI,qBAAqB,EAAE,CAAC;YACxC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;QACzD,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB;IAChC,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,EAAE,CAAC;YAAE,OAAO,EAAE,CAAC;IAC5B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { createRequire } from "node:module";
2
+ import { exec, flatMap, info, map, pure, recover } from "@canonical/task";
3
+ /**
4
+ * Resolve the pragma workspace version range that a generated app should pin
5
+ * for the @canonical/* packages it depends on directly — react-ds-global(-form),
6
+ * react-head, react-hooks, react-ssr, router-core, router-react, styles,
7
+ * storybook-config, biome-config, typescript-config-react. These share one
8
+ * lerna-managed release line, so a single range covers all of them.
9
+ *
10
+ * Scope notes:
11
+ * - Third-party deps (react, express, vite…) keep their own ranges.
12
+ * - `@canonical/design-tokens` is versioned SEPARATELY and is NOT pinned here —
13
+ * it reaches the app transitively via `@canonical/styles`, which owns its range.
14
+ *
15
+ * Resolution strategy (in order):
16
+ * 1. At summon time, query the npm registry for the latest published version of
17
+ * a representative workspace package and pin `^<latest>`. This keeps freshly
18
+ * scaffolded apps on the newest release without a manual bump here.
19
+ * 2. If the query fails (offline, registry down, npm missing), fall back to the
20
+ * version of the generator itself — because summon-application is released in
21
+ * lockstep with the rest of the workspace, its own version is the correct
22
+ * release line for the app it just generated. This is always at least as
23
+ * fresh as the generator binary in use.
24
+ */
25
+ const require = createRequire(import.meta.url);
26
+ /**
27
+ * A representative workspace package whose `latest` dist-tag tracks the shared
28
+ * lerna release line. Any of the co-released packages would do; styles is a
29
+ * root dependency of every generated app.
30
+ */
31
+ const REPRESENTATIVE_PACKAGE = "@canonical/styles";
32
+ /** Read a package's version from the installed tree (offline fallback). */
33
+ function readVersion(packageName) {
34
+ try {
35
+ const pkg = require(`${packageName}/package.json`);
36
+ return pkg.version ?? "unknown";
37
+ }
38
+ catch {
39
+ return "unknown";
40
+ }
41
+ }
42
+ /**
43
+ * The generator's own release-line version, used as the offline fallback range.
44
+ * summon-application is published in lockstep with the workspace packages an app
45
+ * depends on, so `^<own version>` is a safe, non-stale default.
46
+ */
47
+ function fallbackRange() {
48
+ const own = readVersion("@canonical/summon-application");
49
+ return own === "unknown" ? "latest" : `^${own}`;
50
+ }
51
+ const coreVersion = readVersion("@canonical/summon-core");
52
+ const appVersion = readVersion("@canonical/summon-application");
53
+ const SEMVER = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
54
+ /**
55
+ * Resolve the version range as a Task, so the npm query participates in the
56
+ * generator pipeline (dry-run visible, cancellable) instead of firing on module
57
+ * import. Runs `npm view <pkg> version`; on any failure or unparseable output it
58
+ * yields the offline fallback range.
59
+ *
60
+ * @note Impure — spawns `npm` and reads the registry over the network.
61
+ */
62
+ export function resolvePragmaVersion() {
63
+ const fallback = fallbackRange();
64
+ return flatMap(
65
+ // A missing `npm` binary makes the spawn reject (a task failure) rather
66
+ // than resolve with a nonzero exit code, so recover to a synthetic failed
67
+ // ExecResult. Both spawn errors and nonzero exits then flow through the
68
+ // single fallback branch below.
69
+ recover(exec("npm", ["view", REPRESENTATIVE_PACKAGE, "version"], undefined, {
70
+ // Best-effort lookup — never let a registry miss undo prior file writes.
71
+ undo: null,
72
+ }), () => pure({ stdout: "", stderr: "", exitCode: 1 })), (result) => {
73
+ const latest = result.stdout.trim();
74
+ if (result.exitCode === 0 && SEMVER.test(latest)) {
75
+ return map(info(`Pinning @canonical/* packages to ^${latest} (latest on npm).`), () => `^${latest}`);
76
+ }
77
+ return map(info(`Could not reach npm for the latest @canonical/* version; ` +
78
+ `pinning ${fallback} (from the installed generator).`), () => fallback);
79
+ });
80
+ }
81
+ /**
82
+ * Print a version table for the current generator run.
83
+ */
84
+ export function printVersions(generatorName) {
85
+ return info(`@canonical/summon-core ${coreVersion}\n` +
86
+ `@canonical/summon-application ${appVersion} (${generatorName})`);
87
+ }
88
+ //# sourceMappingURL=versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../../src/shared/versions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,2EAA2E;AAC3E,SAAS,WAAW,CAAC,WAAmB;IACtC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,WAAW,eAAe,CAAC,CAAC;QACnD,OAAO,GAAG,CAAC,OAAO,IAAI,SAAS,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;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CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,aAAqB;IACjD,OAAO,IAAI,CACT,kCAAkC,WAAW,IAAI;QAC/C,kCAAkC,UAAU,MAAM,aAAa,GAAG,CACrE,CAAC;AACJ,CAAC"}
@@ -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,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C,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