@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.
- package/README.md +14 -26
- package/{src/index.ts → dist/esm/index.js} +5 -8
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lit/generator.js +152 -0
- package/dist/esm/lit/generator.js.map +1 -0
- package/dist/esm/lit/index.js +5 -0
- package/dist/esm/lit/index.js.map +1 -0
- package/dist/esm/lit/types.js +5 -0
- package/dist/esm/lit/types.js.map +1 -0
- package/dist/esm/react/generator.js +129 -0
- package/dist/esm/react/generator.js.map +1 -0
- package/dist/esm/react/index.js +5 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/esm/react/types.js +5 -0
- package/dist/esm/react/types.js.map +1 -0
- package/dist/esm/shared/createComponentPathPrompt.js +23 -0
- package/dist/esm/shared/createComponentPathPrompt.js.map +1 -0
- package/dist/esm/shared/createTemplateContext.js +20 -0
- package/dist/esm/shared/createTemplateContext.js.map +1 -0
- package/dist/esm/shared/file-operations/appendExportToParentIndex.js +25 -0
- package/dist/esm/shared/file-operations/appendExportToParentIndex.js.map +1 -0
- package/dist/esm/shared/file-operations/dryRunWithFileState.js +25 -0
- package/dist/esm/shared/file-operations/dryRunWithFileState.js.map +1 -0
- package/{src/shared/file-operations/index.ts → dist/esm/shared/file-operations/index.js} +1 -0
- package/dist/esm/shared/file-operations/index.js.map +1 -0
- package/dist/esm/shared/file-operations/removeExportFromParentIndex.js +13 -0
- package/dist/esm/shared/file-operations/removeExportFromParentIndex.js.map +1 -0
- package/dist/esm/shared/file-operations/removeLineFromFile.js +19 -0
- package/dist/esm/shared/file-operations/removeLineFromFile.js.map +1 -0
- package/dist/esm/shared/index.js +11 -0
- package/dist/esm/shared/index.js.map +1 -0
- package/dist/esm/shared/loadTemplate.js +56 -0
- package/dist/esm/shared/loadTemplate.js.map +1 -0
- package/dist/esm/shared/packageName.js +11 -0
- package/dist/esm/shared/packageName.js.map +1 -0
- package/dist/esm/shared/sharedPrompts.js +28 -0
- package/dist/esm/shared/sharedPrompts.js.map +1 -0
- package/dist/esm/shared/string-helpers/getComponentName.js +8 -0
- package/dist/esm/shared/string-helpers/getComponentName.js.map +1 -0
- package/dist/esm/shared/string-helpers/getParentDir.js +8 -0
- package/dist/esm/shared/string-helpers/getParentDir.js.map +1 -0
- package/{src/shared/string-helpers/index.ts → dist/esm/shared/string-helpers/index.js} +1 -0
- package/dist/esm/shared/string-helpers/index.js.map +1 -0
- package/dist/esm/shared/types.js +5 -0
- package/dist/esm/shared/types.js.map +1 -0
- package/dist/esm/shared/validateComponentPath.js +16 -0
- package/dist/esm/shared/validateComponentPath.js.map +1 -0
- package/dist/esm/svelte/generator.js +165 -0
- package/dist/esm/svelte/generator.js.map +1 -0
- package/dist/esm/svelte/index.js +5 -0
- package/dist/esm/svelte/index.js.map +1 -0
- package/dist/esm/svelte/types.js +5 -0
- package/dist/esm/svelte/types.js.map +1 -0
- package/dist/types/index.d.ts +87 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lit/generator.d.ts +52 -0
- package/dist/types/lit/generator.d.ts.map +1 -0
- package/{src/lit/index.ts → dist/types/lit/index.d.ts} +1 -1
- package/dist/types/lit/index.d.ts.map +1 -0
- package/{src/lit/types.ts → dist/types/lit/types.d.ts} +1 -2
- package/dist/types/lit/types.d.ts.map +1 -0
- package/dist/types/react/generator.d.ts +28 -0
- package/dist/types/react/generator.d.ts.map +1 -0
- package/{src/react/index.ts → dist/types/react/index.d.ts} +1 -1
- package/dist/types/react/index.d.ts.map +1 -0
- package/{src/react/types.ts → dist/types/react/types.d.ts} +1 -2
- package/dist/types/react/types.d.ts.map +1 -0
- package/dist/types/shared/createComponentPathPrompt.d.ts +12 -0
- package/dist/types/shared/createComponentPathPrompt.d.ts.map +1 -0
- package/dist/types/shared/createTemplateContext.d.ts +9 -0
- package/dist/types/shared/createTemplateContext.d.ts.map +1 -0
- package/dist/types/shared/file-operations/appendExportToParentIndex.d.ts +8 -0
- package/dist/types/shared/file-operations/appendExportToParentIndex.d.ts.map +1 -0
- package/dist/types/shared/file-operations/dryRunWithFileState.d.ts +7 -0
- package/dist/types/shared/file-operations/dryRunWithFileState.d.ts.map +1 -0
- package/dist/types/shared/file-operations/index.d.ts +4 -0
- package/dist/types/shared/file-operations/index.d.ts.map +1 -0
- package/dist/types/shared/file-operations/removeExportFromParentIndex.d.ts +7 -0
- package/dist/types/shared/file-operations/removeExportFromParentIndex.d.ts.map +1 -0
- package/dist/types/shared/file-operations/removeLineFromFile.d.ts +7 -0
- package/dist/types/shared/file-operations/removeLineFromFile.d.ts.map +1 -0
- package/{src/shared/index.ts → dist/types/shared/index.d.ts} +2 -1
- package/dist/types/shared/index.d.ts.map +1 -0
- package/dist/types/shared/loadTemplate.d.ts +20 -0
- package/dist/types/shared/loadTemplate.d.ts.map +1 -0
- package/dist/types/shared/packageName.d.ts +11 -0
- package/dist/types/shared/packageName.d.ts.map +1 -0
- package/dist/types/shared/sharedPrompts.d.ts +7 -0
- package/dist/types/shared/sharedPrompts.d.ts.map +1 -0
- package/{src/shared/string-helpers/getComponentName.ts → dist/types/shared/string-helpers/getComponentName.d.ts} +2 -5
- package/dist/types/shared/string-helpers/getComponentName.d.ts.map +1 -0
- package/{src/shared/string-helpers/getParentDir.ts → dist/types/shared/string-helpers/getParentDir.d.ts} +2 -5
- package/dist/types/shared/string-helpers/getParentDir.d.ts.map +1 -0
- package/dist/types/shared/string-helpers/index.d.ts +4 -0
- package/dist/types/shared/string-helpers/index.d.ts.map +1 -0
- package/dist/types/shared/types.d.ts +34 -0
- package/dist/types/shared/types.d.ts.map +1 -0
- package/dist/types/shared/validateComponentPath.d.ts +5 -0
- package/dist/types/shared/validateComponentPath.d.ts.map +1 -0
- package/dist/types/svelte/generator.d.ts +52 -0
- package/dist/types/svelte/generator.d.ts.map +1 -0
- package/{src/svelte/index.ts → dist/types/svelte/index.d.ts} +1 -1
- package/dist/types/svelte/index.d.ts.map +1 -0
- package/{src/svelte/types.ts → dist/types/svelte/types.d.ts} +3 -4
- package/dist/types/svelte/types.d.ts.map +1 -0
- package/package.json +21 -10
- package/CHANGELOG.md +0 -245
- package/CONVENTIONS.md +0 -184
- package/biome.json +0 -6
- package/src/index.test.ts +0 -514
- package/src/lit/generator.ts +0 -190
- package/src/react/generator.ts +0 -176
- package/src/shared/createComponentPathPrompt.ts +0 -28
- package/src/shared/createTemplateContext.ts +0 -29
- package/src/shared/file-operations/appendExportToParentIndex.test.ts +0 -82
- package/src/shared/file-operations/appendExportToParentIndex.ts +0 -40
- package/src/shared/file-operations/dryRunWithFileState.ts +0 -28
- package/src/shared/file-operations/removeExportFromParentIndex.test.ts +0 -52
- package/src/shared/file-operations/removeExportFromParentIndex.ts +0 -21
- package/src/shared/file-operations/removeLineFromFile.test.ts +0 -66
- package/src/shared/file-operations/removeLineFromFile.ts +0 -29
- package/src/shared/loadTemplate.test.ts +0 -100
- package/src/shared/loadTemplate.ts +0 -70
- package/src/shared/sharedPrompts.ts +0 -30
- package/src/shared/string-helpers/getComponentName.test.ts +0 -18
- package/src/shared/string-helpers/getParentDir.test.ts +0 -16
- package/src/shared/types.ts +0 -36
- package/src/shared/validateComponentPath.test.ts +0 -40
- package/src/shared/validateComponentPath.ts +0 -16
- package/src/svelte/generator.ts +0 -224
- package/src/testing/integration/generators-undo.test.ts +0 -200
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -18
- /package/{src → dist/esm}/templates/lit/component.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/lit/index.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/lit/stories.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/lit/styles.css.ejs +0 -0
- /package/{src → dist/esm}/templates/lit/tests.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/lit/types.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/react/component.tsx.ejs +0 -0
- /package/{src → dist/esm}/templates/react/index.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/react/ssr.test.tsx.ejs +0 -0
- /package/{src → dist/esm}/templates/react/stories.tsx.ejs +0 -0
- /package/{src → dist/esm}/templates/react/test.tsx.ejs +0 -0
- /package/{src → dist/esm}/templates/react/types.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/shared/styles.css.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/component.svelte.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/index.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/ssr.test.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/stories.svelte.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/stories.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/test.ts.ejs +0 -0
- /package/{src → dist/esm}/templates/svelte/types.ts.ejs +0 -0
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Undo integration tests for component generators
|
|
3
|
-
*
|
|
4
|
-
* Verifies that collectUndos produces correct undo plans for each generator.
|
|
5
|
-
* Each template() call produces 2 undos: mkdir(destDir) + writeFile(dest).
|
|
6
|
-
* Plus the generator's own mkdir(componentDir) and appendExportToParentIndex.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { collectUndos, dryRun } from "@canonical/task";
|
|
10
|
-
import { describe, expect, it } from "vitest";
|
|
11
|
-
import { generators } from "../../index.js";
|
|
12
|
-
|
|
13
|
-
// =============================================================================
|
|
14
|
-
// Helpers
|
|
15
|
-
// =============================================================================
|
|
16
|
-
|
|
17
|
-
/** Collect all undo effect tags from a generator task */
|
|
18
|
-
const getUndoEffectTags = (undos: ReturnType<typeof collectUndos>) =>
|
|
19
|
-
undos.flatMap((undo) => dryRun(undo).effects.map((e) => e._tag));
|
|
20
|
-
|
|
21
|
-
// =============================================================================
|
|
22
|
-
// React
|
|
23
|
-
// =============================================================================
|
|
24
|
-
|
|
25
|
-
describe("component/react undo plan", () => {
|
|
26
|
-
const generator = generators["component/react"];
|
|
27
|
-
|
|
28
|
-
it("produces undos for full component (all options)", () => {
|
|
29
|
-
const task = generator.generate({
|
|
30
|
-
componentPath: "src/components/Button",
|
|
31
|
-
withStyles: true,
|
|
32
|
-
withStories: true,
|
|
33
|
-
withSsrTests: true,
|
|
34
|
-
});
|
|
35
|
-
const undos = collectUndos(task);
|
|
36
|
-
|
|
37
|
-
// 1 mkdir(componentDir) + 7 templates × 2 + 1 appendExport(writeFile) = 16
|
|
38
|
-
expect(undos.length).toBeGreaterThan(0);
|
|
39
|
-
expect(undos.length).toBe(16);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("produces fewer undos for minimal component", () => {
|
|
43
|
-
const fullTask = generator.generate({
|
|
44
|
-
componentPath: "src/components/Button",
|
|
45
|
-
withStyles: true,
|
|
46
|
-
withStories: true,
|
|
47
|
-
withSsrTests: true,
|
|
48
|
-
});
|
|
49
|
-
const minTask = generator.generate({
|
|
50
|
-
componentPath: "src/components/Button",
|
|
51
|
-
withStyles: false,
|
|
52
|
-
withStories: false,
|
|
53
|
-
withSsrTests: false,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const fullUndos = collectUndos(fullTask);
|
|
57
|
-
const minUndos = collectUndos(minTask);
|
|
58
|
-
|
|
59
|
-
expect(minUndos.length).toBeLessThan(fullUndos.length);
|
|
60
|
-
// 1 mkdir + 4 templates × 2 + 1 appendExport = 10
|
|
61
|
-
expect(minUndos.length).toBe(10);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("undo effects are only DeleteFile and DeleteDirectory", () => {
|
|
65
|
-
const task = generator.generate({
|
|
66
|
-
componentPath: "src/components/Button",
|
|
67
|
-
withStyles: true,
|
|
68
|
-
withStories: true,
|
|
69
|
-
withSsrTests: true,
|
|
70
|
-
});
|
|
71
|
-
const undos = collectUndos(task);
|
|
72
|
-
const tags = getUndoEffectTags(undos);
|
|
73
|
-
|
|
74
|
-
for (const tag of tags) {
|
|
75
|
-
expect(["DeleteFile", "DeleteDirectory"]).toContain(tag);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("undo includes DeleteDirectory for component dir", () => {
|
|
80
|
-
const task = generator.generate({
|
|
81
|
-
componentPath: "src/components/Card",
|
|
82
|
-
withStyles: false,
|
|
83
|
-
withStories: false,
|
|
84
|
-
withSsrTests: false,
|
|
85
|
-
});
|
|
86
|
-
const undos = collectUndos(task);
|
|
87
|
-
|
|
88
|
-
// First undo should be the mkdir(componentDir) → DeleteDirectory
|
|
89
|
-
const firstUndoEffects = dryRun(undos[0]).effects;
|
|
90
|
-
expect(firstUndoEffects[0]._tag).toBe("DeleteDirectory");
|
|
91
|
-
expect((firstUndoEffects[0] as { path: string }).path).toBe(
|
|
92
|
-
"src/components/Card",
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// =============================================================================
|
|
98
|
-
// Svelte
|
|
99
|
-
// =============================================================================
|
|
100
|
-
|
|
101
|
-
describe("component/svelte undo plan", () => {
|
|
102
|
-
const generator = generators["component/svelte"];
|
|
103
|
-
|
|
104
|
-
it("produces undos for full component (all options)", () => {
|
|
105
|
-
const task = generator.generate({
|
|
106
|
-
componentPath: "src/lib/components/Button",
|
|
107
|
-
withStyles: true,
|
|
108
|
-
withStories: true,
|
|
109
|
-
useTsStories: false,
|
|
110
|
-
withSsrTests: true,
|
|
111
|
-
});
|
|
112
|
-
const undos = collectUndos(task);
|
|
113
|
-
|
|
114
|
-
// 1 mkdir + 7 templates × 2 + 1 appendExport = 16
|
|
115
|
-
expect(undos.length).toBe(16);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("TS stories and Svelte CSF stories produce same undo count", () => {
|
|
119
|
-
const svelteCSF = generator.generate({
|
|
120
|
-
componentPath: "src/lib/components/Button",
|
|
121
|
-
withStyles: false,
|
|
122
|
-
withStories: true,
|
|
123
|
-
useTsStories: false,
|
|
124
|
-
withSsrTests: false,
|
|
125
|
-
});
|
|
126
|
-
const tsStories = generator.generate({
|
|
127
|
-
componentPath: "src/lib/components/Button",
|
|
128
|
-
withStyles: false,
|
|
129
|
-
withStories: true,
|
|
130
|
-
useTsStories: true,
|
|
131
|
-
withSsrTests: false,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
expect(collectUndos(svelteCSF).length).toBe(collectUndos(tsStories).length);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("produces fewer undos for minimal component", () => {
|
|
138
|
-
const minTask = generator.generate({
|
|
139
|
-
componentPath: "src/lib/components/Button",
|
|
140
|
-
withStyles: false,
|
|
141
|
-
withStories: false,
|
|
142
|
-
useTsStories: false,
|
|
143
|
-
withSsrTests: false,
|
|
144
|
-
});
|
|
145
|
-
const minUndos = collectUndos(minTask);
|
|
146
|
-
|
|
147
|
-
// 1 mkdir + 4 templates × 2 + 1 appendExport = 10
|
|
148
|
-
expect(minUndos.length).toBe(10);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// =============================================================================
|
|
153
|
-
// Lit
|
|
154
|
-
// =============================================================================
|
|
155
|
-
|
|
156
|
-
describe("component/lit undo plan", () => {
|
|
157
|
-
const generator = generators["component/lit"];
|
|
158
|
-
|
|
159
|
-
it("produces undos for full component (all options)", () => {
|
|
160
|
-
const task = generator.generate({
|
|
161
|
-
componentPath: "src/lib/components/Button",
|
|
162
|
-
withStyles: true,
|
|
163
|
-
withStories: true,
|
|
164
|
-
withSsrTests: false,
|
|
165
|
-
});
|
|
166
|
-
const undos = collectUndos(task);
|
|
167
|
-
|
|
168
|
-
// 1 mkdir + 6 templates × 2 + 1 appendExport = 14
|
|
169
|
-
// (lit has: component, index, types, tests, stories, styles = 6 templates)
|
|
170
|
-
expect(undos.length).toBe(14);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("produces fewer undos for minimal component", () => {
|
|
174
|
-
const minTask = generator.generate({
|
|
175
|
-
componentPath: "src/lib/components/Button",
|
|
176
|
-
withStyles: false,
|
|
177
|
-
withStories: false,
|
|
178
|
-
withSsrTests: false,
|
|
179
|
-
});
|
|
180
|
-
const minUndos = collectUndos(minTask);
|
|
181
|
-
|
|
182
|
-
// 1 mkdir + 4 templates × 2 + 1 appendExport = 10
|
|
183
|
-
expect(minUndos.length).toBe(10);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("undo effects are only DeleteFile and DeleteDirectory", () => {
|
|
187
|
-
const task = generator.generate({
|
|
188
|
-
componentPath: "src/lib/components/Widget",
|
|
189
|
-
withStyles: true,
|
|
190
|
-
withStories: true,
|
|
191
|
-
withSsrTests: false,
|
|
192
|
-
});
|
|
193
|
-
const undos = collectUndos(task);
|
|
194
|
-
const tags = getUndoEffectTags(undos);
|
|
195
|
-
|
|
196
|
-
for (const tag of tags) {
|
|
197
|
-
expect(["DeleteFile", "DeleteDirectory"]).toContain(tag);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
package/tsconfig.json
DELETED
package/vitest.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
include: ["src/**/*.test.ts"],
|
|
6
|
-
coverage: {
|
|
7
|
-
provider: "v8",
|
|
8
|
-
include: ["src/**/*.ts"],
|
|
9
|
-
exclude: ["**/index.ts", "**/*.test.ts", "**/*.d.ts", "**/types.ts"],
|
|
10
|
-
thresholds: {
|
|
11
|
-
statements: 100,
|
|
12
|
-
branches: 100,
|
|
13
|
-
functions: 100,
|
|
14
|
-
lines: 100,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|