@canonical/summon-component 0.29.0-experimental.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 -237
- 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
package/README.md
CHANGED
|
@@ -14,23 +14,17 @@ Creating a new component by hand means creating 5-7 files with boilerplate that'
|
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Requires `@canonical/summon` as a peer dependency:
|
|
17
|
+
Install this package alongside the `@canonical/summon` CLI — summon
|
|
18
|
+
auto-discovers it and exposes `summon component react|svelte|lit`:
|
|
22
19
|
|
|
23
20
|
```bash
|
|
24
|
-
|
|
21
|
+
npm install -g @canonical/summon @canonical/summon-component
|
|
22
|
+
# or: bun add -g @canonical/summon @canonical/summon-component
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
cd /path/to/summon-component
|
|
31
|
-
bun link # for bun
|
|
32
|
-
npm link # for npm
|
|
33
|
-
```
|
|
25
|
+
The CLI runs under plain Node (no Bun required). Install both into the same
|
|
26
|
+
location (both global, or both as project dependencies) so discovery can find the
|
|
27
|
+
generators.
|
|
34
28
|
|
|
35
29
|
---
|
|
36
30
|
|
|
@@ -582,18 +576,12 @@ summon
|
|
|
582
576
|
# └─ react, svelte, lit
|
|
583
577
|
```
|
|
584
578
|
|
|
585
|
-
If not, verify
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
bun add @canonical/summon-component
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
### "Cannot find module @canonical/summon"
|
|
592
|
-
|
|
593
|
-
Install the peer dependency:
|
|
579
|
+
If not, verify both the CLI and this generator package are installed **into the
|
|
580
|
+
same location** (both global, or both project dependencies) — summon only
|
|
581
|
+
discovers generators it can resolve:
|
|
594
582
|
|
|
595
583
|
```bash
|
|
596
|
-
|
|
584
|
+
npm install -g @canonical/summon @canonical/summon-component
|
|
597
585
|
```
|
|
598
586
|
|
|
599
587
|
### Barrel file not updated
|
|
@@ -604,8 +592,8 @@ The generator appends to `{parentDir}/index.ts`. If your project uses a differen
|
|
|
604
592
|
|
|
605
593
|
## Related
|
|
606
594
|
|
|
607
|
-
- **[@canonical/summon](../
|
|
608
|
-
- **[@canonical/summon-package](../
|
|
595
|
+
- **[@canonical/summon-core](../core/)** — The generator framework (required peer dependency)
|
|
596
|
+
- **[@canonical/summon-package](../package/)** — Package scaffolding for the monorepo
|
|
609
597
|
|
|
610
598
|
---
|
|
611
599
|
|
|
@@ -645,7 +633,7 @@ Generated templates use generic patterns. For project-specific standards (CSS na
|
|
|
645
633
|
|
|
646
634
|
### Non-Interactive Environments
|
|
647
635
|
|
|
648
|
-
See [Summon How-To: Non-Interactive Usage](/
|
|
636
|
+
See [Summon How-To: Non-Interactive Usage](../core/docs/how-to.md#non-interactive--llm-usage) for CI/LLM usage patterns.
|
|
649
637
|
|
|
650
638
|
## License
|
|
651
639
|
|
|
@@ -20,12 +20,9 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @packageDocumentation
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
import type { AnyGenerator } from "@canonical/summon-core";
|
|
25
23
|
import { generator as litGenerator } from "./lit/index.js";
|
|
26
24
|
import { generator as reactGenerator } from "./react/index.js";
|
|
27
25
|
import { generator as svelteGenerator } from "./svelte/index.js";
|
|
28
|
-
|
|
29
26
|
/**
|
|
30
27
|
* Registry of all component generators.
|
|
31
28
|
*
|
|
@@ -33,9 +30,9 @@ import { generator as svelteGenerator } from "./svelte/index.js";
|
|
|
33
30
|
* Values are generator definitions that can be executed by Summon.
|
|
34
31
|
*/
|
|
35
32
|
export const generators = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
33
|
+
"component/react": reactGenerator,
|
|
34
|
+
"component/svelte": svelteGenerator,
|
|
35
|
+
"component/lit": litGenerator,
|
|
36
|
+
};
|
|
41
37
|
export default generators;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,iBAAiB,EAAE,cAAc;IACjC,kBAAkB,EAAE,eAAe;IACnC,eAAe,EAAE,YAAY;CACkB,CAAC;AAElD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
import * as path from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
import { template } from "@canonical/summon-core";
|
|
22
|
+
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
23
|
+
import { appendExportToParentIndex, createComponentPathPrompt, createTemplateContext, getComponentName, getParentDir, PACKAGE_NAME, } from "../shared/index.js";
|
|
24
|
+
import loadTemplate from "../shared/loadTemplate.js";
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// Template Paths & Content (loaded eagerly via top-level await)
|
|
27
|
+
// =============================================================================
|
|
28
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
const templatesDir = path.join(__dirname, "..", "templates");
|
|
30
|
+
const litTemplates = {
|
|
31
|
+
component: await loadTemplate(path.join(templatesDir, "lit", "component.ts.ejs")),
|
|
32
|
+
index: await loadTemplate(path.join(templatesDir, "lit", "index.ts.ejs")),
|
|
33
|
+
types: await loadTemplate(path.join(templatesDir, "lit", "types.ts.ejs")),
|
|
34
|
+
tests: await loadTemplate(path.join(templatesDir, "lit", "tests.ts.ejs")),
|
|
35
|
+
stories: await loadTemplate(path.join(templatesDir, "lit", "stories.ts.ejs")),
|
|
36
|
+
styles: await loadTemplate(path.join(templatesDir, "lit", "styles.css.ejs")),
|
|
37
|
+
};
|
|
38
|
+
// =============================================================================
|
|
39
|
+
// Custom Prompts (without SSR tests)
|
|
40
|
+
// =============================================================================
|
|
41
|
+
const litPrompts = [
|
|
42
|
+
{
|
|
43
|
+
name: "withStyles",
|
|
44
|
+
type: "confirm",
|
|
45
|
+
message: "Include styles?",
|
|
46
|
+
default: true,
|
|
47
|
+
group: "Options",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "withStories",
|
|
51
|
+
type: "confirm",
|
|
52
|
+
message: "Include Storybook stories?",
|
|
53
|
+
default: true,
|
|
54
|
+
group: "Options",
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
// =============================================================================
|
|
58
|
+
// Generator Definition
|
|
59
|
+
// =============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* Web components generator definition.
|
|
62
|
+
*
|
|
63
|
+
* This generator creates a complete Lit web component with TypeScript support,
|
|
64
|
+
* testing infrastructure, and optional Storybook stories and CSS styles.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://summon.dev/generators/component/lit} for documentation
|
|
67
|
+
*/
|
|
68
|
+
const generator = {
|
|
69
|
+
meta: {
|
|
70
|
+
name: "component/lit",
|
|
71
|
+
displayName: `${PACKAGE_NAME}:lit`,
|
|
72
|
+
description: "Generate a Lit web component with TypeScript, tests, stories, and styles",
|
|
73
|
+
version: "0.1.0",
|
|
74
|
+
help: `Generate a Lit web component with TypeScript, tests, stories, and styles.
|
|
75
|
+
|
|
76
|
+
FEATURES:
|
|
77
|
+
- Lit element with TypeScript decorators
|
|
78
|
+
- Unit tests with Vitest and shadow DOM testing
|
|
79
|
+
- Storybook integration with @storybook/web-components-vite (optional)
|
|
80
|
+
- CSS styles (optional)
|
|
81
|
+
- Auto-export from parent index.ts
|
|
82
|
+
|
|
83
|
+
The component name is extracted from the path and must be PascalCase.
|
|
84
|
+
For example, 'src/lib/components/Button' creates a 'Button' component
|
|
85
|
+
with the custom element tag 'button'.`,
|
|
86
|
+
examples: [
|
|
87
|
+
"summon component lit --component-path=src/lib/components/Button",
|
|
88
|
+
"summon component lit --component-path=src/lib/components/Card --with-styles --with-stories",
|
|
89
|
+
"summon component lit --component-path=src/lib/components/Modal --no-with-styles",
|
|
90
|
+
"summon component lit --component-path=src/lib/components/Button --dry-run",
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
prompts: [createComponentPathPrompt("lit"), ...litPrompts],
|
|
94
|
+
generate: (answers) => {
|
|
95
|
+
const componentName = getComponentName(answers.componentPath);
|
|
96
|
+
const componentDir = answers.componentPath;
|
|
97
|
+
const parentDir = getParentDir(answers.componentPath);
|
|
98
|
+
const ctx = createTemplateContext(answers, "lit");
|
|
99
|
+
return sequence_([
|
|
100
|
+
info(`Generating Lit web component: ${componentName}`),
|
|
101
|
+
debug("Creating component directory"),
|
|
102
|
+
mkdir(componentDir),
|
|
103
|
+
debug("Creating main component file"),
|
|
104
|
+
template({
|
|
105
|
+
source: litTemplates.component.source,
|
|
106
|
+
content: litTemplates.component.content,
|
|
107
|
+
dest: path.join(componentDir, `${componentName}.ts`),
|
|
108
|
+
vars: ctx,
|
|
109
|
+
}),
|
|
110
|
+
debug("Creating index barrel file"),
|
|
111
|
+
template({
|
|
112
|
+
source: litTemplates.index.source,
|
|
113
|
+
content: litTemplates.index.content,
|
|
114
|
+
dest: path.join(componentDir, "index.ts"),
|
|
115
|
+
vars: ctx,
|
|
116
|
+
}),
|
|
117
|
+
debug("Creating types file"),
|
|
118
|
+
template({
|
|
119
|
+
source: litTemplates.types.source,
|
|
120
|
+
content: litTemplates.types.content,
|
|
121
|
+
dest: path.join(componentDir, "types.ts"),
|
|
122
|
+
vars: ctx,
|
|
123
|
+
}),
|
|
124
|
+
debug("Creating test file"),
|
|
125
|
+
template({
|
|
126
|
+
source: litTemplates.tests.source,
|
|
127
|
+
content: litTemplates.tests.content,
|
|
128
|
+
dest: path.join(componentDir, `${componentName}.tests.ts`),
|
|
129
|
+
vars: ctx,
|
|
130
|
+
}),
|
|
131
|
+
when(answers.withStories, debug("Creating stories file")),
|
|
132
|
+
when(answers.withStories, template({
|
|
133
|
+
source: litTemplates.stories.source,
|
|
134
|
+
content: litTemplates.stories.content,
|
|
135
|
+
dest: path.join(componentDir, `${componentName}.stories.ts`),
|
|
136
|
+
vars: ctx,
|
|
137
|
+
})),
|
|
138
|
+
when(answers.withStyles, debug("Creating styles file")),
|
|
139
|
+
when(answers.withStyles, template({
|
|
140
|
+
source: litTemplates.styles.source,
|
|
141
|
+
content: litTemplates.styles.content,
|
|
142
|
+
dest: path.join(componentDir, "styles.css"),
|
|
143
|
+
vars: ctx,
|
|
144
|
+
})),
|
|
145
|
+
debug("Updating parent index.ts with export"),
|
|
146
|
+
appendExportToParentIndex(parentDir, componentName),
|
|
147
|
+
info(`Created ${componentName} component at ${componentDir}`),
|
|
148
|
+
]);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
export default generator;
|
|
152
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/lit/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;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,GACb,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,YAAY,GAAG;IACnB,SAAS,EAAE,MAAM,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;AAErD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lit/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/lit/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
import * as path from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { template } from "@canonical/summon-core";
|
|
18
|
+
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
19
|
+
import { appendExportToParentIndex, createComponentPathPrompt, createTemplateContext, getComponentName, getParentDir, PACKAGE_NAME, sharedPrompts, } from "../shared/index.js";
|
|
20
|
+
import loadTemplate from "../shared/loadTemplate.js";
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Template Paths & Content (loaded eagerly via top-level await)
|
|
23
|
+
// =============================================================================
|
|
24
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const templatesDir = path.join(__dirname, "..", "templates");
|
|
26
|
+
const reactTemplates = {
|
|
27
|
+
component: await loadTemplate(path.join(templatesDir, "react", "component.tsx.ejs")),
|
|
28
|
+
types: await loadTemplate(path.join(templatesDir, "react", "types.ts.ejs")),
|
|
29
|
+
index: await loadTemplate(path.join(templatesDir, "react", "index.ts.ejs")),
|
|
30
|
+
test: await loadTemplate(path.join(templatesDir, "react", "test.tsx.ejs")),
|
|
31
|
+
ssrTest: await loadTemplate(path.join(templatesDir, "react", "ssr.test.tsx.ejs")),
|
|
32
|
+
stories: await loadTemplate(path.join(templatesDir, "react", "stories.tsx.ejs")),
|
|
33
|
+
styles: await loadTemplate(path.join(templatesDir, "shared", "styles.css.ejs")),
|
|
34
|
+
};
|
|
35
|
+
// =============================================================================
|
|
36
|
+
// Generator Definition
|
|
37
|
+
// =============================================================================
|
|
38
|
+
const generator = {
|
|
39
|
+
meta: {
|
|
40
|
+
name: "component/react",
|
|
41
|
+
displayName: `${PACKAGE_NAME}:react`,
|
|
42
|
+
description: "Generate a React component with TypeScript, tests, stories, and styles",
|
|
43
|
+
version: "0.1.0",
|
|
44
|
+
help: `Generate a React component with TypeScript, tests, stories, and styles.
|
|
45
|
+
|
|
46
|
+
FEATURES:
|
|
47
|
+
- TypeScript types and props interface
|
|
48
|
+
- Unit tests with @testing-library/react
|
|
49
|
+
- Storybook integration (optional)
|
|
50
|
+
- CSS styles (optional)
|
|
51
|
+
- SSR tests (optional)
|
|
52
|
+
- Auto-export from parent index.ts
|
|
53
|
+
|
|
54
|
+
The component name is extracted from the path and must be PascalCase.
|
|
55
|
+
For example, 'src/components/Button' creates a 'Button' component.`,
|
|
56
|
+
examples: [
|
|
57
|
+
"summon component react --component-path=src/components/Button",
|
|
58
|
+
"summon component react --component-path=src/components/Card --with-styles --with-stories",
|
|
59
|
+
"summon component react --component-path=src/components/Modal --no-with-ssr-tests",
|
|
60
|
+
"summon component react --component-path=src/components/Button --dry-run",
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
prompts: [createComponentPathPrompt("react"), ...sharedPrompts],
|
|
64
|
+
generate: (answers) => {
|
|
65
|
+
const componentName = getComponentName(answers.componentPath);
|
|
66
|
+
const componentDir = answers.componentPath;
|
|
67
|
+
const parentDir = getParentDir(answers.componentPath);
|
|
68
|
+
const ctx = createTemplateContext(answers, "react");
|
|
69
|
+
return sequence_([
|
|
70
|
+
info(`Generating React component: ${componentName}`),
|
|
71
|
+
debug("Creating component directory"),
|
|
72
|
+
mkdir(componentDir),
|
|
73
|
+
debug("Creating main component file"),
|
|
74
|
+
template({
|
|
75
|
+
source: reactTemplates.component.source,
|
|
76
|
+
content: reactTemplates.component.content,
|
|
77
|
+
dest: path.join(componentDir, `${componentName}.tsx`),
|
|
78
|
+
vars: ctx,
|
|
79
|
+
}),
|
|
80
|
+
debug("Creating types file"),
|
|
81
|
+
template({
|
|
82
|
+
source: reactTemplates.types.source,
|
|
83
|
+
content: reactTemplates.types.content,
|
|
84
|
+
dest: path.join(componentDir, "types.ts"),
|
|
85
|
+
vars: ctx,
|
|
86
|
+
}),
|
|
87
|
+
debug("Creating index barrel file"),
|
|
88
|
+
template({
|
|
89
|
+
source: reactTemplates.index.source,
|
|
90
|
+
content: reactTemplates.index.content,
|
|
91
|
+
dest: path.join(componentDir, "index.ts"),
|
|
92
|
+
vars: ctx,
|
|
93
|
+
}),
|
|
94
|
+
debug("Creating test file"),
|
|
95
|
+
template({
|
|
96
|
+
source: reactTemplates.test.source,
|
|
97
|
+
content: reactTemplates.test.content,
|
|
98
|
+
dest: path.join(componentDir, `${componentName}.tests.tsx`),
|
|
99
|
+
vars: ctx,
|
|
100
|
+
}),
|
|
101
|
+
when(answers.withSsrTests, debug("Creating SSR test file")),
|
|
102
|
+
when(answers.withSsrTests, template({
|
|
103
|
+
source: reactTemplates.ssrTest.source,
|
|
104
|
+
content: reactTemplates.ssrTest.content,
|
|
105
|
+
dest: path.join(componentDir, `${componentName}.ssr.tests.tsx`),
|
|
106
|
+
vars: ctx,
|
|
107
|
+
})),
|
|
108
|
+
when(answers.withStories, debug("Creating stories file")),
|
|
109
|
+
when(answers.withStories, template({
|
|
110
|
+
source: reactTemplates.stories.source,
|
|
111
|
+
content: reactTemplates.stories.content,
|
|
112
|
+
dest: path.join(componentDir, `${componentName}.stories.tsx`),
|
|
113
|
+
vars: ctx,
|
|
114
|
+
})),
|
|
115
|
+
when(answers.withStyles, debug("Creating styles file")),
|
|
116
|
+
when(answers.withStyles, template({
|
|
117
|
+
source: reactTemplates.styles.source,
|
|
118
|
+
content: reactTemplates.styles.content,
|
|
119
|
+
dest: path.join(componentDir, "styles.css"),
|
|
120
|
+
vars: ctx,
|
|
121
|
+
})),
|
|
122
|
+
debug("Updating parent index.ts with export"),
|
|
123
|
+
appendExportToParentIndex(parentDir, componentName),
|
|
124
|
+
info(`Created ${componentName} component at ${componentDir}`),
|
|
125
|
+
]);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
export default generator;
|
|
129
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/react/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;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,CAA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,OAAO;gBACtC,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;CAC4D,CAAC;AAEhE,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/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/react/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import validateComponentPath from "./validateComponentPath.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create component path prompt with framework-specific defaults.
|
|
4
|
+
*
|
|
5
|
+
* This prompt is marked as positional, allowing users to run:
|
|
6
|
+
* summon component react src/components/Button
|
|
7
|
+
* instead of:
|
|
8
|
+
* summon component react --component-path=src/components/Button
|
|
9
|
+
*/
|
|
10
|
+
export default function createComponentPathPrompt(framework) {
|
|
11
|
+
return {
|
|
12
|
+
name: "componentPath",
|
|
13
|
+
type: "text",
|
|
14
|
+
message: "Component path:",
|
|
15
|
+
default: framework === "react"
|
|
16
|
+
? "src/components/MyComponent"
|
|
17
|
+
: "src/lib/components/MyComponent",
|
|
18
|
+
validate: validateComponentPath,
|
|
19
|
+
group: "Component",
|
|
20
|
+
positional: true,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=createComponentPathPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createComponentPathPrompt.js","sourceRoot":"","sources":["../../../src/shared/createComponentPathPrompt.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,SAAoB;IAEpB,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,OAAO,EACL,SAAS,KAAK,OAAO;YACnB,CAAC,CAAC,4BAA4B;YAC9B,CAAC,CAAC,gCAAgC;QACtC,QAAQ,EAAE,qBAAqB;QAC/B,KAAK,EAAE,WAAW;QAClB,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template context creation for component generators
|
|
3
|
+
*/
|
|
4
|
+
import { getComponentName, kebabCase } from "./string-helpers/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create template context from answers
|
|
7
|
+
*/
|
|
8
|
+
export default function createTemplateContext(answers, framework) {
|
|
9
|
+
const name = getComponentName(answers.componentPath);
|
|
10
|
+
return {
|
|
11
|
+
name,
|
|
12
|
+
kebabName: kebabCase(name),
|
|
13
|
+
generatorName: `@canonical/summon:component-${framework}`,
|
|
14
|
+
version: "0.1.0",
|
|
15
|
+
withStyles: answers.withStyles,
|
|
16
|
+
withStories: answers.withStories,
|
|
17
|
+
withSsrTests: answers.withSsrTests,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=createTemplateContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTemplateContext.js","sourceRoot":"","sources":["../../../src/shared/createTemplateContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAOxE;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,OAA6B,EAC7B,SAAoB;IAEpB,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACrD,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC;QAC1B,aAAa,EAAE,+BAA+B,SAAS,EAAE;QACzD,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { appendFile, exists, flatMap, ifElseM, pure, readFile, writeFile, } from "@canonical/task";
|
|
3
|
+
import removeLineFromFile from "./removeLineFromFile.js";
|
|
4
|
+
/**
|
|
5
|
+
* Append export to parent index.ts file (or create if not exists).
|
|
6
|
+
* Carries undo metadata: removes the export line (or deletes the index
|
|
7
|
+
* if it was created from scratch).
|
|
8
|
+
*/
|
|
9
|
+
export default function appendExportToParentIndex(parentDir, componentName) {
|
|
10
|
+
const indexPath = path.join(parentDir, "index.ts");
|
|
11
|
+
const exportLine = `export * from "./${componentName}/index.js";\n`;
|
|
12
|
+
return ifElseM(exists(indexPath),
|
|
13
|
+
// If exists, append (if not already exported)
|
|
14
|
+
flatMap(readFile(indexPath), (content) => {
|
|
15
|
+
if (content.includes(`./${componentName}`)) {
|
|
16
|
+
return pure(undefined); // Already exported
|
|
17
|
+
}
|
|
18
|
+
return appendFile(indexPath, exportLine, true, {
|
|
19
|
+
undo: removeLineFromFile(indexPath, exportLine),
|
|
20
|
+
});
|
|
21
|
+
}),
|
|
22
|
+
// If not exists, create new file (default undo: deleteFile is correct)
|
|
23
|
+
writeFile(indexPath, exportLine));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=appendExportToParentIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendExportToParentIndex.js","sourceRoot":"","sources":["../../../../src/shared/file-operations/appendExportToParentIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,IAAI,EACJ,QAAQ,EAER,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,SAAiB,EACjB,aAAqB;IAErB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,oBAAoB,aAAa,eAAe,CAAC;IAEpE,OAAO,OAAO,CACZ,MAAM,CAAC,SAAS,CAAC;IACjB,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE;QACvC,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,aAAa,EAAE,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB;QAC7C,CAAC;QACD,OAAO,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE;YAC7C,IAAI,EAAE,kBAAkB,CAAC,SAAS,EAAE,UAAU,CAAC;SAChD,CAAC,CAAC;IACL,CAAC,CAAC;IACF,uEAAuE;IACvE,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,CACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { dryRunWith } from "@canonical/task";
|
|
2
|
+
/**
|
|
3
|
+
* dryRunWith that mocks ReadFile and Exists to simulate file state.
|
|
4
|
+
* Test-only helper for file operation tests.
|
|
5
|
+
*/
|
|
6
|
+
export default function dryRunWithFileState(task, files) {
|
|
7
|
+
const mocks = new Map([
|
|
8
|
+
[
|
|
9
|
+
"ReadFile",
|
|
10
|
+
(effect) => {
|
|
11
|
+
const e = effect;
|
|
12
|
+
return files[e.path] ?? "";
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"Exists",
|
|
17
|
+
(effect) => {
|
|
18
|
+
const e = effect;
|
|
19
|
+
return e.path in files;
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
]);
|
|
23
|
+
return dryRunWith(task, mocks);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dryRunWithFileState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dryRunWithFileState.js","sourceRoot":"","sources":["../../../../src/shared/file-operations/dryRunWithFileState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AAErE;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,IAAa,EACb,KAA6B;IAE7B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAsC;QACzD;YACE,UAAU;YACV,CAAC,MAAM,EAAE,EAAE;gBACT,MAAM,CAAC,GAAG,MAA0B,CAAC;gBACrC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAC7B,CAAC;SACF;QACD;YACE,QAAQ;YACR,CAAC,MAAM,EAAE,EAAE;gBACT,MAAM,CAAC,GAAG,MAA0B,CAAC;gBACrC,OAAO,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC;YACzB,CAAC;SACF;KACF,CAAC,CAAC;IACH,OAAO,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { default as appendExportToParentIndex } from "./appendExportToParentIndex.js";
|
|
2
2
|
export { default as removeExportFromParentIndex } from "./removeExportFromParentIndex.js";
|
|
3
3
|
export { default as removeLineFromFile } from "./removeLineFromFile.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/shared/file-operations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { exists, ifElseM, pure } from "@canonical/task";
|
|
3
|
+
import removeLineFromFile from "./removeLineFromFile.js";
|
|
4
|
+
/**
|
|
5
|
+
* Remove a component export from a parent index.ts.
|
|
6
|
+
* Idempotent — no-op if the export is not present or the file doesn't exist.
|
|
7
|
+
*/
|
|
8
|
+
export default function removeExportFromParentIndex(parentDir, componentName) {
|
|
9
|
+
const indexPath = path.join(parentDir, "index.ts");
|
|
10
|
+
const exportLine = `export * from "./${componentName}/index.js";\n`;
|
|
11
|
+
return ifElseM(exists(indexPath), removeLineFromFile(indexPath, exportLine), pure(undefined));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=removeExportFromParentIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeExportFromParentIndex.js","sourceRoot":"","sources":["../../../../src/shared/file-operations/removeExportFromParentIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAa,MAAM,iBAAiB,CAAC;AACnE,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,2BAA2B,CACjD,SAAiB,EACjB,aAAqB;IAErB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,oBAAoB,aAAa,eAAe,CAAC;IAEpE,OAAO,OAAO,CACZ,MAAM,CAAC,SAAS,CAAC,EACjB,kBAAkB,CAAC,SAAS,EAAE,UAAU,CAAC,EACzC,IAAI,CAAC,SAAS,CAAC,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { deleteFile, flatMap, readFile, writeFile, } from "@canonical/task";
|
|
2
|
+
/**
|
|
3
|
+
* Remove a specific line from a file. If the file becomes empty,
|
|
4
|
+
* delete it entirely. Idempotent — no-op if the line is not present.
|
|
5
|
+
*/
|
|
6
|
+
export default function removeLineFromFile(filePath, line) {
|
|
7
|
+
return flatMap(readFile(filePath), (content) => {
|
|
8
|
+
const trimmedLine = line.trim();
|
|
9
|
+
const filtered = content
|
|
10
|
+
.split("\n")
|
|
11
|
+
.filter((l) => l.trim() !== trimmedLine)
|
|
12
|
+
.join("\n");
|
|
13
|
+
if (filtered.trim() === "") {
|
|
14
|
+
return deleteFile(filePath, { undo: null });
|
|
15
|
+
}
|
|
16
|
+
return writeFile(filePath, filtered, { undo: null });
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=removeLineFromFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeLineFromFile.js","sourceRoot":"","sources":["../../../../src/shared/file-operations/removeLineFromFile.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EAER,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,QAAgB,EAChB,IAAY;IAEZ,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE;QAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,OAAO;aACrB,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,WAAW,CAAC;aACvC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC3B,OAAO,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities and types for component generators
|
|
3
|
+
*/
|
|
4
|
+
export { default as createComponentPathPrompt } from "./createComponentPathPrompt.js";
|
|
5
|
+
export { default as createTemplateContext } from "./createTemplateContext.js";
|
|
6
|
+
export * from "./file-operations/index.js";
|
|
7
|
+
export { PACKAGE_NAME } from "./packageName.js";
|
|
8
|
+
export { default as sharedPrompts } from "./sharedPrompts.js";
|
|
9
|
+
export * from "./string-helpers/index.js";
|
|
10
|
+
export { default as validateComponentPath } from "./validateComponentPath.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,cAAc,2BAA2B,CAAC;AAE1C,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|