@canonical/summon-component 0.17.0 → 0.20.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 (38) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/CONVENTIONS.md +184 -0
  3. package/README.md +5 -5
  4. package/package.json +11 -10
  5. package/src/__tests__/generators.test.ts +11 -6
  6. package/src/index.ts +4 -4
  7. package/src/{webcomponents → lit}/generator.ts +30 -35
  8. package/src/{webcomponents → lit}/index.ts +1 -1
  9. package/src/lit/types.ts +8 -0
  10. package/src/react/generator.ts +6 -11
  11. package/src/shared/file-operations.ts +48 -4
  12. package/src/shared/prompts.ts +1 -1
  13. package/src/shared/types.ts +1 -1
  14. package/src/svelte/generator.ts +4 -9
  15. package/src/templates/{webcomponents → lit}/component.ts.ejs +8 -10
  16. package/src/templates/{webcomponents → lit}/index.ts.ejs +0 -2
  17. package/src/templates/{webcomponents → lit}/stories.ts.ejs +3 -5
  18. package/src/templates/lit/styles.css.ejs +49 -0
  19. package/src/templates/lit/tests.ts.ejs +27 -0
  20. package/src/templates/lit/types.ts.ejs +6 -0
  21. package/src/templates/react/component.tsx.ejs +0 -2
  22. package/src/templates/react/index.ts.ejs +0 -2
  23. package/src/templates/react/ssr.test.tsx.ejs +0 -2
  24. package/src/templates/react/stories.tsx.ejs +1 -3
  25. package/src/templates/react/test.tsx.ejs +0 -2
  26. package/src/templates/react/types.ts.ejs +0 -2
  27. package/src/templates/shared/styles.css.ejs +0 -2
  28. package/src/templates/svelte/component.svelte.ejs +0 -2
  29. package/src/templates/svelte/index.ts.ejs +0 -2
  30. package/src/templates/svelte/ssr.test.ts.ejs +0 -2
  31. package/src/templates/svelte/stories.svelte.ejs +0 -1
  32. package/src/templates/svelte/stories.ts.ejs +0 -2
  33. package/src/templates/svelte/test.ts.ejs +0 -2
  34. package/src/templates/svelte/types.ts.ejs +0 -2
  35. package/src/templates/webcomponents/styles.css.ejs +0 -16
  36. package/src/templates/webcomponents/tests.ts.ejs +0 -29
  37. package/src/templates/webcomponents/types.ts.ejs +0 -8
  38. 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.20.0](https://github.com/canonical/pragma/compare/v0.19.0...v0.20.0) (2026-03-26)
7
+
8
+ **Note:** Version bump only for package @canonical/summon-component
9
+
10
+
11
+
12
+
13
+
14
+ # [0.19.0](https://github.com/canonical/pragma/compare/v0.18.0...v0.19.0) (2026-03-26)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **summon-component:** duplication of "generated by" comment ([#495](https://github.com/canonical/pragma/issues/495)) ([c52a374](https://github.com/canonical/pragma/commit/c52a374a85a9f703d0ff04b3fc3fd6d18370c458))
20
+
21
+
22
+ ### Features
23
+
24
+ * **react-ds-global:** announcement component ([#554](https://github.com/canonical/pragma/issues/554)) ([e5434d0](https://github.com/canonical/pragma/commit/e5434d05421090cb77c227ccaa6025983c9a292c))
25
+ * **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))
26
+ * **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))
27
+
28
+
29
+
30
+
31
+
32
+ # [0.18.0](https://github.com/canonical/pragma/compare/v0.17.1...v0.18.0) (2026-03-11)
33
+
34
+ **Note:** Version bump only for package @canonical/summon-component
35
+
36
+
37
+
38
+
39
+
40
+ ## [0.17.1](https://github.com/canonical/pragma/compare/v0.17.0...v0.17.1) (2026-03-04)
41
+
42
+ **Note:** Version bump only for package @canonical/summon-component
43
+
44
+
45
+
46
+
47
+
6
48
  # [0.17.0](https://github.com/canonical/pragma/compare/v0.16.0...v0.17.0) (2026-03-04)
7
49
 
8
50
 
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.0",
3
+ "description": "Component generators for Summon - React, Svelte and Lit component scaffolding",
4
+ "version": "0.20.0",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
7
7
  "author": {
@@ -29,17 +29,18 @@
29
29
  "test": "vitest run"
30
30
  },
31
31
  "devDependencies": {
32
- "@biomejs/biome": "2.4.5",
33
- "@canonical/biome-config": "^0.17.0",
34
- "@canonical/typescript-config": "^0.17.0",
35
- "@canonical/webarchitect": "^0.17.0",
36
- "@types/bun": "^1.3.8",
37
- "@types/node": "^24.10.13",
32
+ "@biomejs/biome": "2.4.6",
33
+ "@canonical/biome-config": "^0.20.0",
34
+ "@canonical/typescript-config": "^0.20.0",
35
+ "@canonical/webarchitect": "^0.20.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
41
  "peerDependencies": {
42
- "@canonical/summon": "^0.1.0"
42
+ "@canonical/summon-core": "^0.18.0",
43
+ "@canonical/task": "^0.18.0"
43
44
  },
44
- "gitHead": "7797c6d0bc70e440c183e8a3f2b33c6d4f03e234"
45
+ "gitHead": "1aee634b278922f2aa1cfe2a11d3b14e64280905"
45
46
  }
@@ -6,7 +6,7 @@
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
11
  import { generators } from "../index.js";
12
12
 
@@ -14,7 +14,7 @@ import { generators } from "../index.js";
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
  });
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;
@@ -10,8 +10,8 @@
10
10
  *
11
11
  * @example
12
12
  * ```bash
13
- * summon component webcomponents --component-path=src/lib/components/Button
14
- * summon component webcomponents --component-path=src/lib/components/Card --with-styles --with-stories
13
+ * summon component lit --component-path=src/lib/components/Button
14
+ * summon component lit --component-path=src/lib/components/Card --with-styles --with-stories
15
15
  * ```
16
16
  *
17
17
  * @module
@@ -19,15 +19,9 @@
19
19
 
20
20
  import * as path from "node:path";
21
21
  import { fileURLToPath } from "node:url";
22
- import {
23
- debug,
24
- type GeneratorDefinition,
25
- info,
26
- mkdir,
27
- sequence_,
28
- template,
29
- when,
30
- } from "@canonical/summon";
22
+ import { type GeneratorDefinition, template } from "@canonical/summon-core";
23
+ import { debug, info, mkdir, sequence_, when } from "@canonical/task";
24
+ import pkg from "../../package.json" with { type: "json" };
31
25
 
32
26
  import {
33
27
  appendExportToParentIndex,
@@ -36,7 +30,7 @@ import {
36
30
  getComponentName,
37
31
  getParentDir,
38
32
  } from "../shared/index.js";
39
- import type { WebComponentAnswers } from "./types.js";
33
+ import type { LitAnswers } from "./types.js";
40
34
 
41
35
  // =============================================================================
42
36
  // Template Paths
@@ -45,20 +39,20 @@ import type { WebComponentAnswers } from "./types.js";
45
39
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
46
40
  const templatesDir = path.join(__dirname, "..", "templates");
47
41
 
48
- const webComponentTemplates = {
49
- component: path.join(templatesDir, "webcomponents", "component.ts.ejs"),
50
- index: path.join(templatesDir, "webcomponents", "index.ts.ejs"),
51
- types: path.join(templatesDir, "webcomponents", "types.ts.ejs"),
52
- tests: path.join(templatesDir, "webcomponents", "tests.ts.ejs"),
53
- stories: path.join(templatesDir, "webcomponents", "stories.ts.ejs"),
54
- styles: path.join(templatesDir, "webcomponents", "styles.css.ejs"),
42
+ const litTemplates = {
43
+ component: path.join(templatesDir, "lit", "component.ts.ejs"),
44
+ index: path.join(templatesDir, "lit", "index.ts.ejs"),
45
+ types: path.join(templatesDir, "lit", "types.ts.ejs"),
46
+ tests: path.join(templatesDir, "lit", "tests.ts.ejs"),
47
+ stories: path.join(templatesDir, "lit", "stories.ts.ejs"),
48
+ styles: path.join(templatesDir, "lit", "styles.css.ejs"),
55
49
  };
56
50
 
57
51
  // =============================================================================
58
52
  // Custom Prompts (without SSR tests)
59
53
  // =============================================================================
60
54
 
61
- const webComponentPrompts = [
55
+ const litPrompts = [
62
56
  {
63
57
  name: "withStyles",
64
58
  type: "confirm",
@@ -85,11 +79,12 @@ const webComponentPrompts = [
85
79
  * This generator creates a complete Lit web component with TypeScript support,
86
80
  * testing infrastructure, and optional Storybook stories and CSS styles.
87
81
  *
88
- * @see {@link https://summon.dev/generators/component/webcomponents} for documentation
82
+ * @see {@link https://summon.dev/generators/component/lit} for documentation
89
83
  */
90
84
  export const generator = {
91
85
  meta: {
92
- name: "component/webcomponents",
86
+ name: "component/lit",
87
+ displayName: `${pkg.name}:lit`,
93
88
  description:
94
89
  "Generate a Lit web component with TypeScript, tests, stories, and styles",
95
90
  version: "0.1.0",
@@ -106,20 +101,20 @@ The component name is extracted from the path and must be PascalCase.
106
101
  For example, 'src/lib/components/Button' creates a 'Button' component
107
102
  with the custom element tag 'button'.`,
108
103
  examples: [
109
- "summon component webcomponents --component-path=src/lib/components/Button",
110
- "summon component webcomponents --component-path=src/lib/components/Card --with-styles --with-stories",
111
- "summon component webcomponents --component-path=src/lib/components/Modal --no-with-styles",
112
- "summon component webcomponents --component-path=src/lib/components/Button --dry-run",
104
+ "summon component lit --component-path=src/lib/components/Button",
105
+ "summon component lit --component-path=src/lib/components/Card --with-styles --with-stories",
106
+ "summon component lit --component-path=src/lib/components/Modal --no-with-styles",
107
+ "summon component lit --component-path=src/lib/components/Button --dry-run",
113
108
  ],
114
109
  },
115
110
 
116
- prompts: [createComponentPathPrompt("webcomponents"), ...webComponentPrompts],
111
+ prompts: [createComponentPathPrompt("lit"), ...litPrompts],
117
112
 
118
113
  generate: (answers) => {
119
114
  const componentName = getComponentName(answers.componentPath);
120
115
  const componentDir = answers.componentPath;
121
116
  const parentDir = getParentDir(answers.componentPath);
122
- const ctx = createTemplateContext(answers, "webcomponents");
117
+ const ctx = createTemplateContext(answers, "lit");
123
118
 
124
119
  return sequence_([
125
120
  info(`Generating Lit web component: ${componentName}`),
@@ -129,28 +124,28 @@ with the custom element tag 'button'.`,
129
124
 
130
125
  debug("Creating main component file"),
131
126
  template({
132
- source: webComponentTemplates.component,
127
+ source: litTemplates.component,
133
128
  dest: path.join(componentDir, `${componentName}.ts`),
134
129
  vars: ctx,
135
130
  }),
136
131
 
137
132
  debug("Creating index barrel file"),
138
133
  template({
139
- source: webComponentTemplates.index,
134
+ source: litTemplates.index,
140
135
  dest: path.join(componentDir, "index.ts"),
141
136
  vars: ctx,
142
137
  }),
143
138
 
144
139
  debug("Creating types file"),
145
140
  template({
146
- source: webComponentTemplates.types,
141
+ source: litTemplates.types,
147
142
  dest: path.join(componentDir, "types.ts"),
148
143
  vars: ctx,
149
144
  }),
150
145
 
151
146
  debug("Creating test file"),
152
147
  template({
153
- source: webComponentTemplates.tests,
148
+ source: litTemplates.tests,
154
149
  dest: path.join(componentDir, `${componentName}.tests.ts`),
155
150
  vars: ctx,
156
151
  }),
@@ -159,7 +154,7 @@ with the custom element tag 'button'.`,
159
154
  when(
160
155
  answers.withStories,
161
156
  template({
162
- source: webComponentTemplates.stories,
157
+ source: litTemplates.stories,
163
158
  dest: path.join(componentDir, `${componentName}.stories.ts`),
164
159
  vars: ctx,
165
160
  }),
@@ -169,7 +164,7 @@ with the custom element tag 'button'.`,
169
164
  when(
170
165
  answers.withStyles,
171
166
  template({
172
- source: webComponentTemplates.styles,
167
+ source: litTemplates.styles,
173
168
  dest: path.join(componentDir, "styles.css"),
174
169
  vars: ctx,
175
170
  }),
@@ -181,4 +176,4 @@ with the custom element tag 'button'.`,
181
176
  info(`Created ${componentName} component at ${componentDir}`),
182
177
  ]);
183
178
  },
184
- } as const satisfies GeneratorDefinition<WebComponentAnswers>;
179
+ } as const satisfies GeneratorDefinition<LitAnswers>;
@@ -3,4 +3,4 @@
3
3
  */
4
4
 
5
5
  export { generator } from "./generator.js";
6
- export type { WebComponentAnswers } from "./types.js";
6
+ export type { LitAnswers } from "./types.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Types for Lit web component generator
3
+ */
4
+
5
+ import type { BaseComponentAnswers } from "../shared/index.js";
6
+
7
+ /** Lit web component generator answers - uses base answers only */
8
+ export type LitAnswers = BaseComponentAnswers;
@@ -21,15 +21,9 @@
21
21
 
22
22
  import * as path from "node:path";
23
23
  import { fileURLToPath } from "node:url";
24
- import {
25
- debug,
26
- type GeneratorDefinition,
27
- info,
28
- mkdir,
29
- sequence_,
30
- template,
31
- when,
32
- } from "@canonical/summon";
24
+ import { type GeneratorDefinition, template } from "@canonical/summon-core";
25
+ import { debug, info, mkdir, sequence_, when } from "@canonical/task";
26
+ import pkg from "../../package.json" with { type: "json" };
33
27
 
34
28
  import {
35
29
  appendExportToParentIndex,
@@ -73,6 +67,7 @@ const reactTemplates = {
73
67
  export const generator = {
74
68
  meta: {
75
69
  name: "component/react",
70
+ displayName: `${pkg.name}:react`,
76
71
  description:
77
72
  "Generate a React component with TypeScript, tests, stories, and styles",
78
73
  version: "0.1.0",
@@ -134,7 +129,7 @@ For example, 'src/components/Button' creates a 'Button' component.`,
134
129
  debug("Creating test file"),
135
130
  template({
136
131
  source: reactTemplates.test,
137
- dest: path.join(componentDir, `${componentName}.test.tsx`),
132
+ dest: path.join(componentDir, `${componentName}.tests.tsx`),
138
133
  vars: ctx,
139
134
  }),
140
135
 
@@ -143,7 +138,7 @@ For example, 'src/components/Button' creates a 'Button' component.`,
143
138
  answers.withSsrTests,
144
139
  template({
145
140
  source: reactTemplates.ssrTest,
146
- dest: path.join(componentDir, `${componentName}.ssr.test.tsx`),
141
+ dest: path.join(componentDir, `${componentName}.ssr.tests.tsx`),
147
142
  vars: ctx,
148
143
  }),
149
144
  ),
@@ -5,6 +5,7 @@
5
5
  import * as path from "node:path";
6
6
  import {
7
7
  appendFile,
8
+ deleteFile,
8
9
  exists,
9
10
  flatMap,
10
11
  ifElseM,
@@ -12,10 +13,33 @@ import {
12
13
  readFile,
13
14
  type Task,
14
15
  writeFile,
15
- } from "@canonical/summon";
16
+ } from "@canonical/task";
16
17
 
17
18
  /**
18
- * Append export to parent index.ts file (or create if not exists)
19
+ * Remove a specific line from a file. If the file becomes empty,
20
+ * delete it entirely. Idempotent — no-op if the line is not present.
21
+ */
22
+ export const removeLineFromFile = (
23
+ filePath: string,
24
+ line: string,
25
+ ): Task<void> =>
26
+ flatMap(readFile(filePath), (content) => {
27
+ const trimmedLine = line.trim();
28
+ const filtered = content
29
+ .split("\n")
30
+ .filter((l) => l.trim() !== trimmedLine)
31
+ .join("\n");
32
+
33
+ if (filtered.trim() === "") {
34
+ return deleteFile(filePath, { undo: null });
35
+ }
36
+ return writeFile(filePath, filtered, { undo: null });
37
+ });
38
+
39
+ /**
40
+ * Append export to parent index.ts file (or create if not exists).
41
+ * Carries undo metadata: removes the export line (or deletes the index
42
+ * if it was created from scratch).
19
43
  */
20
44
  export const appendExportToParentIndex = (
21
45
  parentDir: string,
@@ -31,9 +55,29 @@ export const appendExportToParentIndex = (
31
55
  if (content.includes(`./${componentName}`)) {
32
56
  return pure(undefined); // Already exported
33
57
  }
34
- return appendFile(indexPath, exportLine);
58
+ return appendFile(indexPath, exportLine, true, {
59
+ undo: removeLineFromFile(indexPath, exportLine),
60
+ });
35
61
  }),
36
- // If not exists, create new file
62
+ // If not exists, create new file (default undo: deleteFile is correct)
37
63
  writeFile(indexPath, exportLine),
38
64
  );
39
65
  };
66
+
67
+ /**
68
+ * Remove a component export from a parent index.ts.
69
+ * Idempotent — no-op if the export is not present or the file doesn't exist.
70
+ */
71
+ export const removeExportFromParentIndex = (
72
+ parentDir: string,
73
+ componentName: string,
74
+ ): Task<void> => {
75
+ const indexPath = path.join(parentDir, "index.ts");
76
+ const exportLine = `export * from "./${componentName}/index.js";\n`;
77
+
78
+ return ifElseM(
79
+ exists(indexPath),
80
+ removeLineFromFile(indexPath, exportLine),
81
+ pure(undefined),
82
+ );
83
+ };
@@ -2,7 +2,7 @@
2
2
  * Shared prompt definitions for component generators
3
3
  */
4
4
 
5
- import type { PromptDefinition } from "@canonical/summon";
5
+ import type { PromptDefinition } from "@canonical/summon-core";
6
6
  import type { Framework } from "./types.js";
7
7
  import { validateComponentPath } from "./validation.js";
8
8
 
@@ -2,7 +2,7 @@
2
2
  * Shared types for component generators
3
3
  */
4
4
 
5
- export type Framework = "react" | "svelte" | "webcomponents";
5
+ export type Framework = "react" | "svelte" | "lit";
6
6
 
7
7
  /** Base answers shared across component generators */
8
8
  export interface BaseComponentAnswers {
@@ -23,15 +23,9 @@
23
23
 
24
24
  import * as path from "node:path";
25
25
  import { fileURLToPath } from "node:url";
26
- import {
27
- debug,
28
- type GeneratorDefinition,
29
- info,
30
- mkdir,
31
- sequence_,
32
- template,
33
- when,
34
- } from "@canonical/summon";
26
+ import { type GeneratorDefinition, template } from "@canonical/summon-core";
27
+ import { debug, info, mkdir, sequence_, when } from "@canonical/task";
28
+ import pkg from "../../package.json" with { type: "json" };
35
29
 
36
30
  import {
37
31
  appendExportToParentIndex,
@@ -76,6 +70,7 @@ const svelteTemplates = {
76
70
  export const generator = {
77
71
  meta: {
78
72
  name: "component/svelte",
73
+ displayName: `${pkg.name}:svelte`,
79
74
  description:
80
75
  "Generate a Svelte 5 component with TypeScript, tests, stories, and styles",
81
76
  version: "0.1.0",
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import { html, LitElement } from "lit";
4
2
  import { customElement } from "lit/decorators.js";
5
3
  <% if (withStyles) { -%>
@@ -17,14 +15,14 @@ const componentCssClassName = "ds <%= kebabName %>";
17
15
  @customElement("ds-<%= kebabName %>")
18
16
  export default class <%= name %> extends LitElement implements <%= name %>Props {
19
17
  <% if (withStyles) { -%>
20
- static styles = styles;
18
+ static styles = styles;
21
19
 
22
20
  <% } -%>
23
- render() {
24
- return html`
25
- <div class="${componentCssClassName}">
26
- <slot></slot>
27
- </div>
28
- `;
29
- }
21
+ render() {
22
+ return html`
23
+ <div class="${componentCssClassName}">
24
+ <slot></slot>
25
+ </div>
26
+ `;
27
+ }
30
28
  }
@@ -1,4 +1,2 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  export { default as <%= name %> } from "./<%= name %>.js";
4
2
  export type { <%= name %>Props } from "./types.js";
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import type { Meta, StoryObj } from "@storybook/web-components-vite";
4
2
  import { html } from "lit";
5
3
 
@@ -7,13 +5,13 @@ import "./<%= name %>.js";
7
5
  import type <%= name %> from "./<%= name %>.js";
8
6
 
9
7
  const meta = {
10
- title: "Web Components/<%= name %>",
11
- tags: ["autodocs"],
8
+ title: "Web Components/<%= name %>",
9
+ tags: ["autodocs"],
12
10
  } satisfies Meta<<%= name %>>;
13
11
 
14
12
  export default meta;
15
13
  type Story = StoryObj<<%= name %>>;
16
14
 
17
15
  export const Default: Story = {
18
- render: () => html`<ds-<%= kebabName %>></ds-<%= kebabName %>>`,
16
+ render: () => html`<ds-<%= kebabName %>>Hello, <%= name %>!</ds-<%= kebabName %>>`,
19
17
  };
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Lit Layout Primer
3
+ * Delete this comment block when you're done implementing.
4
+ *
5
+ * Styles live in a shadow DOM, isolated from the page by default.
6
+ *
7
+ * Two layers:
8
+ *
9
+ * 1) :host — the outer shell, how this component presents to its parent layout.
10
+ * display, width, height (always apply)
11
+ * grid-column, grid-row, align-self, justify-self (parent must be grid/flex)
12
+ *
13
+ * 2) .ds.<%= kebabName %> — the inner shell, how this component arranges its shadow children.
14
+ * display: grid/flex, gap, grid-template-columns, align-items, justify-content
15
+ *
16
+ * Subgrid pattern — use when the parent defines grid tracks you want to inherit:
17
+ *
18
+ * In the parent component:
19
+ * .ds.parent { display: grid; grid-template-columns: repeat(4, 1fr); }
20
+ *
21
+ * In this component:
22
+ * :host { display: grid; grid-column: span 2; }
23
+ * .ds.<%= kebabName %> { display: grid; grid-template-columns: subgrid; }
24
+ *
25
+ * In this example, the parent establishes a 4-column grid.
26
+ * This component claims 2 of those columns and inherits their widths via subgrid.
27
+ *
28
+ * Keep in mind:
29
+ * - Custom elements are display: inline by default — always set display on :host.
30
+ * - Flex/grid rules only affect direct children of the container, not deeper descendants.
31
+ * - External CSS cannot pierce the shadow boundary — expose CSS custom properties for theming.
32
+ */
33
+
34
+ :host {
35
+ /*
36
+ * Host controls the outer layout role.
37
+ * Declare component CSS variables here when needed.
38
+ * Variables must be on :host to be accessible inside the shadow tree.
39
+ *
40
+ * Example:
41
+ * --<%= kebabName %>-color-background: var(--color-background-default);
42
+ * --<%= kebabName %>-color-text: var(--color-text-default);
43
+ */
44
+ display: inline-flex;
45
+ }
46
+
47
+ .ds.<%= kebabName %> {
48
+ /* Inner layout and visual styles go here. */
49
+ }
@@ -0,0 +1,27 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+ import "./<%= name %>.js";
3
+ import type <%= name %> from "./<%= name %>.js";
4
+
5
+ describe("<%= name %> component", () => {
6
+ let elem: <%= name %>;
7
+
8
+ beforeEach(() => {
9
+ elem = document.createElement("ds-<%= kebabName %>") as <%= name %>;
10
+ document.body.appendChild(elem);
11
+ });
12
+
13
+ afterEach(() => {
14
+ elem.remove();
15
+ });
16
+
17
+ it("should render component", async () => {
18
+ await customElements.whenDefined("ds-<%= kebabName %>");
19
+
20
+ const container = elem.shadowRoot?.querySelector(".ds.<%= kebabName %>");
21
+ expect(container).toBeTruthy();
22
+ });
23
+
24
+ it("should have correct tag name", () => {
25
+ expect(elem.tagName.toLowerCase()).toBe("ds-<%= kebabName %>");
26
+ });
27
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Props for the <%= name %> component.
3
+ */
4
+ export interface <%= name %>Props {
5
+ // Define props specific to <%= name %> here
6
+ }
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import type React from "react";
4
2
  import type { <%= name %>Props } from "./types.js";
5
3
  <% if (withStyles) { -%>
@@ -1,4 +1,2 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  export { default as <%= name %> } from "./<%= name %>.js";
4
2
  export type * from "./types.js";
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import { describe, expect, it } from "vitest";
4
2
  import { renderToString } from "react-dom/server";
5
3
  import <%= name %> from "./<%= name %>.js";
@@ -1,6 +1,4 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
- import type { Meta, StoryObj } from "@storybook/react";
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
2
  import <%= name %> from "./<%= name %>.js";
5
3
 
6
4
  const meta: Meta<typeof <%= name %>> = {
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import { describe, expect, it } from "vitest";
4
2
  import { render, screen } from "@testing-library/react";
5
3
  import <%= name %> from "./<%= name %>.js";
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import type { HTMLAttributes, ReactNode } from "react";
4
2
 
5
3
  export interface <%= name %>Props extends HTMLAttributes<HTMLDivElement> {
@@ -1,5 +1,3 @@
1
- /* Generated by <%= generatorName %> v<%= version %> */
2
-
3
1
  .ds.<%= kebabName %> {
4
2
  /* Component styles */
5
3
  }
@@ -1,5 +1,3 @@
1
- <!-- Generated by <%= generatorName %> v<%= version %> -->
2
-
3
1
  <script lang="ts">
4
2
  import type { <%= name %>Props } from "./types";
5
3
  <% if (withStyles) { -%>
@@ -1,4 +1,2 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  export { default as <%= name %> } from "./<%= name %>.svelte";
4
2
  export type { <%= name %>Props } from "./types";
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import { render } from "@canonical/svelte-ssr-test";
4
2
  import type { RenderResult } from "@canonical/svelte-ssr-test";
5
3
  import { createRawSnippet } from "svelte";
@@ -1,5 +1,4 @@
1
1
  <script lang="ts" module>
2
- // Generated by <%= generatorName %> v<%= version %>
3
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
4
3
  import <%= name %> from "./<%= name %>.svelte";
5
4
 
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import type { Meta, StoryObj } from "@storybook/svelte";
4
2
  import <%= name %> from "./<%= name %>.svelte";
5
3
 
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import type { Locator } from "@vitest/browser/context";
4
2
  import { createRawSnippet } from "svelte";
5
3
  import type { ComponentProps } from "svelte";
@@ -1,5 +1,3 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
1
  import type { SvelteHTMLElements } from "svelte/elements";
4
2
 
5
3
  /*
@@ -1,16 +0,0 @@
1
- /* Generated by <%= generatorName %> v<%= version %> */
2
-
3
- :host {
4
- /*
5
- * Declare component-scoped CSS variables here.
6
- * Variables must be on :host to be accessible inside the shadow tree.
7
- *
8
- * Example:
9
- * --<%= kebabName %>-color-background: var(--color-background-default);
10
- * --<%= kebabName %>-color-text: var(--color-text-default);
11
- */
12
- }
13
-
14
- .ds.<%= kebabName %> {
15
- /* Component styles */
16
- }
@@ -1,29 +0,0 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
4
- import "./<%= name %>.js";
5
- import type <%= name %> from "./<%= name %>.js";
6
-
7
- describe("<%= name %> component", () => {
8
- let elem: <%= name %>;
9
-
10
- beforeEach(() => {
11
- elem = document.createElement("ds-<%= kebabName %>") as <%= name %>;
12
- document.body.appendChild(elem);
13
- });
14
-
15
- afterEach(() => {
16
- elem.remove();
17
- });
18
-
19
- it("should render component", async () => {
20
- await customElements.whenDefined("ds-<%= kebabName %>");
21
-
22
- const container = elem.shadowRoot?.querySelector(".ds.<%= kebabName %>");
23
- expect(container).toBeTruthy();
24
- });
25
-
26
- it("should have correct tag name", () => {
27
- expect(elem.tagName.toLowerCase()).toBe("ds-<%= kebabName %>");
28
- });
29
- });
@@ -1,8 +0,0 @@
1
- // Generated by <%= generatorName %> v<%= version %>
2
-
3
- /**
4
- * Props for the <%= name %> component.
5
- */
6
- export interface <%= name %>Props {
7
- // Define props specific to <%= name %> here
8
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Types for Lit web component generator
3
- */
4
-
5
- import type { BaseComponentAnswers } from "../shared/index.js";
6
-
7
- /** Web component generator answers - uses base answers only */
8
- export type WebComponentAnswers = BaseComponentAnswers;