@canonical/summon-component 0.29.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 (153) hide show
  1. package/README.md +14 -26
  2. package/{src/index.ts → dist/esm/index.js} +5 -8
  3. package/dist/esm/index.js.map +1 -0
  4. package/dist/esm/lit/generator.js +152 -0
  5. package/dist/esm/lit/generator.js.map +1 -0
  6. package/dist/esm/lit/index.js +5 -0
  7. package/dist/esm/lit/index.js.map +1 -0
  8. package/dist/esm/lit/types.js +5 -0
  9. package/dist/esm/lit/types.js.map +1 -0
  10. package/dist/esm/react/generator.js +129 -0
  11. package/dist/esm/react/generator.js.map +1 -0
  12. package/dist/esm/react/index.js +5 -0
  13. package/dist/esm/react/index.js.map +1 -0
  14. package/dist/esm/react/types.js +5 -0
  15. package/dist/esm/react/types.js.map +1 -0
  16. package/dist/esm/shared/createComponentPathPrompt.js +23 -0
  17. package/dist/esm/shared/createComponentPathPrompt.js.map +1 -0
  18. package/dist/esm/shared/createTemplateContext.js +20 -0
  19. package/dist/esm/shared/createTemplateContext.js.map +1 -0
  20. package/dist/esm/shared/file-operations/appendExportToParentIndex.js +25 -0
  21. package/dist/esm/shared/file-operations/appendExportToParentIndex.js.map +1 -0
  22. package/dist/esm/shared/file-operations/dryRunWithFileState.js +25 -0
  23. package/dist/esm/shared/file-operations/dryRunWithFileState.js.map +1 -0
  24. package/{src/shared/file-operations/index.ts → dist/esm/shared/file-operations/index.js} +1 -0
  25. package/dist/esm/shared/file-operations/index.js.map +1 -0
  26. package/dist/esm/shared/file-operations/removeExportFromParentIndex.js +13 -0
  27. package/dist/esm/shared/file-operations/removeExportFromParentIndex.js.map +1 -0
  28. package/dist/esm/shared/file-operations/removeLineFromFile.js +19 -0
  29. package/dist/esm/shared/file-operations/removeLineFromFile.js.map +1 -0
  30. package/dist/esm/shared/index.js +11 -0
  31. package/dist/esm/shared/index.js.map +1 -0
  32. package/dist/esm/shared/loadTemplate.js +56 -0
  33. package/dist/esm/shared/loadTemplate.js.map +1 -0
  34. package/dist/esm/shared/packageName.js +11 -0
  35. package/dist/esm/shared/packageName.js.map +1 -0
  36. package/dist/esm/shared/sharedPrompts.js +28 -0
  37. package/dist/esm/shared/sharedPrompts.js.map +1 -0
  38. package/dist/esm/shared/string-helpers/getComponentName.js +8 -0
  39. package/dist/esm/shared/string-helpers/getComponentName.js.map +1 -0
  40. package/dist/esm/shared/string-helpers/getParentDir.js +8 -0
  41. package/dist/esm/shared/string-helpers/getParentDir.js.map +1 -0
  42. package/{src/shared/string-helpers/index.ts → dist/esm/shared/string-helpers/index.js} +1 -0
  43. package/dist/esm/shared/string-helpers/index.js.map +1 -0
  44. package/dist/esm/shared/types.js +5 -0
  45. package/dist/esm/shared/types.js.map +1 -0
  46. package/dist/esm/shared/validateComponentPath.js +16 -0
  47. package/dist/esm/shared/validateComponentPath.js.map +1 -0
  48. package/dist/esm/svelte/generator.js +165 -0
  49. package/dist/esm/svelte/generator.js.map +1 -0
  50. package/dist/esm/svelte/index.js +5 -0
  51. package/dist/esm/svelte/index.js.map +1 -0
  52. package/dist/esm/svelte/types.js +5 -0
  53. package/dist/esm/svelte/types.js.map +1 -0
  54. package/dist/types/index.d.ts +87 -0
  55. package/dist/types/index.d.ts.map +1 -0
  56. package/dist/types/lit/generator.d.ts +52 -0
  57. package/dist/types/lit/generator.d.ts.map +1 -0
  58. package/{src/lit/index.ts → dist/types/lit/index.d.ts} +1 -1
  59. package/dist/types/lit/index.d.ts.map +1 -0
  60. package/{src/lit/types.ts → dist/types/lit/types.d.ts} +1 -2
  61. package/dist/types/lit/types.d.ts.map +1 -0
  62. package/dist/types/react/generator.d.ts +28 -0
  63. package/dist/types/react/generator.d.ts.map +1 -0
  64. package/{src/react/index.ts → dist/types/react/index.d.ts} +1 -1
  65. package/dist/types/react/index.d.ts.map +1 -0
  66. package/{src/react/types.ts → dist/types/react/types.d.ts} +1 -2
  67. package/dist/types/react/types.d.ts.map +1 -0
  68. package/dist/types/shared/createComponentPathPrompt.d.ts +12 -0
  69. package/dist/types/shared/createComponentPathPrompt.d.ts.map +1 -0
  70. package/dist/types/shared/createTemplateContext.d.ts +9 -0
  71. package/dist/types/shared/createTemplateContext.d.ts.map +1 -0
  72. package/dist/types/shared/file-operations/appendExportToParentIndex.d.ts +8 -0
  73. package/dist/types/shared/file-operations/appendExportToParentIndex.d.ts.map +1 -0
  74. package/dist/types/shared/file-operations/dryRunWithFileState.d.ts +7 -0
  75. package/dist/types/shared/file-operations/dryRunWithFileState.d.ts.map +1 -0
  76. package/dist/types/shared/file-operations/index.d.ts +4 -0
  77. package/dist/types/shared/file-operations/index.d.ts.map +1 -0
  78. package/dist/types/shared/file-operations/removeExportFromParentIndex.d.ts +7 -0
  79. package/dist/types/shared/file-operations/removeExportFromParentIndex.d.ts.map +1 -0
  80. package/dist/types/shared/file-operations/removeLineFromFile.d.ts +7 -0
  81. package/dist/types/shared/file-operations/removeLineFromFile.d.ts.map +1 -0
  82. package/{src/shared/index.ts → dist/types/shared/index.d.ts} +2 -1
  83. package/dist/types/shared/index.d.ts.map +1 -0
  84. package/dist/types/shared/loadTemplate.d.ts +20 -0
  85. package/dist/types/shared/loadTemplate.d.ts.map +1 -0
  86. package/dist/types/shared/packageName.d.ts +11 -0
  87. package/dist/types/shared/packageName.d.ts.map +1 -0
  88. package/dist/types/shared/sharedPrompts.d.ts +7 -0
  89. package/dist/types/shared/sharedPrompts.d.ts.map +1 -0
  90. package/{src/shared/string-helpers/getComponentName.ts → dist/types/shared/string-helpers/getComponentName.d.ts} +2 -5
  91. package/dist/types/shared/string-helpers/getComponentName.d.ts.map +1 -0
  92. package/{src/shared/string-helpers/getParentDir.ts → dist/types/shared/string-helpers/getParentDir.d.ts} +2 -5
  93. package/dist/types/shared/string-helpers/getParentDir.d.ts.map +1 -0
  94. package/dist/types/shared/string-helpers/index.d.ts +4 -0
  95. package/dist/types/shared/string-helpers/index.d.ts.map +1 -0
  96. package/dist/types/shared/types.d.ts +34 -0
  97. package/dist/types/shared/types.d.ts.map +1 -0
  98. package/dist/types/shared/validateComponentPath.d.ts +5 -0
  99. package/dist/types/shared/validateComponentPath.d.ts.map +1 -0
  100. package/dist/types/svelte/generator.d.ts +52 -0
  101. package/dist/types/svelte/generator.d.ts.map +1 -0
  102. package/{src/svelte/index.ts → dist/types/svelte/index.d.ts} +1 -1
  103. package/dist/types/svelte/index.d.ts.map +1 -0
  104. package/{src/svelte/types.ts → dist/types/svelte/types.d.ts} +3 -4
  105. package/dist/types/svelte/types.d.ts.map +1 -0
  106. package/package.json +21 -10
  107. package/CHANGELOG.md +0 -245
  108. package/CONVENTIONS.md +0 -184
  109. package/biome.json +0 -6
  110. package/src/index.test.ts +0 -514
  111. package/src/lit/generator.ts +0 -190
  112. package/src/react/generator.ts +0 -176
  113. package/src/shared/createComponentPathPrompt.ts +0 -28
  114. package/src/shared/createTemplateContext.ts +0 -29
  115. package/src/shared/file-operations/appendExportToParentIndex.test.ts +0 -82
  116. package/src/shared/file-operations/appendExportToParentIndex.ts +0 -40
  117. package/src/shared/file-operations/dryRunWithFileState.ts +0 -28
  118. package/src/shared/file-operations/removeExportFromParentIndex.test.ts +0 -52
  119. package/src/shared/file-operations/removeExportFromParentIndex.ts +0 -21
  120. package/src/shared/file-operations/removeLineFromFile.test.ts +0 -66
  121. package/src/shared/file-operations/removeLineFromFile.ts +0 -29
  122. package/src/shared/loadTemplate.test.ts +0 -100
  123. package/src/shared/loadTemplate.ts +0 -70
  124. package/src/shared/sharedPrompts.ts +0 -30
  125. package/src/shared/string-helpers/getComponentName.test.ts +0 -18
  126. package/src/shared/string-helpers/getParentDir.test.ts +0 -16
  127. package/src/shared/types.ts +0 -36
  128. package/src/shared/validateComponentPath.test.ts +0 -40
  129. package/src/shared/validateComponentPath.ts +0 -16
  130. package/src/svelte/generator.ts +0 -224
  131. package/src/testing/integration/generators-undo.test.ts +0 -200
  132. package/tsconfig.json +0 -9
  133. package/vitest.config.ts +0 -18
  134. /package/{src → dist/esm}/templates/lit/component.ts.ejs +0 -0
  135. /package/{src → dist/esm}/templates/lit/index.ts.ejs +0 -0
  136. /package/{src → dist/esm}/templates/lit/stories.ts.ejs +0 -0
  137. /package/{src → dist/esm}/templates/lit/styles.css.ejs +0 -0
  138. /package/{src → dist/esm}/templates/lit/tests.ts.ejs +0 -0
  139. /package/{src → dist/esm}/templates/lit/types.ts.ejs +0 -0
  140. /package/{src → dist/esm}/templates/react/component.tsx.ejs +0 -0
  141. /package/{src → dist/esm}/templates/react/index.ts.ejs +0 -0
  142. /package/{src → dist/esm}/templates/react/ssr.test.tsx.ejs +0 -0
  143. /package/{src → dist/esm}/templates/react/stories.tsx.ejs +0 -0
  144. /package/{src → dist/esm}/templates/react/test.tsx.ejs +0 -0
  145. /package/{src → dist/esm}/templates/react/types.ts.ejs +0 -0
  146. /package/{src → dist/esm}/templates/shared/styles.css.ejs +0 -0
  147. /package/{src → dist/esm}/templates/svelte/component.svelte.ejs +0 -0
  148. /package/{src → dist/esm}/templates/svelte/index.ts.ejs +0 -0
  149. /package/{src → dist/esm}/templates/svelte/ssr.test.ts.ejs +0 -0
  150. /package/{src → dist/esm}/templates/svelte/stories.svelte.ejs +0 -0
  151. /package/{src → dist/esm}/templates/svelte/stories.ts.ejs +0 -0
  152. /package/{src → dist/esm}/templates/svelte/test.ts.ejs +0 -0
  153. /package/{src → dist/esm}/templates/svelte/types.ts.ejs +0 -0
package/CONVENTIONS.md DELETED
@@ -1,184 +0,0 @@
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/biome.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": ["@canonical/biome-config"],
3
- "files": {
4
- "includes": ["generators"]
5
- }
6
- }
package/src/index.test.ts DELETED
@@ -1,514 +0,0 @@
1
- /**
2
- * Tests for @canonical/summon-component generators
3
- *
4
- * Uses dry-run to verify generator output without writing files.
5
- * Uses dryRunWith with ReadFile mock to test template rendering.
6
- */
7
-
8
- import * as fs from "node:fs";
9
- import { dryRun, dryRunWith, type Effect, type Task } from "@canonical/task";
10
- import { describe, expect, it } from "vitest";
11
- import { generators } from "./index.js";
12
-
13
- /**
14
- * Helper: dry-run with actual file reading for templates.
15
- * This allows testing template output without writing files.
16
- */
17
- const dryRunWithTemplates = <A>(task: Task<A>) => {
18
- const mocks = new Map<string, (effect: Effect) => unknown>([
19
- [
20
- "ReadFile",
21
- (effect) => {
22
- const e = effect as { path: string };
23
- // Actually read template files
24
- if (e.path.endsWith(".ejs")) {
25
- return fs.readFileSync(e.path, "utf-8");
26
- }
27
- return `[mock content of ${e.path}]`;
28
- },
29
- ],
30
- ]);
31
- return dryRunWith(task, mocks);
32
- };
33
-
34
- describe("generators barrel", () => {
35
- it("exports component/react generator", () => {
36
- expect(generators["component/react"]).toBeDefined();
37
- expect(generators["component/react"].meta.name).toBe("component/react");
38
- });
39
-
40
- it("exports component/svelte generator", () => {
41
- expect(generators["component/svelte"]).toBeDefined();
42
- expect(generators["component/svelte"].meta.name).toBe("component/svelte");
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
- });
49
- });
50
-
51
- describe("component/react generator", () => {
52
- const generator = generators["component/react"];
53
-
54
- describe("meta", () => {
55
- it("has correct name", () => {
56
- expect(generator.meta.name).toBe("component/react");
57
- });
58
-
59
- it("has description", () => {
60
- expect(generator.meta.description).toContain("React component");
61
- });
62
-
63
- it("has version", () => {
64
- expect(generator.meta.version).toBe("0.1.0");
65
- });
66
-
67
- it("has help text", () => {
68
- expect(generator.meta.help).toBeDefined();
69
- expect(generator.meta.help).toContain("TypeScript");
70
- });
71
-
72
- it("has examples", () => {
73
- expect(generator.meta.examples).toBeDefined();
74
- expect(generator.meta.examples?.length).toBeGreaterThan(0);
75
- });
76
- });
77
-
78
- describe("prompts", () => {
79
- it("has componentPath prompt", () => {
80
- const prompt = generator.prompts.find((p) => p.name === "componentPath");
81
- expect(prompt).toBeDefined();
82
- expect(prompt?.type).toBe("text");
83
- expect(prompt?.default).toBe("src/components/MyComponent");
84
- });
85
-
86
- it("has withStyles prompt", () => {
87
- const prompt = generator.prompts.find((p) => p.name === "withStyles");
88
- expect(prompt).toBeDefined();
89
- expect(prompt?.type).toBe("confirm");
90
- expect(prompt?.default).toBe(true);
91
- });
92
-
93
- it("has withStories prompt", () => {
94
- const prompt = generator.prompts.find((p) => p.name === "withStories");
95
- expect(prompt).toBeDefined();
96
- expect(prompt?.type).toBe("confirm");
97
- expect(prompt?.default).toBe(true);
98
- });
99
-
100
- it("has withSsrTests prompt", () => {
101
- const prompt = generator.prompts.find((p) => p.name === "withSsrTests");
102
- expect(prompt).toBeDefined();
103
- expect(prompt?.type).toBe("confirm");
104
- expect(prompt?.default).toBe(true);
105
- });
106
- });
107
-
108
- describe("generate", () => {
109
- it("creates component files with all options enabled", () => {
110
- const task = generator.generate({
111
- componentPath: "src/components/Button",
112
- withStyles: true,
113
- withStories: true,
114
- withSsrTests: true,
115
- });
116
-
117
- const result = dryRun(task);
118
- const paths = result.effects
119
- .filter((e) => e._tag === "WriteFile")
120
- .map((e) => (e as { path: string }).path);
121
-
122
- expect(paths).toContain("src/components/Button/Button.tsx");
123
- expect(paths).toContain("src/components/Button/types.ts");
124
- expect(paths).toContain("src/components/Button/index.ts");
125
- expect(paths).toContain("src/components/Button/Button.tests.tsx");
126
- expect(paths).toContain("src/components/Button/Button.ssr.tests.tsx");
127
- expect(paths).toContain("src/components/Button/Button.stories.tsx");
128
- expect(paths).toContain("src/components/Button/styles.css");
129
- });
130
-
131
- it("creates minimal component without optional files", () => {
132
- const task = generator.generate({
133
- componentPath: "src/components/Icon",
134
- withStyles: false,
135
- withStories: false,
136
- withSsrTests: false,
137
- });
138
-
139
- const result = dryRun(task);
140
- const paths = result.effects
141
- .filter((e) => e._tag === "WriteFile")
142
- .map((e) => (e as { path: string }).path);
143
-
144
- expect(paths).toContain("src/components/Icon/Icon.tsx");
145
- expect(paths).toContain("src/components/Icon/types.ts");
146
- expect(paths).toContain("src/components/Icon/index.ts");
147
- expect(paths).toContain("src/components/Icon/Icon.tests.tsx");
148
- expect(paths).not.toContain("src/components/Icon/Icon.ssr.tests.tsx");
149
- expect(paths).not.toContain("src/components/Icon/Icon.stories.tsx");
150
- expect(paths).not.toContain("src/components/Icon/styles.css");
151
- });
152
-
153
- it("extracts component name from path", () => {
154
- const task = generator.generate({
155
- componentPath: "src/components/MyButton",
156
- withStyles: false,
157
- withStories: false,
158
- withSsrTests: false,
159
- });
160
-
161
- const result = dryRunWithTemplates(task);
162
- const mainFile = result.effects.find(
163
- (e) =>
164
- e._tag === "WriteFile" &&
165
- (e as { path: string }).path.endsWith("MyButton.tsx"),
166
- );
167
-
168
- expect(mainFile).toBeDefined();
169
- const content = (mainFile as { content: string }).content;
170
- expect(content).toContain("MyButton");
171
- expect(content).toContain("MyButtonProps");
172
- });
173
-
174
- it("generates kebab-case class name", () => {
175
- const task = generator.generate({
176
- componentPath: "src/components/MyButton",
177
- withStyles: false,
178
- withStories: false,
179
- withSsrTests: false,
180
- });
181
-
182
- const result = dryRunWithTemplates(task);
183
- const mainFile = result.effects.find(
184
- (e) =>
185
- e._tag === "WriteFile" &&
186
- (e as { path: string }).path.endsWith("MyButton.tsx"),
187
- );
188
-
189
- const content = (mainFile as { content: string }).content;
190
- expect(content).toContain("my-button");
191
- });
192
-
193
- it("appends export to parent index", () => {
194
- const task = generator.generate({
195
- componentPath: "src/components/Card",
196
- withStyles: false,
197
- withStories: false,
198
- withSsrTests: false,
199
- });
200
-
201
- const result = dryRun(task);
202
- const parentIndex = result.effects.find(
203
- (e) =>
204
- e._tag === "WriteFile" &&
205
- (e as { path: string }).path === "src/components/index.ts",
206
- );
207
-
208
- expect(parentIndex).toBeDefined();
209
- const content = (parentIndex as { content: string }).content;
210
- expect(content).toContain('export * from "./Card/index.js"');
211
- });
212
- });
213
- });
214
-
215
- describe("component/svelte generator", () => {
216
- const generator = generators["component/svelte"];
217
-
218
- describe("meta", () => {
219
- it("has correct name", () => {
220
- expect(generator.meta.name).toBe("component/svelte");
221
- });
222
-
223
- it("has description", () => {
224
- expect(generator.meta.description).toContain("Svelte");
225
- });
226
-
227
- it("has version", () => {
228
- expect(generator.meta.version).toBe("0.1.0");
229
- });
230
- });
231
-
232
- describe("prompts", () => {
233
- it("has componentPath prompt with svelte default", () => {
234
- const prompt = generator.prompts.find((p) => p.name === "componentPath");
235
- expect(prompt).toBeDefined();
236
- expect(prompt?.default).toBe("src/lib/components/MyComponent");
237
- });
238
-
239
- it("has useTsStories prompt", () => {
240
- const prompt = generator.prompts.find((p) => p.name === "useTsStories");
241
- expect(prompt).toBeDefined();
242
- expect(prompt?.type).toBe("confirm");
243
- expect(prompt?.default).toBe(false);
244
- });
245
-
246
- it("useTsStories prompt when condition checks withStories", () => {
247
- const prompt = generator.prompts.find((p) => p.name === "useTsStories");
248
- expect(
249
- prompt?.when?.({ withStories: true } as Record<string, unknown>),
250
- ).toBe(true);
251
- expect(
252
- prompt?.when?.({ withStories: false } as Record<string, unknown>),
253
- ).toBe(false);
254
- });
255
- });
256
-
257
- describe("generate", () => {
258
- it("creates svelte component files with all options", () => {
259
- const task = generator.generate({
260
- componentPath: "src/lib/components/Button",
261
- withStyles: true,
262
- withStories: true,
263
- useTsStories: false,
264
- withSsrTests: true,
265
- });
266
-
267
- const result = dryRun(task);
268
- const paths = result.effects
269
- .filter((e) => e._tag === "WriteFile")
270
- .map((e) => (e as { path: string }).path);
271
-
272
- expect(paths).toContain("src/lib/components/Button/Button.svelte");
273
- expect(paths).toContain("src/lib/components/Button/types.ts");
274
- expect(paths).toContain("src/lib/components/Button/index.ts");
275
- expect(paths).toContain(
276
- "src/lib/components/Button/Button.svelte.test.ts",
277
- );
278
- expect(paths).toContain("src/lib/components/Button/Button.ssr.test.ts");
279
- expect(paths).toContain(
280
- "src/lib/components/Button/Button.stories.svelte",
281
- );
282
- expect(paths).toContain("src/lib/components/Button/styles.css");
283
- });
284
-
285
- it("creates typescript stories when useTsStories is true", () => {
286
- const task = generator.generate({
287
- componentPath: "src/lib/components/Card",
288
- withStyles: false,
289
- withStories: true,
290
- useTsStories: true,
291
- withSsrTests: false,
292
- });
293
-
294
- const result = dryRun(task);
295
- const paths = result.effects
296
- .filter((e) => e._tag === "WriteFile")
297
- .map((e) => (e as { path: string }).path);
298
-
299
- expect(paths).toContain("src/lib/components/Card/Card.stories.ts");
300
- expect(paths).not.toContain(
301
- "src/lib/components/Card/Card.stories.svelte",
302
- );
303
- });
304
-
305
- it("generates svelte 5 runes syntax", () => {
306
- const task = generator.generate({
307
- componentPath: "src/lib/components/Toggle",
308
- withStyles: false,
309
- withStories: false,
310
- useTsStories: false,
311
- withSsrTests: false,
312
- });
313
-
314
- const result = dryRunWithTemplates(task);
315
- const mainFile = result.effects.find(
316
- (e) =>
317
- e._tag === "WriteFile" &&
318
- (e as { path: string }).path.endsWith("Toggle.svelte"),
319
- );
320
-
321
- const content = (mainFile as { content: string }).content;
322
- expect(content).toContain("$props()");
323
- expect(content).toContain("@render children");
324
- });
325
-
326
- it("imports styles.css when withStyles is enabled", () => {
327
- const task = generator.generate({
328
- componentPath: "src/lib/components/Banner",
329
- withStyles: true,
330
- withStories: false,
331
- useTsStories: false,
332
- withSsrTests: false,
333
- });
334
-
335
- const result = dryRunWithTemplates(task);
336
- const mainFile = result.effects.find(
337
- (e) =>
338
- e._tag === "WriteFile" &&
339
- (e as { path: string }).path.endsWith("Banner.svelte"),
340
- );
341
-
342
- const content = (mainFile as { content: string }).content;
343
- expect(content).toContain('import "./styles.css";');
344
- expect(content).not.toContain("<style>");
345
- });
346
- });
347
- });
348
-
349
- // =============================================================================
350
- // Lit Generator
351
- // =============================================================================
352
-
353
- describe("component/lit generator", () => {
354
- const generator = generators["component/lit"];
355
-
356
- describe("meta", () => {
357
- it("has correct name", () => {
358
- expect(generator.meta.name).toBe("component/lit");
359
- });
360
-
361
- it("has description containing Lit", () => {
362
- expect(generator.meta.description).toContain("Lit");
363
- });
364
-
365
- it("has version", () => {
366
- expect(generator.meta.version).toBe("0.1.0");
367
- });
368
-
369
- it("has help text mentioning decorators", () => {
370
- expect(generator.meta.help).toBeDefined();
371
- expect(generator.meta.help).toContain("decorators");
372
- });
373
-
374
- it("has examples", () => {
375
- expect(generator.meta.examples).toBeDefined();
376
- expect(generator.meta.examples?.length).toBeGreaterThan(0);
377
- });
378
- });
379
-
380
- describe("prompts", () => {
381
- it("has componentPath prompt with lib default path", () => {
382
- const prompt = generator.prompts.find((p) => p.name === "componentPath");
383
- expect(prompt).toBeDefined();
384
- expect(prompt?.default).toBe("src/lib/components/MyComponent");
385
- });
386
-
387
- it("has withStyles prompt", () => {
388
- const prompt = generator.prompts.find((p) => p.name === "withStyles");
389
- expect(prompt).toBeDefined();
390
- expect(prompt?.type).toBe("confirm");
391
- expect(prompt?.default).toBe(true);
392
- });
393
-
394
- it("has withStories prompt", () => {
395
- const prompt = generator.prompts.find((p) => p.name === "withStories");
396
- expect(prompt).toBeDefined();
397
- expect(prompt?.type).toBe("confirm");
398
- expect(prompt?.default).toBe(true);
399
- });
400
-
401
- it("does not have withSsrTests prompt", () => {
402
- const prompt = generator.prompts.find((p) => p.name === "withSsrTests");
403
- expect(prompt).toBeUndefined();
404
- });
405
-
406
- it("does not have useTsStories prompt", () => {
407
- const prompt = generator.prompts.find((p) => p.name === "useTsStories");
408
- expect(prompt).toBeUndefined();
409
- });
410
- });
411
-
412
- describe("generate", () => {
413
- it("creates lit component files with all options enabled", () => {
414
- const task = generator.generate({
415
- componentPath: "src/lib/components/Button",
416
- withStyles: true,
417
- withStories: true,
418
- withSsrTests: false,
419
- });
420
-
421
- const result = dryRun(task);
422
- const paths = result.effects
423
- .filter((e) => e._tag === "WriteFile")
424
- .map((e) => (e as { path: string }).path);
425
-
426
- expect(paths).toContain("src/lib/components/Button/Button.ts");
427
- expect(paths).toContain("src/lib/components/Button/index.ts");
428
- expect(paths).toContain("src/lib/components/Button/types.ts");
429
- expect(paths).toContain("src/lib/components/Button/Button.tests.ts");
430
- expect(paths).toContain("src/lib/components/Button/Button.stories.ts");
431
- expect(paths).toContain("src/lib/components/Button/styles.css");
432
- });
433
-
434
- it("creates minimal component without optional files", () => {
435
- const task = generator.generate({
436
- componentPath: "src/lib/components/Icon",
437
- withStyles: false,
438
- withStories: false,
439
- withSsrTests: false,
440
- });
441
-
442
- const result = dryRun(task);
443
- const paths = result.effects
444
- .filter((e) => e._tag === "WriteFile")
445
- .map((e) => (e as { path: string }).path);
446
-
447
- expect(paths).toContain("src/lib/components/Icon/Icon.ts");
448
- expect(paths).toContain("src/lib/components/Icon/index.ts");
449
- expect(paths).toContain("src/lib/components/Icon/types.ts");
450
- expect(paths).toContain("src/lib/components/Icon/Icon.tests.ts");
451
- expect(paths).not.toContain("src/lib/components/Icon/Icon.stories.ts");
452
- expect(paths).not.toContain("src/lib/components/Icon/styles.css");
453
- });
454
-
455
- it("extracts component name from path", () => {
456
- const task = generator.generate({
457
- componentPath: "src/lib/components/MyButton",
458
- withStyles: false,
459
- withStories: false,
460
- withSsrTests: false,
461
- });
462
-
463
- const result = dryRunWithTemplates(task);
464
- const mainFile = result.effects.find(
465
- (e) =>
466
- e._tag === "WriteFile" &&
467
- (e as { path: string }).path.endsWith("MyButton.ts"),
468
- );
469
-
470
- expect(mainFile).toBeDefined();
471
- const content = (mainFile as { content: string }).content;
472
- expect(content).toContain("MyButton");
473
- });
474
-
475
- it("generates kebab-case tag name", () => {
476
- const task = generator.generate({
477
- componentPath: "src/lib/components/MyButton",
478
- withStyles: false,
479
- withStories: false,
480
- withSsrTests: false,
481
- });
482
-
483
- const result = dryRunWithTemplates(task);
484
- const mainFile = result.effects.find(
485
- (e) =>
486
- e._tag === "WriteFile" &&
487
- (e as { path: string }).path.endsWith("MyButton.ts"),
488
- );
489
-
490
- const content = (mainFile as { content: string }).content;
491
- expect(content).toContain("my-button");
492
- });
493
-
494
- it("appends export to parent index", () => {
495
- const task = generator.generate({
496
- componentPath: "src/lib/components/Card",
497
- withStyles: false,
498
- withStories: false,
499
- withSsrTests: false,
500
- });
501
-
502
- const result = dryRun(task);
503
- const parentIndex = result.effects.find(
504
- (e) =>
505
- e._tag === "WriteFile" &&
506
- (e as { path: string }).path === "src/lib/components/index.ts",
507
- );
508
-
509
- expect(parentIndex).toBeDefined();
510
- const content = (parentIndex as { content: string }).content;
511
- expect(content).toContain('export * from "./Card/index.js"');
512
- });
513
- });
514
- });