@canonical/summon-component 0.17.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/CONVENTIONS.md +184 -0
  3. package/README.md +5 -5
  4. package/package.json +14 -10
  5. package/src/{__tests__/generators.test.ts → index.test.ts} +179 -7
  6. package/src/index.ts +4 -4
  7. package/src/{webcomponents → lit}/generator.ts +33 -36
  8. package/src/lit/index.ts +6 -0
  9. package/src/lit/types.ts +8 -0
  10. package/src/react/generator.ts +9 -12
  11. package/src/react/index.ts +1 -1
  12. package/src/shared/createComponentPathPrompt.ts +28 -0
  13. package/src/shared/{template-context.ts → createTemplateContext.ts} +4 -4
  14. package/src/shared/file-operations/appendExportToParentIndex.test.ts +75 -0
  15. package/src/shared/{file-operations.ts → file-operations/appendExportToParentIndex.ts} +12 -11
  16. package/src/shared/file-operations/dryRunWithFileState.ts +28 -0
  17. package/src/shared/file-operations/index.ts +3 -0
  18. package/src/shared/file-operations/removeExportFromParentIndex.test.ts +52 -0
  19. package/src/shared/file-operations/removeExportFromParentIndex.ts +21 -0
  20. package/src/shared/file-operations/removeLineFromFile.test.ts +66 -0
  21. package/src/shared/file-operations/removeLineFromFile.ts +29 -0
  22. package/src/shared/index.ts +6 -5
  23. package/src/shared/sharedPrompts.ts +30 -0
  24. package/src/shared/string-helpers/getComponentName.test.ts +18 -0
  25. package/src/shared/string-helpers/getComponentName.ts +8 -0
  26. package/src/shared/string-helpers/getParentDir.test.ts +16 -0
  27. package/src/shared/string-helpers/getParentDir.ts +8 -0
  28. package/src/shared/string-helpers/index.ts +3 -0
  29. package/src/shared/types.ts +1 -1
  30. package/src/shared/validateComponentPath.test.ts +40 -0
  31. package/src/shared/{validation.ts → validateComponentPath.ts} +3 -13
  32. package/src/svelte/generator.ts +7 -10
  33. package/src/svelte/index.ts +1 -1
  34. package/src/templates/{webcomponents → lit}/component.ts.ejs +8 -10
  35. package/src/templates/{webcomponents → lit}/index.ts.ejs +0 -2
  36. package/src/templates/{webcomponents → lit}/stories.ts.ejs +3 -5
  37. package/src/templates/lit/styles.css.ejs +49 -0
  38. package/src/templates/lit/tests.ts.ejs +27 -0
  39. package/src/templates/lit/types.ts.ejs +6 -0
  40. package/src/templates/react/component.tsx.ejs +0 -2
  41. package/src/templates/react/index.ts.ejs +0 -2
  42. package/src/templates/react/ssr.test.tsx.ejs +0 -2
  43. package/src/templates/react/stories.tsx.ejs +1 -3
  44. package/src/templates/react/test.tsx.ejs +0 -2
  45. package/src/templates/react/types.ts.ejs +0 -2
  46. package/src/templates/shared/styles.css.ejs +0 -2
  47. package/src/templates/svelte/component.svelte.ejs +0 -2
  48. package/src/templates/svelte/index.ts.ejs +0 -2
  49. package/src/templates/svelte/ssr.test.ts.ejs +0 -2
  50. package/src/templates/svelte/stories.svelte.ejs +0 -1
  51. package/src/templates/svelte/stories.ts.ejs +0 -2
  52. package/src/templates/svelte/test.ts.ejs +0 -2
  53. package/src/templates/svelte/types.ts.ejs +0 -2
  54. package/src/testing/integration/generators-undo.test.ts +200 -0
  55. package/vitest.config.ts +12 -0
  56. package/src/shared/prompts.ts +0 -57
  57. package/src/shared/string-helpers.ts +0 -29
  58. package/src/templates/webcomponents/styles.css.ejs +0 -16
  59. package/src/templates/webcomponents/tests.ts.ejs +0 -29
  60. package/src/templates/webcomponents/types.ts.ejs +0 -8
  61. package/src/webcomponents/index.ts +0 -6
  62. package/src/webcomponents/types.ts +0 -8
@@ -0,0 +1,12 @@
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"],
10
+ },
11
+ },
12
+ });
@@ -1,57 +0,0 @@
1
- /**
2
- * Shared prompt definitions for component generators
3
- */
4
-
5
- import type { PromptDefinition } from "@canonical/summon";
6
- import type { Framework } from "./types.js";
7
- import { validateComponentPath } from "./validation.js";
8
-
9
- /**
10
- * Create component path prompt with framework-specific defaults.
11
- *
12
- * This prompt is marked as positional, allowing users to run:
13
- * summon component react src/components/Button
14
- * instead of:
15
- * summon component react --component-path=src/components/Button
16
- */
17
- export const createComponentPathPrompt = (
18
- framework: Framework,
19
- ): PromptDefinition => ({
20
- name: "componentPath",
21
- type: "text",
22
- message: "Component path:",
23
- default:
24
- framework === "react"
25
- ? "src/components/MyComponent"
26
- : "src/lib/components/MyComponent",
27
- validate: validateComponentPath,
28
- group: "Component",
29
- positional: true,
30
- });
31
-
32
- /**
33
- * Shared prompts for both frameworks
34
- */
35
- export const sharedPrompts: PromptDefinition[] = [
36
- {
37
- name: "withStyles",
38
- type: "confirm",
39
- message: "Include styles?",
40
- default: true,
41
- group: "Options",
42
- },
43
- {
44
- name: "withStories",
45
- type: "confirm",
46
- message: "Include Storybook stories?",
47
- default: true,
48
- group: "Options",
49
- },
50
- {
51
- name: "withSsrTests",
52
- type: "confirm",
53
- message: "Include SSR tests?",
54
- default: true,
55
- group: "Options",
56
- },
57
- ];
@@ -1,29 +0,0 @@
1
- /**
2
- * String manipulation utilities for component generators
3
- */
4
-
5
- import * as path from "node:path";
6
-
7
- /**
8
- * Convert PascalCase to kebab-case
9
- */
10
- export const kebabCase = (str: string): string => {
11
- return str
12
- .replace(/([a-z])([A-Z])/g, "$1-$2")
13
- .replace(/([A-Z])([A-Z][a-z])/g, "$1-$2")
14
- .toLowerCase();
15
- };
16
-
17
- /**
18
- * Extract component name from path
19
- */
20
- export const getComponentName = (componentPath: string): string => {
21
- return path.basename(componentPath);
22
- };
23
-
24
- /**
25
- * Get parent directory of component
26
- */
27
- export const getParentDir = (componentPath: string): string => {
28
- return path.dirname(componentPath);
29
- };
@@ -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,6 +0,0 @@
1
- /**
2
- * Lit Web Component Generator - Barrel export
3
- */
4
-
5
- export { generator } from "./generator.js";
6
- export type { WebComponentAnswers } from "./types.js";
@@ -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;