@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.
- package/CHANGELOG.md +42 -0
- package/CONVENTIONS.md +184 -0
- package/README.md +5 -5
- package/package.json +14 -10
- package/src/{__tests__/generators.test.ts → index.test.ts} +179 -7
- package/src/index.ts +4 -4
- package/src/{webcomponents → lit}/generator.ts +33 -36
- package/src/lit/index.ts +6 -0
- package/src/lit/types.ts +8 -0
- package/src/react/generator.ts +9 -12
- package/src/react/index.ts +1 -1
- package/src/shared/createComponentPathPrompt.ts +28 -0
- package/src/shared/{template-context.ts → createTemplateContext.ts} +4 -4
- package/src/shared/file-operations/appendExportToParentIndex.test.ts +75 -0
- package/src/shared/{file-operations.ts → file-operations/appendExportToParentIndex.ts} +12 -11
- package/src/shared/file-operations/dryRunWithFileState.ts +28 -0
- package/src/shared/file-operations/index.ts +3 -0
- package/src/shared/file-operations/removeExportFromParentIndex.test.ts +52 -0
- package/src/shared/file-operations/removeExportFromParentIndex.ts +21 -0
- package/src/shared/file-operations/removeLineFromFile.test.ts +66 -0
- package/src/shared/file-operations/removeLineFromFile.ts +29 -0
- package/src/shared/index.ts +6 -5
- package/src/shared/sharedPrompts.ts +30 -0
- package/src/shared/string-helpers/getComponentName.test.ts +18 -0
- package/src/shared/string-helpers/getComponentName.ts +8 -0
- package/src/shared/string-helpers/getParentDir.test.ts +16 -0
- package/src/shared/string-helpers/getParentDir.ts +8 -0
- package/src/shared/string-helpers/index.ts +3 -0
- package/src/shared/types.ts +1 -1
- package/src/shared/validateComponentPath.test.ts +40 -0
- package/src/shared/{validation.ts → validateComponentPath.ts} +3 -13
- package/src/svelte/generator.ts +7 -10
- package/src/svelte/index.ts +1 -1
- package/src/templates/{webcomponents → lit}/component.ts.ejs +8 -10
- package/src/templates/{webcomponents → lit}/index.ts.ejs +0 -2
- package/src/templates/{webcomponents → lit}/stories.ts.ejs +3 -5
- package/src/templates/lit/styles.css.ejs +49 -0
- package/src/templates/lit/tests.ts.ejs +27 -0
- package/src/templates/lit/types.ts.ejs +6 -0
- package/src/templates/react/component.tsx.ejs +0 -2
- package/src/templates/react/index.ts.ejs +0 -2
- package/src/templates/react/ssr.test.tsx.ejs +0 -2
- package/src/templates/react/stories.tsx.ejs +1 -3
- package/src/templates/react/test.tsx.ejs +0 -2
- package/src/templates/react/types.ts.ejs +0 -2
- package/src/templates/shared/styles.css.ejs +0 -2
- package/src/templates/svelte/component.svelte.ejs +0 -2
- package/src/templates/svelte/index.ts.ejs +0 -2
- package/src/templates/svelte/ssr.test.ts.ejs +0 -2
- package/src/templates/svelte/stories.svelte.ejs +0 -1
- package/src/templates/svelte/stories.ts.ejs +0 -2
- package/src/templates/svelte/test.ts.ejs +0 -2
- package/src/templates/svelte/types.ts.ejs +0 -2
- package/src/testing/integration/generators-undo.test.ts +200 -0
- package/vitest.config.ts +12 -0
- package/src/shared/prompts.ts +0 -57
- package/src/shared/string-helpers.ts +0 -29
- package/src/templates/webcomponents/styles.css.ejs +0 -16
- package/src/templates/webcomponents/tests.ts.ejs +0 -29
- package/src/templates/webcomponents/types.ts.ejs +0 -8
- package/src/webcomponents/index.ts +0 -6
- package/src/webcomponents/types.ts +0 -8
package/vitest.config.ts
ADDED
|
@@ -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
|
+
});
|
package/src/shared/prompts.ts
DELETED
|
@@ -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
|
-
});
|