@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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load a template file eagerly, with compiled binary support.
|
|
3
|
+
*
|
|
4
|
+
* In interpreted mode, reads from the filesystem. In a compiled binary,
|
|
5
|
+
* falls back to `Bun.embeddedFiles` blobs (async, requires top-level await).
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
/**
|
|
9
|
+
* Load a template from disk or embedded files.
|
|
10
|
+
*
|
|
11
|
+
* @param source - Absolute path to the template file.
|
|
12
|
+
* @returns Loaded template with path and content.
|
|
13
|
+
*/
|
|
14
|
+
export default async function loadTemplate(source) {
|
|
15
|
+
// Try filesystem first (works in interpreted mode)
|
|
16
|
+
try {
|
|
17
|
+
return { source, content: readFileSync(source, "utf-8") };
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Fall through to embedded lookup
|
|
21
|
+
}
|
|
22
|
+
// Try Bun.embeddedFiles (works in compiled binary)
|
|
23
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
24
|
+
const blobs = globalThis.Bun
|
|
25
|
+
.embeddedFiles;
|
|
26
|
+
if (blobs) {
|
|
27
|
+
// KNOWN LIMITATION (basename collision): we match embedded blobs by
|
|
28
|
+
// basename only, because Bun flattens embedded-asset names to the
|
|
29
|
+
// filename (the source directory is not preserved). Several templates
|
|
30
|
+
// share a basename across frameworks — types.ts.ejs, index.ts.ejs,
|
|
31
|
+
// styles.css.ejs and stories.ts.ejs each exist in lit/, react/ and/or
|
|
32
|
+
// svelte/. In a compiled binary this can resolve to the WRONG
|
|
33
|
+
// framework's template (whichever blob is encountered first), producing
|
|
34
|
+
// a silently incorrect generated file. The proper fix is build-side:
|
|
35
|
+
// embed templates under directory-qualified unique names and match on
|
|
36
|
+
// those. Deferred — needs verification against a real compiled binary
|
|
37
|
+
// (see pragma-adrs/session/J.CLI_MCP_FINISH.md). Interpreted mode (the
|
|
38
|
+
// common path) reads from disk above and is unaffected.
|
|
39
|
+
const basename = source.slice(source.lastIndexOf("/") + 1);
|
|
40
|
+
for (const blob of blobs) {
|
|
41
|
+
const dehashed = blob.name.replace(/-[a-z0-9]+\./, ".");
|
|
42
|
+
if (dehashed === basename) {
|
|
43
|
+
const content = await blob.text();
|
|
44
|
+
return { source, content };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Neither the filesystem nor embedded files yielded the template. Fail loud
|
|
50
|
+
// rather than returning empty content: callers await this for required
|
|
51
|
+
// templates and do not guard against blanks, so a silent "" would generate
|
|
52
|
+
// empty files (notably in a compiled binary, where the disk read always
|
|
53
|
+
// fails and a missing embed is the only failure mode).
|
|
54
|
+
throw new Error(`Template not found: ${source} (not on disk, and no matching embedded file).`);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=loadTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadTemplate.js","sourceRoot":"","sources":["../../../src/shared/loadTemplate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC;;;;;GAKG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
|
2
|
+
* The published package name, used in generator `displayName` labels.
|
|
3
|
+
*
|
|
4
|
+
* Kept as a plain constant rather than a `package.json` JSON import: the import
|
|
5
|
+
* path (`../../package.json`) is relative to the source file, but after the
|
|
6
|
+
* `src → dist/esm` build it would resolve one level too shallow (`dist/` instead
|
|
7
|
+
* of the package root), breaking at runtime under Node. A constant sidesteps the
|
|
8
|
+
* build-layout coupling entirely.
|
|
9
|
+
*/
|
|
10
|
+
export const PACKAGE_NAME = "@canonical/summon-component";
|
|
11
|
+
//# sourceMappingURL=packageName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageName.js","sourceRoot":"","sources":["../../../src/shared/packageName.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared prompts for component generators (styles, stories, SSR tests)
|
|
3
|
+
*/
|
|
4
|
+
const sharedPrompts = [
|
|
5
|
+
{
|
|
6
|
+
name: "withStyles",
|
|
7
|
+
type: "confirm",
|
|
8
|
+
message: "Include styles?",
|
|
9
|
+
default: true,
|
|
10
|
+
group: "Options",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "withStories",
|
|
14
|
+
type: "confirm",
|
|
15
|
+
message: "Include Storybook stories?",
|
|
16
|
+
default: true,
|
|
17
|
+
group: "Options",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "withSsrTests",
|
|
21
|
+
type: "confirm",
|
|
22
|
+
message: "Include SSR tests?",
|
|
23
|
+
default: true,
|
|
24
|
+
group: "Options",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
export default sharedPrompts;
|
|
28
|
+
//# sourceMappingURL=sharedPrompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedPrompts.js","sourceRoot":"","sources":["../../../src/shared/sharedPrompts.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,aAAa,GAAuB;IACxC;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,iBAAiB;QAC1B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,4BAA4B;QACrC,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getComponentName.js","sourceRoot":"","sources":["../../../../src/shared/string-helpers/getComponentName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,aAAqB;IAC5D,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getParentDir.js","sourceRoot":"","sources":["../../../../src/shared/string-helpers/getParentDir.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,aAAqB;IACxD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/shared/string-helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { isPascalCase } from "./string-helpers/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validate component path
|
|
5
|
+
*/
|
|
6
|
+
export default function validateComponentPath(value) {
|
|
7
|
+
if (!value || typeof value !== "string") {
|
|
8
|
+
return "Component path is required";
|
|
9
|
+
}
|
|
10
|
+
const name = path.basename(value);
|
|
11
|
+
if (!isPascalCase(name)) {
|
|
12
|
+
return "Component name must be in PascalCase (e.g., MyComponent)";
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=validateComponentPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateComponentPath.js","sourceRoot":"","sources":["../../../src/shared/validateComponentPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAc;IAC1D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,4BAA4B,CAAC;IACtC,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,0DAA0D,CAAC;IACpE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte Component Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates a Svelte 5 component with a consistent file structure:
|
|
5
|
+
* - `ComponentName.svelte` - Main component file with Svelte 5 runes ($props)
|
|
6
|
+
* - `types.ts` - TypeScript types and props interface
|
|
7
|
+
* - `index.ts` - Barrel export
|
|
8
|
+
* - `ComponentName.svelte.test.ts` - Unit tests with @testing-library/svelte
|
|
9
|
+
* - `ComponentName.ssr.test.ts` - SSR tests (optional)
|
|
10
|
+
* - `ComponentName.stories.svelte` - Svelte CSF stories (optional)
|
|
11
|
+
* - `ComponentName.stories.ts` - TypeScript stories (optional, alternative to Svelte CSF)
|
|
12
|
+
* - `styles.css` - CSS styles (optional)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```bash
|
|
16
|
+
* summon component svelte --component-path=src/lib/components/Button
|
|
17
|
+
* summon component svelte --component-path=src/lib/components/Card --with-stories
|
|
18
|
+
* summon component svelte --component-path=src/lib/components/Modal --with-stories --use-ts-stories
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
import * as path from "node:path";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
import { template } from "@canonical/summon-core";
|
|
26
|
+
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
27
|
+
import { appendExportToParentIndex, createComponentPathPrompt, createTemplateContext, getComponentName, getParentDir, PACKAGE_NAME, sharedPrompts, } from "../shared/index.js";
|
|
28
|
+
import loadTemplate from "../shared/loadTemplate.js";
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// Template Paths & Content (loaded eagerly via top-level await)
|
|
31
|
+
// =============================================================================
|
|
32
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const templatesDir = path.join(__dirname, "..", "templates");
|
|
34
|
+
const svelteTemplates = {
|
|
35
|
+
component: await loadTemplate(path.join(templatesDir, "svelte", "component.svelte.ejs")),
|
|
36
|
+
types: await loadTemplate(path.join(templatesDir, "svelte", "types.ts.ejs")),
|
|
37
|
+
index: await loadTemplate(path.join(templatesDir, "svelte", "index.ts.ejs")),
|
|
38
|
+
test: await loadTemplate(path.join(templatesDir, "svelte", "test.ts.ejs")),
|
|
39
|
+
ssrTest: await loadTemplate(path.join(templatesDir, "svelte", "ssr.test.ts.ejs")),
|
|
40
|
+
storiesSvelte: await loadTemplate(path.join(templatesDir, "svelte", "stories.svelte.ejs")),
|
|
41
|
+
storiesTs: await loadTemplate(path.join(templatesDir, "svelte", "stories.ts.ejs")),
|
|
42
|
+
styles: await loadTemplate(path.join(templatesDir, "shared", "styles.css.ejs")),
|
|
43
|
+
};
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Generator Definition
|
|
46
|
+
// =============================================================================
|
|
47
|
+
/**
|
|
48
|
+
* Svelte component generator definition.
|
|
49
|
+
*
|
|
50
|
+
* This generator creates a complete Svelte 5 component with TypeScript support,
|
|
51
|
+
* runes ($props), testing infrastructure, and optional Storybook stories.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://summon.dev/generators/component/svelte} for documentation
|
|
54
|
+
*/
|
|
55
|
+
const generator = {
|
|
56
|
+
meta: {
|
|
57
|
+
name: "component/svelte",
|
|
58
|
+
displayName: `${PACKAGE_NAME}:svelte`,
|
|
59
|
+
description: "Generate a Svelte 5 component with TypeScript, tests, stories, and styles",
|
|
60
|
+
version: "0.1.0",
|
|
61
|
+
help: `Generate a Svelte 5 component with TypeScript, tests, stories, and styles.
|
|
62
|
+
|
|
63
|
+
FEATURES:
|
|
64
|
+
- Svelte 5 with runes ($props)
|
|
65
|
+
- TypeScript types and props interface
|
|
66
|
+
- Unit tests with @testing-library/svelte
|
|
67
|
+
- Storybook integration (Svelte CSF or TypeScript)
|
|
68
|
+
- CSS styles (optional)
|
|
69
|
+
- SSR tests (optional)
|
|
70
|
+
- Auto-export from parent index.ts
|
|
71
|
+
|
|
72
|
+
The component name is extracted from the path and must be PascalCase.
|
|
73
|
+
For example, 'src/lib/components/Button' creates a 'Button' component.`,
|
|
74
|
+
examples: [
|
|
75
|
+
"summon component svelte --component-path=src/lib/components/Button",
|
|
76
|
+
"summon component svelte --component-path=src/lib/components/Card --with-styles --with-stories",
|
|
77
|
+
"summon component svelte --component-path=src/lib/components/Modal --with-stories --use-ts-stories",
|
|
78
|
+
"summon component svelte --component-path=src/lib/components/Button --dry-run",
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
prompts: [
|
|
82
|
+
createComponentPathPrompt("svelte"),
|
|
83
|
+
...sharedPrompts,
|
|
84
|
+
{
|
|
85
|
+
name: "useTsStories",
|
|
86
|
+
type: "confirm",
|
|
87
|
+
message: "Use TypeScript stories format? (otherwise Svelte CSF)",
|
|
88
|
+
default: false,
|
|
89
|
+
when: (answers) => answers.withStories === true,
|
|
90
|
+
group: "Options",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
generate: (answers) => {
|
|
94
|
+
const componentName = getComponentName(answers.componentPath);
|
|
95
|
+
const componentDir = answers.componentPath;
|
|
96
|
+
const parentDir = getParentDir(answers.componentPath);
|
|
97
|
+
const ctx = createTemplateContext(answers, "svelte");
|
|
98
|
+
return sequence_([
|
|
99
|
+
info(`Generating Svelte component: ${componentName}`),
|
|
100
|
+
debug("Creating component directory"),
|
|
101
|
+
mkdir(componentDir),
|
|
102
|
+
debug("Creating main component file"),
|
|
103
|
+
template({
|
|
104
|
+
source: svelteTemplates.component.source,
|
|
105
|
+
content: svelteTemplates.component.content,
|
|
106
|
+
dest: path.join(componentDir, `${componentName}.svelte`),
|
|
107
|
+
vars: ctx,
|
|
108
|
+
}),
|
|
109
|
+
debug("Creating types file"),
|
|
110
|
+
template({
|
|
111
|
+
source: svelteTemplates.types.source,
|
|
112
|
+
content: svelteTemplates.types.content,
|
|
113
|
+
dest: path.join(componentDir, "types.ts"),
|
|
114
|
+
vars: ctx,
|
|
115
|
+
}),
|
|
116
|
+
debug("Creating index barrel file"),
|
|
117
|
+
template({
|
|
118
|
+
source: svelteTemplates.index.source,
|
|
119
|
+
content: svelteTemplates.index.content,
|
|
120
|
+
dest: path.join(componentDir, "index.ts"),
|
|
121
|
+
vars: ctx,
|
|
122
|
+
}),
|
|
123
|
+
debug("Creating test file"),
|
|
124
|
+
template({
|
|
125
|
+
source: svelteTemplates.test.source,
|
|
126
|
+
content: svelteTemplates.test.content,
|
|
127
|
+
dest: path.join(componentDir, `${componentName}.svelte.test.ts`),
|
|
128
|
+
vars: ctx,
|
|
129
|
+
}),
|
|
130
|
+
when(answers.withSsrTests, debug("Creating SSR test file")),
|
|
131
|
+
when(answers.withSsrTests, template({
|
|
132
|
+
source: svelteTemplates.ssrTest.source,
|
|
133
|
+
content: svelteTemplates.ssrTest.content,
|
|
134
|
+
dest: path.join(componentDir, `${componentName}.ssr.test.ts`),
|
|
135
|
+
vars: ctx,
|
|
136
|
+
})),
|
|
137
|
+
when(answers.withStories && !answers.useTsStories, debug("Creating Svelte CSF stories file")),
|
|
138
|
+
when(answers.withStories && !answers.useTsStories, template({
|
|
139
|
+
source: svelteTemplates.storiesSvelte.source,
|
|
140
|
+
content: svelteTemplates.storiesSvelte.content,
|
|
141
|
+
dest: path.join(componentDir, `${componentName}.stories.svelte`),
|
|
142
|
+
vars: ctx,
|
|
143
|
+
})),
|
|
144
|
+
when(answers.withStories && answers.useTsStories, debug("Creating TypeScript stories file")),
|
|
145
|
+
when(answers.withStories && answers.useTsStories, template({
|
|
146
|
+
source: svelteTemplates.storiesTs.source,
|
|
147
|
+
content: svelteTemplates.storiesTs.content,
|
|
148
|
+
dest: path.join(componentDir, `${componentName}.stories.ts`),
|
|
149
|
+
vars: ctx,
|
|
150
|
+
})),
|
|
151
|
+
when(answers.withStyles, debug("Creating styles file")),
|
|
152
|
+
when(answers.withStyles, template({
|
|
153
|
+
source: svelteTemplates.styles.source,
|
|
154
|
+
content: svelteTemplates.styles.content,
|
|
155
|
+
dest: path.join(componentDir, "styles.css"),
|
|
156
|
+
vars: ctx,
|
|
157
|
+
})),
|
|
158
|
+
debug("Updating parent index.ts with export"),
|
|
159
|
+
appendExportToParentIndex(parentDir, componentName),
|
|
160
|
+
info(`Created ${componentName} component at ${componentDir}`),
|
|
161
|
+
]);
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
export default generator;
|
|
165
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/svelte/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAA4B,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,2BAA2B,CAAC;AAGrD,gFAAgF;AAChF,gEAAgE;AAChE,gFAAgF;AAEhF,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAE7D,MAAM,eAAe,GAAG;IACtB,SAAS,EAAE,MAAM,YAAY,CAC3B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,sBA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AC,kCAAkC,CAAC,CAC1C;YACD,IAAI,CACF,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,YAAY,EAC3C,QAAQ,CAAC;gBACP,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,MAAM;gBACxC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,OAAO;gBAC1C,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,aAAa,aAAa,CAAC;gBAC5D,IAAI,EAAE,GAAG;aACV,CAAC,CACH;YAED,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;YACvD,IAAI,CACF,OAAO,CAAC,UAAU,EAClB,QAAQ,CAAC;gBACP,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM;gBACrC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,OAAO;gBACvC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC;gBAC3C,IAAI,EAAE,GAAG;aACV,CAAC,CACH;YAED,KAAK,CAAC,sCAAsC,CAAC;YAC7C,yBAAyB,CAAC,SAAS,EAAE,aAAa,CAAC;YAEnD,IAAI,CAAC,WAAW,aAAa,iBAAiB,YAAY,EAAE,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;CAC6D,CAAC;AAEjE,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/svelte/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/svelte/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @canonical/summon-component
|
|
3
|
+
*
|
|
4
|
+
* Component generators for Summon CLI.
|
|
5
|
+
*
|
|
6
|
+
* This package provides generators for creating React, Svelte, and Web Components
|
|
7
|
+
* with TypeScript, tests, stories, and styles.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```bash
|
|
11
|
+
* # Generate a React component
|
|
12
|
+
* summon component react --component-path=src/components/Button
|
|
13
|
+
*
|
|
14
|
+
* # Generate a Svelte component
|
|
15
|
+
* summon component svelte --component-path=src/lib/components/Button
|
|
16
|
+
*
|
|
17
|
+
* # Generate a Web Component
|
|
18
|
+
* summon component lit --component-path=src/lib/components/Button
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Registry of all component generators.
|
|
25
|
+
*
|
|
26
|
+
* Keys are command paths (e.g., "component/react") that map to the CLI command structure.
|
|
27
|
+
* Values are generator definitions that can be executed by Summon.
|
|
28
|
+
*/
|
|
29
|
+
export declare const generators: {
|
|
30
|
+
readonly "component/react": {
|
|
31
|
+
readonly meta: {
|
|
32
|
+
readonly name: "component/react";
|
|
33
|
+
readonly displayName: "@canonical/summon-component:react";
|
|
34
|
+
readonly description: "Generate a React component with TypeScript, tests, stories, and styles";
|
|
35
|
+
readonly version: "0.1.0";
|
|
36
|
+
readonly help: "Generate a React component with TypeScript, tests, stories, and styles.\n\nFEATURES:\n - TypeScript types and props interface\n - Unit tests with @testing-library/react\n - Storybook integration (optional)\n - CSS styles (optional)\n - SSR tests (optional)\n - Auto-export from parent index.ts\n\nThe component name is extracted from the path and must be PascalCase.\nFor example, 'src/components/Button' creates a 'Button' component.";
|
|
37
|
+
readonly examples: ["summon component react --component-path=src/components/Button", "summon component react --component-path=src/components/Card --with-styles --with-stories", "summon component react --component-path=src/components/Modal --no-with-ssr-tests", "summon component react --component-path=src/components/Button --dry-run"];
|
|
38
|
+
};
|
|
39
|
+
readonly prompts: [import("@canonical/summon-core").PromptDefinition, ...import("@canonical/summon-core").PromptDefinition[]];
|
|
40
|
+
readonly generate: (answers: import("./shared/types.js").BaseComponentAnswers) => import("@canonical/task").Task<void>;
|
|
41
|
+
};
|
|
42
|
+
readonly "component/svelte": {
|
|
43
|
+
readonly meta: {
|
|
44
|
+
readonly name: "component/svelte";
|
|
45
|
+
readonly displayName: "@canonical/summon-component:svelte";
|
|
46
|
+
readonly description: "Generate a Svelte 5 component with TypeScript, tests, stories, and styles";
|
|
47
|
+
readonly version: "0.1.0";
|
|
48
|
+
readonly help: "Generate a Svelte 5 component with TypeScript, tests, stories, and styles.\n\nFEATURES:\n - Svelte 5 with runes ($props)\n - TypeScript types and props interface\n - Unit tests with @testing-library/svelte\n - Storybook integration (Svelte CSF or TypeScript)\n - CSS styles (optional)\n - SSR tests (optional)\n - Auto-export from parent index.ts\n\nThe component name is extracted from the path and must be PascalCase.\nFor example, 'src/lib/components/Button' creates a 'Button' component.";
|
|
49
|
+
readonly examples: ["summon component svelte --component-path=src/lib/components/Button", "summon component svelte --component-path=src/lib/components/Card --with-styles --with-stories", "summon component svelte --component-path=src/lib/components/Modal --with-stories --use-ts-stories", "summon component svelte --component-path=src/lib/components/Button --dry-run"];
|
|
50
|
+
};
|
|
51
|
+
readonly prompts: [import("@canonical/summon-core").PromptDefinition, ...import("@canonical/summon-core").PromptDefinition[], {
|
|
52
|
+
readonly name: "useTsStories";
|
|
53
|
+
readonly type: "confirm";
|
|
54
|
+
readonly message: "Use TypeScript stories format? (otherwise Svelte CSF)";
|
|
55
|
+
readonly default: false;
|
|
56
|
+
readonly when: (answers: Record<string, unknown>) => boolean;
|
|
57
|
+
readonly group: "Options";
|
|
58
|
+
}];
|
|
59
|
+
readonly generate: (answers: import("./svelte/types.js").SvelteComponentAnswers) => import("@canonical/task").Task<void>;
|
|
60
|
+
};
|
|
61
|
+
readonly "component/lit": {
|
|
62
|
+
readonly meta: {
|
|
63
|
+
readonly name: "component/lit";
|
|
64
|
+
readonly displayName: "@canonical/summon-component:lit";
|
|
65
|
+
readonly description: "Generate a Lit web component with TypeScript, tests, stories, and styles";
|
|
66
|
+
readonly version: "0.1.0";
|
|
67
|
+
readonly help: "Generate a Lit web component with TypeScript, tests, stories, and styles.\n\nFEATURES:\n - Lit element with TypeScript decorators\n - Unit tests with Vitest and shadow DOM testing\n - Storybook integration with @storybook/web-components-vite (optional)\n - CSS styles (optional)\n - Auto-export from parent index.ts\n\nThe component name is extracted from the path and must be PascalCase.\nFor example, 'src/lib/components/Button' creates a 'Button' component\nwith the custom element tag 'button'.";
|
|
68
|
+
readonly examples: ["summon component lit --component-path=src/lib/components/Button", "summon component lit --component-path=src/lib/components/Card --with-styles --with-stories", "summon component lit --component-path=src/lib/components/Modal --no-with-styles", "summon component lit --component-path=src/lib/components/Button --dry-run"];
|
|
69
|
+
};
|
|
70
|
+
readonly prompts: [import("@canonical/summon-core").PromptDefinition, {
|
|
71
|
+
readonly name: "withStyles";
|
|
72
|
+
readonly type: "confirm";
|
|
73
|
+
readonly message: "Include styles?";
|
|
74
|
+
readonly default: true;
|
|
75
|
+
readonly group: "Options";
|
|
76
|
+
}, {
|
|
77
|
+
readonly name: "withStories";
|
|
78
|
+
readonly type: "confirm";
|
|
79
|
+
readonly message: "Include Storybook stories?";
|
|
80
|
+
readonly default: true;
|
|
81
|
+
readonly group: "Options";
|
|
82
|
+
}];
|
|
83
|
+
readonly generate: (answers: import("./shared/types.js").BaseComponentAnswers) => import("@canonical/task").Task<void>;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export default generators;
|
|
87
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAOH;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAI0B,CAAC;AAElD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Components Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates a Lit web component with a consistent file structure:
|
|
5
|
+
* - `ComponentName.ts` - Main component file (Lit element)
|
|
6
|
+
* - `index.ts` - Barrel export
|
|
7
|
+
* - `ComponentName.tests.ts` - Unit tests with Vitest
|
|
8
|
+
* - `ComponentName.stories.ts` - Storybook stories (optional)
|
|
9
|
+
* - `styles.css` - CSS styles (optional)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```bash
|
|
13
|
+
* summon component lit --component-path=src/lib/components/Button
|
|
14
|
+
* summon component lit --component-path=src/lib/components/Card --with-styles --with-stories
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Web components generator definition.
|
|
21
|
+
*
|
|
22
|
+
* This generator creates a complete Lit web component with TypeScript support,
|
|
23
|
+
* testing infrastructure, and optional Storybook stories and CSS styles.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://summon.dev/generators/component/lit} for documentation
|
|
26
|
+
*/
|
|
27
|
+
declare const generator: {
|
|
28
|
+
readonly meta: {
|
|
29
|
+
readonly name: "component/lit";
|
|
30
|
+
readonly displayName: "@canonical/summon-component:lit";
|
|
31
|
+
readonly description: "Generate a Lit web component with TypeScript, tests, stories, and styles";
|
|
32
|
+
readonly version: "0.1.0";
|
|
33
|
+
readonly help: "Generate a Lit web component with TypeScript, tests, stories, and styles.\n\nFEATURES:\n - Lit element with TypeScript decorators\n - Unit tests with Vitest and shadow DOM testing\n - Storybook integration with @storybook/web-components-vite (optional)\n - CSS styles (optional)\n - Auto-export from parent index.ts\n\nThe component name is extracted from the path and must be PascalCase.\nFor example, 'src/lib/components/Button' creates a 'Button' component\nwith the custom element tag 'button'.";
|
|
34
|
+
readonly examples: ["summon component lit --component-path=src/lib/components/Button", "summon component lit --component-path=src/lib/components/Card --with-styles --with-stories", "summon component lit --component-path=src/lib/components/Modal --no-with-styles", "summon component lit --component-path=src/lib/components/Button --dry-run"];
|
|
35
|
+
};
|
|
36
|
+
readonly prompts: [import("@canonical/summon-core").PromptDefinition, {
|
|
37
|
+
readonly name: "withStyles";
|
|
38
|
+
readonly type: "confirm";
|
|
39
|
+
readonly message: "Include styles?";
|
|
40
|
+
readonly default: true;
|
|
41
|
+
readonly group: "Options";
|
|
42
|
+
}, {
|
|
43
|
+
readonly name: "withStories";
|
|
44
|
+
readonly type: "confirm";
|
|
45
|
+
readonly message: "Include Storybook stories?";
|
|
46
|
+
readonly default: true;
|
|
47
|
+
readonly group: "Options";
|
|
48
|
+
}];
|
|
49
|
+
readonly generate: (answers: import("../shared/types.js").BaseComponentAnswers) => import("@canonical/task").Task<void>;
|
|
50
|
+
};
|
|
51
|
+
export default generator;
|
|
52
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/lit/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA6DH;;;;;;;GAOG;AACH,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;CAqGqC,CAAC;AAErD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lit/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types for Lit web component generator
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
import type { BaseComponentAnswers } from "../shared/index.js";
|
|
6
|
-
|
|
7
5
|
/** Lit web component generator answers - uses base answers only */
|
|
8
6
|
export type LitAnswers = BaseComponentAnswers;
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lit/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,mEAAmE;AACnE,MAAM,MAAM,UAAU,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Component Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates a React component with a consistent file structure:
|
|
5
|
+
* - `ComponentName.tsx` - Main component file
|
|
6
|
+
* - `types.ts` - TypeScript types and props interface
|
|
7
|
+
* - `index.ts` - Barrel export
|
|
8
|
+
* - `ComponentName.test.tsx` - Unit tests with @testing-library/react
|
|
9
|
+
* - `ComponentName.ssr.test.tsx` - SSR tests (optional)
|
|
10
|
+
* - `ComponentName.stories.tsx` - Storybook stories (optional)
|
|
11
|
+
* - `styles.css` - CSS styles (optional)
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
declare const generator: {
|
|
16
|
+
readonly meta: {
|
|
17
|
+
readonly name: "component/react";
|
|
18
|
+
readonly displayName: "@canonical/summon-component:react";
|
|
19
|
+
readonly description: "Generate a React component with TypeScript, tests, stories, and styles";
|
|
20
|
+
readonly version: "0.1.0";
|
|
21
|
+
readonly help: "Generate a React component with TypeScript, tests, stories, and styles.\n\nFEATURES:\n - TypeScript types and props interface\n - Unit tests with @testing-library/react\n - Storybook integration (optional)\n - CSS styles (optional)\n - SSR tests (optional)\n - Auto-export from parent index.ts\n\nThe component name is extracted from the path and must be PascalCase.\nFor example, 'src/components/Button' creates a 'Button' component.";
|
|
22
|
+
readonly examples: ["summon component react --component-path=src/components/Button", "summon component react --component-path=src/components/Card --with-styles --with-stories", "summon component react --component-path=src/components/Modal --no-with-ssr-tests", "summon component react --component-path=src/components/Button --dry-run"];
|
|
23
|
+
};
|
|
24
|
+
readonly prompts: [import("@canonical/summon-core").PromptDefinition, ...import("@canonical/summon-core").PromptDefinition[]];
|
|
25
|
+
readonly generate: (answers: import("../shared/types.js").BaseComponentAnswers) => import("@canonical/task").Task<void>;
|
|
26
|
+
};
|
|
27
|
+
export default generator;
|
|
28
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/react/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgDH,QAAA,MAAM,SAAS;;;;;;;;;;;CAgHgD,CAAC;AAEhE,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types for React component generator
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
import type { BaseComponentAnswers } from "../shared/index.js";
|
|
6
|
-
|
|
7
5
|
/** React component generator answers - uses base answers only */
|
|
8
6
|
export type ReactComponentAnswers = BaseComponentAnswers;
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,iEAAiE;AACjE,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PromptDefinition } from "@canonical/summon-core";
|
|
2
|
+
import type { Framework } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create component path prompt with framework-specific defaults.
|
|
5
|
+
*
|
|
6
|
+
* This prompt is marked as positional, allowing users to run:
|
|
7
|
+
* summon component react src/components/Button
|
|
8
|
+
* instead of:
|
|
9
|
+
* summon component react --component-path=src/components/Button
|
|
10
|
+
*/
|
|
11
|
+
export default function createComponentPathPrompt(framework: Framework): PromptDefinition;
|
|
12
|
+
//# sourceMappingURL=createComponentPathPrompt.d.ts.map
|