@canonical/summon-component 0.17.1 → 0.21.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 (62) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/CONVENTIONS.md +184 -0
  3. package/README.md +5 -5
  4. package/package.json +14 -10
  5. package/src/{__tests__/generators.test.ts → index.test.ts} +179 -7
  6. package/src/index.ts +4 -4
  7. package/src/{webcomponents → lit}/generator.ts +33 -36
  8. package/src/lit/index.ts +6 -0
  9. package/src/lit/types.ts +8 -0
  10. package/src/react/generator.ts +9 -12
  11. package/src/react/index.ts +1 -1
  12. package/src/shared/createComponentPathPrompt.ts +28 -0
  13. package/src/shared/{template-context.ts → createTemplateContext.ts} +4 -4
  14. package/src/shared/file-operations/appendExportToParentIndex.test.ts +75 -0
  15. package/src/shared/{file-operations.ts → file-operations/appendExportToParentIndex.ts} +12 -11
  16. package/src/shared/file-operations/dryRunWithFileState.ts +28 -0
  17. package/src/shared/file-operations/index.ts +3 -0
  18. package/src/shared/file-operations/removeExportFromParentIndex.test.ts +52 -0
  19. package/src/shared/file-operations/removeExportFromParentIndex.ts +21 -0
  20. package/src/shared/file-operations/removeLineFromFile.test.ts +66 -0
  21. package/src/shared/file-operations/removeLineFromFile.ts +29 -0
  22. package/src/shared/index.ts +6 -5
  23. package/src/shared/sharedPrompts.ts +30 -0
  24. package/src/shared/string-helpers/getComponentName.test.ts +18 -0
  25. package/src/shared/string-helpers/getComponentName.ts +8 -0
  26. package/src/shared/string-helpers/getParentDir.test.ts +16 -0
  27. package/src/shared/string-helpers/getParentDir.ts +8 -0
  28. package/src/shared/string-helpers/index.ts +3 -0
  29. package/src/shared/types.ts +1 -1
  30. package/src/shared/validateComponentPath.test.ts +40 -0
  31. package/src/shared/{validation.ts → validateComponentPath.ts} +3 -13
  32. package/src/svelte/generator.ts +7 -10
  33. package/src/svelte/index.ts +1 -1
  34. package/src/templates/{webcomponents → lit}/component.ts.ejs +8 -10
  35. package/src/templates/{webcomponents → lit}/index.ts.ejs +0 -2
  36. package/src/templates/{webcomponents → lit}/stories.ts.ejs +3 -5
  37. package/src/templates/lit/styles.css.ejs +49 -0
  38. package/src/templates/lit/tests.ts.ejs +27 -0
  39. package/src/templates/lit/types.ts.ejs +6 -0
  40. package/src/templates/react/component.tsx.ejs +0 -2
  41. package/src/templates/react/index.ts.ejs +0 -2
  42. package/src/templates/react/ssr.test.tsx.ejs +0 -2
  43. package/src/templates/react/stories.tsx.ejs +1 -3
  44. package/src/templates/react/test.tsx.ejs +0 -2
  45. package/src/templates/react/types.ts.ejs +0 -2
  46. package/src/templates/shared/styles.css.ejs +0 -2
  47. package/src/templates/svelte/component.svelte.ejs +0 -2
  48. package/src/templates/svelte/index.ts.ejs +0 -2
  49. package/src/templates/svelte/ssr.test.ts.ejs +0 -2
  50. package/src/templates/svelte/stories.svelte.ejs +0 -1
  51. package/src/templates/svelte/stories.ts.ejs +0 -2
  52. package/src/templates/svelte/test.ts.ejs +0 -2
  53. package/src/templates/svelte/types.ts.ejs +0 -2
  54. package/src/testing/integration/generators-undo.test.ts +200 -0
  55. package/vitest.config.ts +12 -0
  56. package/src/shared/prompts.ts +0 -57
  57. package/src/shared/string-helpers.ts +0 -29
  58. package/src/templates/webcomponents/styles.css.ejs +0 -16
  59. package/src/templates/webcomponents/tests.ts.ejs +0 -29
  60. package/src/templates/webcomponents/types.ts.ejs +0 -8
  61. package/src/webcomponents/index.ts +0 -6
  62. package/src/webcomponents/types.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -3,6 +3,48 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.21.0](https://github.com/canonical/pragma/compare/v0.20.1...v0.21.0) (2026-04-01)
7
+
8
+ **Note:** Version bump only for package @canonical/summon-component
9
+
10
+
11
+
12
+
13
+
14
+ # [0.20.0](https://github.com/canonical/pragma/compare/v0.19.0...v0.20.0) (2026-03-26)
15
+
16
+ **Note:** Version bump only for package @canonical/summon-component
17
+
18
+
19
+
20
+
21
+
22
+ # [0.19.0](https://github.com/canonical/pragma/compare/v0.18.0...v0.19.0) (2026-03-26)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **summon-component:** duplication of "generated by" comment ([#495](https://github.com/canonical/pragma/issues/495)) ([c52a374](https://github.com/canonical/pragma/commit/c52a374a85a9f703d0ff04b3fc3fd6d18370c458))
28
+
29
+
30
+ ### Features
31
+
32
+ * **react-ds-global:** announcement component ([#554](https://github.com/canonical/pragma/issues/554)) ([e5434d0](https://github.com/canonical/pragma/commit/e5434d05421090cb77c227ccaa6025983c9a292c))
33
+ * **task,summon-core:** extract @canonical/task, restructure summon as @canonical/summon-core (v0.1-P1+P2) ([#484](https://github.com/canonical/pragma/issues/484)) ([1493baf](https://github.com/canonical/pragma/commit/1493baf6b28a9d5cbd7e4e13009f105945df72a9))
34
+ * **task:** add undo interpreter and --undo flag across CLI ([#538](https://github.com/canonical/pragma/issues/538)) ([8c2fff5](https://github.com/canonical/pragma/commit/8c2fff58eb4e5527e4ca2aa1bd7e9f42b3cf70ee))
35
+
36
+
37
+
38
+
39
+
40
+ # [0.18.0](https://github.com/canonical/pragma/compare/v0.17.1...v0.18.0) (2026-03-11)
41
+
42
+ **Note:** Version bump only for package @canonical/summon-component
43
+
44
+
45
+
46
+
47
+
6
48
  ## [0.17.1](https://github.com/canonical/pragma/compare/v0.17.0...v0.17.1) (2026-03-04)
7
49
 
8
50
  **Note:** Version bump only for package @canonical/summon-component
package/CONVENTIONS.md ADDED
@@ -0,0 +1,184 @@
1
+ # Component Conventions
2
+
3
+ > Generated by `@canonical/summon-component` v0.1.0
4
+ > Last updated: 2026-03-08
5
+
6
+ ## Taxonomy Key
7
+
8
+ | Prefix | Domain | Description |
9
+ |--------|--------|-------------|
10
+ | `C1` | Framework | Supported frameworks and their constraints |
11
+ | `C2` | Structure | Directory layout and file organization |
12
+ | `C3` | Naming | Component, file, and directory casing |
13
+ | `C4` | Files | Required file patterns per component |
14
+ | `C5` | Exports | Barrel files and public API surface |
15
+ | `C6` | Styles | CSS patterns, theming, shared primitives |
16
+ | `C7` | Testing | Test types, patterns, runner |
17
+ | `C8` | Storybook | Story format, co-location, variants |
18
+ | `C9` | Types | Props definition and strict mode |
19
+ | `C10` | SSR | Server-side rendering support |
20
+
21
+ ---
22
+
23
+ ## C1 — Framework
24
+
25
+ | ID | Rule | Gate |
26
+ |----|------|------|
27
+ | C1.1 | Components target exactly one of: React, Svelte, or Web Components (Lit) | framework ∈ {react, svelte, lit} |
28
+ | C1.2 | React components live in `src/react/` | directory = `src/react/` |
29
+ | C1.3 | Svelte components live in `src/svelte/` | directory = `src/svelte/` |
30
+ | C1.4 | Web Components live in `src/lit/` | directory = `src/lit/` |
31
+
32
+ ### Framework Matrix
33
+
34
+ | Framework | Directory | Component Ext | Story Ext |
35
+ |-----------|-----------|---------------|-----------|
36
+ | React | `src/react/` | `.tsx` | `.stories.tsx` |
37
+ | Svelte | `src/svelte/` | `.svelte` | `.stories.svelte` + `.stories.ts` |
38
+ | Web Components (Lit) | `src/lit/` | `.ts` | `.stories.ts` |
39
+
40
+ ---
41
+
42
+ ## C2 — Structure
43
+
44
+ | ID | Rule | Gate |
45
+ |----|------|------|
46
+ | C2.1 | Each component has its own directory named in PascalCase | directory is PascalCase |
47
+ | C2.2 | Component directory contains implementation, test, story, index, types, and styles | required files present |
48
+ | C2.3 | SSR test file is separate from unit test file | `*.ssr.test.*` exists separately |
49
+
50
+ ### Component Directory Layout
51
+
52
+ ```
53
+ <ComponentName>/
54
+ ├── <ComponentName>.tsx # C4.1 Implementation
55
+ ├── <ComponentName>.test.tsx # C4.2 Unit tests
56
+ ├── <ComponentName>.stories.tsx # C4.3 Storybook stories
57
+ ├── <ComponentName>.ssr.test.tsx # C4.4 SSR tests
58
+ ├── index.ts # C4.5 Re-export barrel
59
+ ├── types.ts # C4.6 Component types
60
+ └── styles.css # C4.7 Component styles
61
+ ```
62
+
63
+ ---
64
+
65
+ ## C3 — Naming
66
+
67
+ | ID | Rule | Gate |
68
+ |----|------|------|
69
+ | C3.1 | Component names use PascalCase | name matches `/^[A-Z][a-zA-Z0-9]*$/` |
70
+ | C3.2 | File names use PascalCase matching the component name | filename = ComponentName + ext |
71
+ | C3.3 | Directory names use PascalCase matching the component name | dirname = ComponentName |
72
+ | C3.4 | Package-level exports use `index.ts` barrel files | `index.ts` exists |
73
+
74
+ ---
75
+
76
+ ## C4 — Files
77
+
78
+ | ID | Rule | Gate |
79
+ |----|------|------|
80
+ | C4.1 | Implementation file: `<Name>.tsx` / `.svelte` / `.ts` | file exists |
81
+ | C4.2 | Unit test file: `<Name>.test.tsx` / `.test.ts` | file exists |
82
+ | C4.3 | Story file: `<Name>.stories.tsx` / `.stories.ts` / `.stories.svelte` | file exists |
83
+ | C4.4 | SSR test file: `<Name>.ssr.test.tsx` / `.ssr.test.ts` | file exists |
84
+ | C4.5 | Barrel file: `index.ts` re-exports component and types | file exists |
85
+ | C4.6 | Types file: `types.ts` defines component props | file exists |
86
+ | C4.7 | Styles file: `styles.css` (optional but conventional) | file exists if styled |
87
+
88
+ ---
89
+
90
+ ## C5 — Exports
91
+
92
+ | ID | Rule | Gate |
93
+ |----|------|------|
94
+ | C5.1 | Components are exported from package via barrel files | `src/index.ts` exports component |
95
+ | C5.2 | Props types are exported alongside components | types re-exported from index |
96
+ | C5.3 | Component index re-exports from implementation and types | `index.ts` has both exports |
97
+
98
+ ### Export Pattern
99
+
100
+ ```typescript
101
+ // packages/<pkg>/src/index.ts
102
+ export { MyComponent } from "./MyComponent/index.js";
103
+ export type { MyComponentProps } from "./MyComponent/types.js";
104
+ ```
105
+
106
+ ---
107
+
108
+ ## C6 — Styles
109
+
110
+ | ID | Rule | Gate |
111
+ |----|------|------|
112
+ | C6.1 | Theming uses CSS custom properties | custom properties used |
113
+ | C6.2 | Styles are component-scoped via CSS files | styles in `styles.css` |
114
+ | C6.3 | Component file imports its styles | import statement present |
115
+ | C6.4 | Shared primitives from `@canonical/styles` | shared import used |
116
+
117
+ ---
118
+
119
+ ## C7 — Testing
120
+
121
+ | ID | Rule | Gate |
122
+ |----|------|------|
123
+ | C7.1 | Unit tests co-located with components | test file in component dir |
124
+ | C7.2 | Test pattern: `*.test.tsx` / `*.test.ts` (singular) | pattern matches |
125
+ | C7.3 | SSR tests in separate `*.ssr.test.*` files | SSR file separate |
126
+ | C7.4 | Test runner is Vitest | vitest configured |
127
+ | C7.5 | DOM testing uses `@testing-library/*` | testing-library in deps |
128
+
129
+ ---
130
+
131
+ ## C8 — Storybook
132
+
133
+ | ID | Rule | Gate |
134
+ |----|------|------|
135
+ | C8.1 | Stories co-located with components | story file in component dir |
136
+ | C8.2 | Stories use CSF3 (Component Story Format 3) | CSF3 syntax |
137
+ | C8.3 | Every component has a default story and all variant stories | default + variants present |
138
+ | C8.4 | Storybook config in `.storybook/` at package level | `.storybook/` dir exists |
139
+
140
+ ---
141
+
142
+ ## C9 — Types
143
+
144
+ | ID | Rule | Gate |
145
+ |----|------|------|
146
+ | C9.1 | Props defined in dedicated `types.ts` file | `types.ts` exists |
147
+ | C9.2 | All public types exported from `index.ts` | types re-exported |
148
+ | C9.3 | Strict TypeScript enabled (`strict: true`) | strict mode on |
149
+
150
+ ---
151
+
152
+ ## C10 — SSR
153
+
154
+ | ID | Rule | Gate |
155
+ |----|------|------|
156
+ | C10.1 | Components support server-side rendering | SSR test passes |
157
+ | C10.2 | SSR tests verify hydration correctness | hydration tested |
158
+ | C10.3 | React uses `renderToString` / `renderToPipeableStream` | correct SSR API |
159
+ | C10.4 | Svelte uses `render` from `svelte/server` | correct SSR API |
160
+ | C10.5 | Lit uses `@lit-labs/ssr` | correct SSR API |
161
+
162
+ ---
163
+
164
+ ## Quick Gate Checklist
165
+
166
+ Use this as a pass/fail gate for new components:
167
+
168
+ ```
169
+ [ ] C1.1 Framework is React, Svelte, or Web Components
170
+ [ ] C2.1 Component has its own PascalCase directory
171
+ [ ] C3.1 Component name is PascalCase
172
+ [ ] C4.1 Implementation file exists
173
+ [ ] C4.2 Unit test file exists
174
+ [ ] C4.3 Story file exists
175
+ [ ] C4.5 index.ts barrel file exists
176
+ [ ] C4.6 types.ts file exists
177
+ [ ] C5.1 Component exported from package barrel
178
+ [ ] C6.2 Styles are component-scoped
179
+ [ ] C7.4 Vitest is the test runner
180
+ [ ] C8.2 Stories use CSF3 format
181
+ [ ] C9.1 Props in dedicated types.ts
182
+ [ ] C9.3 Strict TypeScript enabled
183
+ [ ] C10.1 Component supports SSR
184
+ ```
package/README.md CHANGED
@@ -66,13 +66,13 @@ summon component svelte --component-path=src/lib/components/Card --use-ts-storie
66
66
 
67
67
  ```bash
68
68
  # Interactive — prompts guide you
69
- summon component webcomponents
69
+ summon component lit
70
70
 
71
71
  # Direct — specify path
72
- summon component webcomponents --component-path=src/lib/Button
72
+ summon component lit --component-path=src/lib/Button
73
73
 
74
74
  # Preview — see what would be created
75
- summon component webcomponents --component-path=src/lib/Button --dry-run
75
+ summon component lit --component-path=src/lib/Button --dry-run
76
76
  ```
77
77
 
78
78
  ---
@@ -197,7 +197,7 @@ Uses Svelte 5 runes (`$props()`) and render tags (`@render`).
197
197
 
198
198
  ### Web Components (Lit)
199
199
 
200
- For `summon component webcomponents --component-path=src/lib/Button`:
200
+ For `summon component lit --component-path=src/lib/Button`:
201
201
 
202
202
  ```
203
203
  src/lib/Button/
@@ -579,7 +579,7 @@ summon
579
579
 
580
580
  # Should show:
581
581
  # component [pkg] (has subtopics)
582
- # └─ react, svelte, webcomponents
582
+ # └─ react, svelte, lit
583
583
  ```
584
584
 
585
585
  If not, verify installation:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/summon-component",
3
- "description": "Component generators for Summon - React and Svelte component scaffolding",
4
- "version": "0.17.1",
3
+ "description": "Component generators for Summon - React, Svelte and Lit component scaffolding",
4
+ "version": "0.21.0",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
7
7
  "author": {
@@ -29,17 +29,21 @@
29
29
  "test": "vitest run"
30
30
  },
31
31
  "devDependencies": {
32
- "@biomejs/biome": "2.4.5",
33
- "@canonical/biome-config": "^0.17.1",
34
- "@canonical/typescript-config": "^0.17.1",
35
- "@canonical/webarchitect": "^0.17.1",
36
- "@types/bun": "^1.3.8",
37
- "@types/node": "^24.10.13",
32
+ "@biomejs/biome": "2.4.9",
33
+ "@canonical/biome-config": "^0.21.0",
34
+ "@canonical/typescript-config": "^0.21.0",
35
+ "@canonical/webarchitect": "^0.21.0",
36
+ "@types/bun": "^1.3.10",
37
+ "@types/node": "^24.12.0",
38
38
  "typescript": "^5.9.3",
39
39
  "vitest": "^4.0.18"
40
40
  },
41
+ "dependencies": {
42
+ "@canonical/utils": "^0.21.0"
43
+ },
41
44
  "peerDependencies": {
42
- "@canonical/summon": "^0.1.0"
45
+ "@canonical/summon-core": "^0.18.0 || ^0.20.0",
46
+ "@canonical/task": "^0.18.0 || ^0.20.0"
43
47
  },
44
- "gitHead": "e3eaaa9efdb58fa72acb8fdd3c7dffa25a1341c4"
48
+ "gitHead": "4a39c954e7bbad4903397f8371f801982034a26d"
45
49
  }
@@ -6,15 +6,15 @@
6
6
  */
7
7
 
8
8
  import * as fs from "node:fs";
9
- import { dryRun, dryRunWith, type Effect } from "@canonical/summon";
9
+ import { dryRun, dryRunWith, type Effect, type Task } from "@canonical/task";
10
10
  import { describe, expect, it } from "vitest";
11
- import { generators } from "../index.js";
11
+ import { generators } from "./index.js";
12
12
 
13
13
  /**
14
14
  * Helper: dry-run with actual file reading for templates.
15
15
  * This allows testing template output without writing files.
16
16
  */
17
- const dryRunWithTemplates = <A>(task: import("@canonical/summon").Task<A>) => {
17
+ const dryRunWithTemplates = <A>(task: Task<A>) => {
18
18
  const mocks = new Map<string, (effect: Effect) => unknown>([
19
19
  [
20
20
  "ReadFile",
@@ -41,6 +41,11 @@ describe("generators barrel", () => {
41
41
  expect(generators["component/svelte"]).toBeDefined();
42
42
  expect(generators["component/svelte"].meta.name).toBe("component/svelte");
43
43
  });
44
+
45
+ it("exports component/lit generator", () => {
46
+ expect(generators["component/lit"]).toBeDefined();
47
+ expect(generators["component/lit"].meta.name).toBe("component/lit");
48
+ });
44
49
  });
45
50
 
46
51
  describe("component/react generator", () => {
@@ -117,8 +122,8 @@ describe("component/react generator", () => {
117
122
  expect(paths).toContain("src/components/Button/Button.tsx");
118
123
  expect(paths).toContain("src/components/Button/types.ts");
119
124
  expect(paths).toContain("src/components/Button/index.ts");
120
- expect(paths).toContain("src/components/Button/Button.test.tsx");
121
- expect(paths).toContain("src/components/Button/Button.ssr.test.tsx");
125
+ expect(paths).toContain("src/components/Button/Button.tests.tsx");
126
+ expect(paths).toContain("src/components/Button/Button.ssr.tests.tsx");
122
127
  expect(paths).toContain("src/components/Button/Button.stories.tsx");
123
128
  expect(paths).toContain("src/components/Button/styles.css");
124
129
  });
@@ -139,8 +144,8 @@ describe("component/react generator", () => {
139
144
  expect(paths).toContain("src/components/Icon/Icon.tsx");
140
145
  expect(paths).toContain("src/components/Icon/types.ts");
141
146
  expect(paths).toContain("src/components/Icon/index.ts");
142
- expect(paths).toContain("src/components/Icon/Icon.test.tsx");
143
- expect(paths).not.toContain("src/components/Icon/Icon.ssr.test.tsx");
147
+ expect(paths).toContain("src/components/Icon/Icon.tests.tsx");
148
+ expect(paths).not.toContain("src/components/Icon/Icon.ssr.tests.tsx");
144
149
  expect(paths).not.toContain("src/components/Icon/Icon.stories.tsx");
145
150
  expect(paths).not.toContain("src/components/Icon/styles.css");
146
151
  });
@@ -330,3 +335,170 @@ describe("component/svelte generator", () => {
330
335
  });
331
336
  });
332
337
  });
338
+
339
+ // =============================================================================
340
+ // Lit Generator
341
+ // =============================================================================
342
+
343
+ describe("component/lit generator", () => {
344
+ const generator = generators["component/lit"];
345
+
346
+ describe("meta", () => {
347
+ it("has correct name", () => {
348
+ expect(generator.meta.name).toBe("component/lit");
349
+ });
350
+
351
+ it("has description containing Lit", () => {
352
+ expect(generator.meta.description).toContain("Lit");
353
+ });
354
+
355
+ it("has version", () => {
356
+ expect(generator.meta.version).toBe("0.1.0");
357
+ });
358
+
359
+ it("has help text mentioning decorators", () => {
360
+ expect(generator.meta.help).toBeDefined();
361
+ expect(generator.meta.help).toContain("decorators");
362
+ });
363
+
364
+ it("has examples", () => {
365
+ expect(generator.meta.examples).toBeDefined();
366
+ expect(generator.meta.examples?.length).toBeGreaterThan(0);
367
+ });
368
+ });
369
+
370
+ describe("prompts", () => {
371
+ it("has componentPath prompt with lib default path", () => {
372
+ const prompt = generator.prompts.find((p) => p.name === "componentPath");
373
+ expect(prompt).toBeDefined();
374
+ expect(prompt?.default).toBe("src/lib/components/MyComponent");
375
+ });
376
+
377
+ it("has withStyles prompt", () => {
378
+ const prompt = generator.prompts.find((p) => p.name === "withStyles");
379
+ expect(prompt).toBeDefined();
380
+ expect(prompt?.type).toBe("confirm");
381
+ expect(prompt?.default).toBe(true);
382
+ });
383
+
384
+ it("has withStories prompt", () => {
385
+ const prompt = generator.prompts.find((p) => p.name === "withStories");
386
+ expect(prompt).toBeDefined();
387
+ expect(prompt?.type).toBe("confirm");
388
+ expect(prompt?.default).toBe(true);
389
+ });
390
+
391
+ it("does not have withSsrTests prompt", () => {
392
+ const prompt = generator.prompts.find((p) => p.name === "withSsrTests");
393
+ expect(prompt).toBeUndefined();
394
+ });
395
+
396
+ it("does not have useTsStories prompt", () => {
397
+ const prompt = generator.prompts.find((p) => p.name === "useTsStories");
398
+ expect(prompt).toBeUndefined();
399
+ });
400
+ });
401
+
402
+ describe("generate", () => {
403
+ it("creates lit component files with all options enabled", () => {
404
+ const task = generator.generate({
405
+ componentPath: "src/lib/components/Button",
406
+ withStyles: true,
407
+ withStories: true,
408
+ withSsrTests: false,
409
+ });
410
+
411
+ const result = dryRun(task);
412
+ const paths = result.effects
413
+ .filter((e) => e._tag === "WriteFile")
414
+ .map((e) => (e as { path: string }).path);
415
+
416
+ expect(paths).toContain("src/lib/components/Button/Button.ts");
417
+ expect(paths).toContain("src/lib/components/Button/index.ts");
418
+ expect(paths).toContain("src/lib/components/Button/types.ts");
419
+ expect(paths).toContain("src/lib/components/Button/Button.tests.ts");
420
+ expect(paths).toContain("src/lib/components/Button/Button.stories.ts");
421
+ expect(paths).toContain("src/lib/components/Button/styles.css");
422
+ });
423
+
424
+ it("creates minimal component without optional files", () => {
425
+ const task = generator.generate({
426
+ componentPath: "src/lib/components/Icon",
427
+ withStyles: false,
428
+ withStories: false,
429
+ withSsrTests: false,
430
+ });
431
+
432
+ const result = dryRun(task);
433
+ const paths = result.effects
434
+ .filter((e) => e._tag === "WriteFile")
435
+ .map((e) => (e as { path: string }).path);
436
+
437
+ expect(paths).toContain("src/lib/components/Icon/Icon.ts");
438
+ expect(paths).toContain("src/lib/components/Icon/index.ts");
439
+ expect(paths).toContain("src/lib/components/Icon/types.ts");
440
+ expect(paths).toContain("src/lib/components/Icon/Icon.tests.ts");
441
+ expect(paths).not.toContain("src/lib/components/Icon/Icon.stories.ts");
442
+ expect(paths).not.toContain("src/lib/components/Icon/styles.css");
443
+ });
444
+
445
+ it("extracts component name from path", () => {
446
+ const task = generator.generate({
447
+ componentPath: "src/lib/components/MyButton",
448
+ withStyles: false,
449
+ withStories: false,
450
+ withSsrTests: false,
451
+ });
452
+
453
+ const result = dryRunWithTemplates(task);
454
+ const mainFile = result.effects.find(
455
+ (e) =>
456
+ e._tag === "WriteFile" &&
457
+ (e as { path: string }).path.endsWith("MyButton.ts"),
458
+ );
459
+
460
+ expect(mainFile).toBeDefined();
461
+ const content = (mainFile as { content: string }).content;
462
+ expect(content).toContain("MyButton");
463
+ });
464
+
465
+ it("generates kebab-case tag name", () => {
466
+ const task = generator.generate({
467
+ componentPath: "src/lib/components/MyButton",
468
+ withStyles: false,
469
+ withStories: false,
470
+ withSsrTests: false,
471
+ });
472
+
473
+ const result = dryRunWithTemplates(task);
474
+ const mainFile = result.effects.find(
475
+ (e) =>
476
+ e._tag === "WriteFile" &&
477
+ (e as { path: string }).path.endsWith("MyButton.ts"),
478
+ );
479
+
480
+ const content = (mainFile as { content: string }).content;
481
+ expect(content).toContain("my-button");
482
+ });
483
+
484
+ it("appends export to parent index", () => {
485
+ const task = generator.generate({
486
+ componentPath: "src/lib/components/Card",
487
+ withStyles: false,
488
+ withStories: false,
489
+ withSsrTests: false,
490
+ });
491
+
492
+ const result = dryRun(task);
493
+ const parentIndex = result.effects.find(
494
+ (e) =>
495
+ e._tag === "WriteFile" &&
496
+ (e as { path: string }).path === "src/lib/components/index.ts",
497
+ );
498
+
499
+ expect(parentIndex).toBeDefined();
500
+ const content = (parentIndex as { content: string }).content;
501
+ expect(content).toContain('export * from "./Card/index.js"');
502
+ });
503
+ });
504
+ });
package/src/index.ts CHANGED
@@ -15,16 +15,16 @@
15
15
  * summon component svelte --component-path=src/lib/components/Button
16
16
  *
17
17
  * # Generate a Web Component
18
- * summon component webcomponents --component-path=src/lib/components/Button
18
+ * summon component lit --component-path=src/lib/components/Button
19
19
  * ```
20
20
  *
21
21
  * @packageDocumentation
22
22
  */
23
23
 
24
- import type { AnyGenerator } from "@canonical/summon";
24
+ import type { AnyGenerator } from "@canonical/summon-core";
25
+ import { generator as litGenerator } from "./lit/index.js";
25
26
  import { generator as reactGenerator } from "./react/index.js";
26
27
  import { generator as svelteGenerator } from "./svelte/index.js";
27
- import { generator as webComponentsGenerator } from "./webcomponents/index.js";
28
28
 
29
29
  /**
30
30
  * Registry of all component generators.
@@ -35,7 +35,7 @@ import { generator as webComponentsGenerator } from "./webcomponents/index.js";
35
35
  export const generators = {
36
36
  "component/react": reactGenerator,
37
37
  "component/svelte": svelteGenerator,
38
- "component/webcomponents": webComponentsGenerator,
38
+ "component/lit": litGenerator,
39
39
  } as const satisfies Record<string, AnyGenerator>;
40
40
 
41
41
  export default generators;