@canonical/summon-component 0.12.0 → 0.14.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/CHANGELOG.md +16 -0
- package/package.json +9 -7
- package/src/__tests__/generators.test.ts +13 -13
- package/src/shared/file-operations.ts +2 -2
- package/src/templates/react/component.tsx.ejs +9 -4
- package/src/templates/react/index.ts.ejs +2 -2
- package/src/templates/react/ssr.test.tsx.ejs +2 -2
- package/src/templates/react/stories.tsx.ejs +1 -1
- package/src/templates/react/test.tsx.ejs +3 -3
- package/src/templates/shared/styles.css.ejs +1 -1
- package/tsconfig.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.14.0](https://github.com/canonical/pragma/compare/v0.13.0...v0.14.0) (2026-02-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @canonical/summon-component
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [0.13.0](https://github.com/canonical/pragma/compare/v0.13.0-experimental.0...v0.13.0) (2026-02-10)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @canonical/summon-component
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [0.12.0](https://github.com/canonical/pragma/compare/v0.12.0-experimental.0...v0.12.0) (2026-02-06)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @canonical/summon-component
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/summon-component",
|
|
3
3
|
"description": "Component generators for Summon - React and Svelte component scaffolding",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.14.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"author": {
|
|
@@ -29,15 +29,17 @@
|
|
|
29
29
|
"test": "vitest run"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@biomejs/biome": "2.3.
|
|
33
|
-
"@canonical/biome-config": "^0.
|
|
34
|
-
"@canonical/typescript-config
|
|
35
|
-
"
|
|
32
|
+
"@biomejs/biome": "2.3.14",
|
|
33
|
+
"@canonical/biome-config": "^0.14.0",
|
|
34
|
+
"@canonical/typescript-config": "^0.14.0",
|
|
35
|
+
"@canonical/webarchitect": "^0.14.0",
|
|
36
|
+
"@types/bun": "^1.3.8",
|
|
37
|
+
"@types/node": "^24.10.13",
|
|
36
38
|
"typescript": "^5.9.3",
|
|
37
|
-
"vitest": "^
|
|
39
|
+
"vitest": "^4.0.18"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
40
42
|
"@canonical/summon": "^0.1.0"
|
|
41
43
|
},
|
|
42
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "3bcc701893d91c5b7d36454e0c00fb3b490f55cc"
|
|
43
45
|
}
|
|
@@ -66,7 +66,7 @@ describe("component/react generator", () => {
|
|
|
66
66
|
|
|
67
67
|
it("has examples", () => {
|
|
68
68
|
expect(generator.meta.examples).toBeDefined();
|
|
69
|
-
expect(generator.meta.examples
|
|
69
|
+
expect(generator.meta.examples?.length).toBeGreaterThan(0);
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -74,29 +74,29 @@ describe("component/react generator", () => {
|
|
|
74
74
|
it("has componentPath prompt", () => {
|
|
75
75
|
const prompt = generator.prompts.find((p) => p.name === "componentPath");
|
|
76
76
|
expect(prompt).toBeDefined();
|
|
77
|
-
expect(prompt
|
|
78
|
-
expect(prompt
|
|
77
|
+
expect(prompt?.type).toBe("text");
|
|
78
|
+
expect(prompt?.default).toBe("src/components/MyComponent");
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it("has withStyles prompt", () => {
|
|
82
82
|
const prompt = generator.prompts.find((p) => p.name === "withStyles");
|
|
83
83
|
expect(prompt).toBeDefined();
|
|
84
|
-
expect(prompt
|
|
85
|
-
expect(prompt
|
|
84
|
+
expect(prompt?.type).toBe("confirm");
|
|
85
|
+
expect(prompt?.default).toBe(true);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
it("has withStories prompt", () => {
|
|
89
89
|
const prompt = generator.prompts.find((p) => p.name === "withStories");
|
|
90
90
|
expect(prompt).toBeDefined();
|
|
91
|
-
expect(prompt
|
|
92
|
-
expect(prompt
|
|
91
|
+
expect(prompt?.type).toBe("confirm");
|
|
92
|
+
expect(prompt?.default).toBe(true);
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
it("has withSsrTests prompt", () => {
|
|
96
96
|
const prompt = generator.prompts.find((p) => p.name === "withSsrTests");
|
|
97
97
|
expect(prompt).toBeDefined();
|
|
98
|
-
expect(prompt
|
|
99
|
-
expect(prompt
|
|
98
|
+
expect(prompt?.type).toBe("confirm");
|
|
99
|
+
expect(prompt?.default).toBe(true);
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
@@ -202,7 +202,7 @@ describe("component/react generator", () => {
|
|
|
202
202
|
|
|
203
203
|
expect(parentIndex).toBeDefined();
|
|
204
204
|
const content = (parentIndex as { content: string }).content;
|
|
205
|
-
expect(content).toContain('export * from "./Card"');
|
|
205
|
+
expect(content).toContain('export * from "./Card/index.js"');
|
|
206
206
|
});
|
|
207
207
|
});
|
|
208
208
|
});
|
|
@@ -228,14 +228,14 @@ describe("component/svelte generator", () => {
|
|
|
228
228
|
it("has componentPath prompt with svelte default", () => {
|
|
229
229
|
const prompt = generator.prompts.find((p) => p.name === "componentPath");
|
|
230
230
|
expect(prompt).toBeDefined();
|
|
231
|
-
expect(prompt
|
|
231
|
+
expect(prompt?.default).toBe("src/lib/components/MyComponent");
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
it("has useTsStories prompt", () => {
|
|
235
235
|
const prompt = generator.prompts.find((p) => p.name === "useTsStories");
|
|
236
236
|
expect(prompt).toBeDefined();
|
|
237
|
-
expect(prompt
|
|
238
|
-
expect(prompt
|
|
237
|
+
expect(prompt?.type).toBe("confirm");
|
|
238
|
+
expect(prompt?.default).toBe(false);
|
|
239
239
|
});
|
|
240
240
|
});
|
|
241
241
|
|
|
@@ -22,13 +22,13 @@ export const appendExportToParentIndex = (
|
|
|
22
22
|
componentName: string,
|
|
23
23
|
): Task<void> => {
|
|
24
24
|
const indexPath = path.join(parentDir, "index.ts");
|
|
25
|
-
const exportLine = `export * from "./${componentName}";\n`;
|
|
25
|
+
const exportLine = `export * from "./${componentName}/index.js";\n`;
|
|
26
26
|
|
|
27
27
|
return ifElseM(
|
|
28
28
|
exists(indexPath),
|
|
29
29
|
// If exists, append (if not already exported)
|
|
30
30
|
flatMap(readFile(indexPath), (content) => {
|
|
31
|
-
if (content.includes(
|
|
31
|
+
if (content.includes(`./${componentName}`)) {
|
|
32
32
|
return pure(undefined); // Already exported
|
|
33
33
|
}
|
|
34
34
|
return appendFile(indexPath, exportLine);
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
// Generated by <%= generatorName %> v<%= version %>
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import type { <%= name %>Props } from "./types.js";
|
|
4
5
|
<% if (withStyles) { -%>
|
|
5
6
|
import "./styles.css";
|
|
6
7
|
<% } -%>
|
|
7
8
|
|
|
9
|
+
const componentCssClassName = "ds <%= kebabName %>";
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* <%= name %> component
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
const <%= name %> = ({
|
|
12
15
|
className,
|
|
13
16
|
children,
|
|
14
17
|
...props
|
|
15
|
-
}: <%= name %>Props):
|
|
18
|
+
}: <%= name %>Props): React.ReactElement => {
|
|
16
19
|
return (
|
|
17
20
|
<div
|
|
18
|
-
className={
|
|
21
|
+
className={[componentCssClassName, className].filter(Boolean).join(" ")}
|
|
19
22
|
{...props}
|
|
20
23
|
>
|
|
21
24
|
{children}
|
|
22
25
|
</div>
|
|
23
26
|
);
|
|
24
27
|
};
|
|
28
|
+
|
|
29
|
+
export default <%= name %>;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { renderToString } from "react-dom/server";
|
|
5
|
-
import
|
|
5
|
+
import <%= name %> from "./<%= name %>.js";
|
|
6
6
|
|
|
7
7
|
describe("<%= name %> SSR", () => {
|
|
8
8
|
it("renders without hydration errors", () => {
|
|
9
9
|
const html = renderToString(<<%= name %>>Test content</<%= name %>>);
|
|
10
10
|
expect(html).toContain("Test content");
|
|
11
|
-
expect(html).toContain("<%= kebabName %>");
|
|
11
|
+
expect(html).toContain("ds <%= kebabName %>");
|
|
12
12
|
});
|
|
13
13
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by <%= generatorName %> v<%= version %>
|
|
2
2
|
|
|
3
3
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
|
-
import
|
|
4
|
+
import <%= name %> from "./<%= name %>.js";
|
|
5
5
|
|
|
6
6
|
const meta: Meta<typeof <%= name %>> = {
|
|
7
7
|
title: "Components/<%= name %>",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { render, screen } from "@testing-library/react";
|
|
5
|
-
import
|
|
5
|
+
import <%= name %> from "./<%= name %>.js";
|
|
6
6
|
|
|
7
7
|
describe("<%= name %>", () => {
|
|
8
8
|
it("renders children", () => {
|
|
@@ -13,8 +13,8 @@ describe("<%= name %>", () => {
|
|
|
13
13
|
it("applies custom className", () => {
|
|
14
14
|
render(<<%= name %> className="custom-class">Content</<%= name %>>);
|
|
15
15
|
const element = screen.getByText("Content");
|
|
16
|
-
expect(element).
|
|
17
|
-
expect(element).
|
|
16
|
+
expect(element.className).toContain("ds <%= kebabName %>");
|
|
17
|
+
expect(element.className).toContain("custom-class");
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it("passes through additional props", () => {
|
package/tsconfig.json
CHANGED