component-gen-cli 1.0.0 → 1.0.2
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 +215 -0
- package/bin/cli.js +64 -6
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# component-gen-cli
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/component-gen-cli)
|
|
4
|
+
[](https://www.npmjs.com/package/component-gen-cli)
|
|
5
|
+
|
|
6
|
+
**CLI to scaffold starter components** for **[React](https://react.dev/)**, **[Vue 3](https://vuejs.org/)**, **[Angular](https://angular.dev/)**, **[Svelte](https://svelte.dev/)**, **[SolidJS](https://solidjs.com/)**, and **[Next.js](https://nextjs.org/)**. Use JavaScript or TypeScript via a single flag.
|
|
7
|
+
|
|
8
|
+
Binaries installed from this package:
|
|
9
|
+
|
|
10
|
+
| Command | Purpose |
|
|
11
|
+
|---------|---------|
|
|
12
|
+
| **`cg`** | Short default (shown in docs below) |
|
|
13
|
+
| **`component-gen`** | Same CLI, longer name |
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- **Node.js ≥ 18**
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
**Run once (no global install)**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx component-gen-cli@latest
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Opens the built-in help and examples.
|
|
32
|
+
|
|
33
|
+
**Globally**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install -g component-gen-cli
|
|
37
|
+
cg --help
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**As a dev tool in another project**
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install --save-dev component-gen-cli
|
|
44
|
+
npx cg --help
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# React + TypeScript into ./src/components
|
|
53
|
+
npx component-gen-cli@latest generate ProductCard -f react --typescript --out ./src/components
|
|
54
|
+
|
|
55
|
+
# Same, short form
|
|
56
|
+
cg g ProductCard -f react --ts -o ./src/components
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Run **`cg`** with **no arguments** to print the full help block (same examples as **`cg examples`**).
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Supported frameworks
|
|
64
|
+
|
|
65
|
+
Use **`-f`** or **`--framework`** with exactly one value:
|
|
66
|
+
|
|
67
|
+
| Value | Typical output |
|
|
68
|
+
|-------|----------------|
|
|
69
|
+
| **`react`** | `<Name>.jsx` or `<Name>.tsx` |
|
|
70
|
+
| **`vue`** | `<Name>.vue` (Vue 3 `<script setup>`) |
|
|
71
|
+
| **`angular`** | `<kebab>/<kebab>.component.ts` plus `.html` and `.css` or `.scss` |
|
|
72
|
+
| **`svelte`** | `<Name>.svelte` |
|
|
73
|
+
| **`solid`** | `<Name>.jsx` / `<Name>.tsx` (JSX component) |
|
|
74
|
+
| **`next`** | `<Name>.jsx` / `<Name>.tsx` (Next-compatible React; optional `'use client'`) |
|
|
75
|
+
|
|
76
|
+
Angular uses a **standalone** component and **selector** `app-<kebab>` (from your component name).
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## CLI reference
|
|
81
|
+
|
|
82
|
+
### Discover commands
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
cg # Help + examples
|
|
86
|
+
cg frameworks # List targets (aliases: cg fw, cg targets)
|
|
87
|
+
cg examples # Examples only (alias: cg guide)
|
|
88
|
+
cg generate --help # All flags for generate (alias: cg g -h)
|
|
89
|
+
cg help generate
|
|
90
|
+
cg --version # Published version
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `generate` / `g`
|
|
94
|
+
|
|
95
|
+
```text
|
|
96
|
+
cg generate <ComponentName> -f <framework> [options]
|
|
97
|
+
cg g <ComponentName> -f <framework> [options]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`<ComponentName>` can be PascalCase (`UserCard`), kebab-case (`user-card`), or spaced words (`user card`). Names are normalized to PascalCase for file symbols and sensible paths.
|
|
101
|
+
|
|
102
|
+
| Option | Description |
|
|
103
|
+
|--------|--------------|
|
|
104
|
+
| **`-f, --framework <fw>`** | **Required.** `react`, `vue`, `angular`, `svelte`, `solid`, or `next`. |
|
|
105
|
+
| **`-o, --out <dir>`** | Destination folder (default: current directory `.`). Parent folders are created as needed. |
|
|
106
|
+
| **`--typescript`, `--ts`** | TypeScript dialect (`.tsx`, `<script lang="ts">`, etc.). Omit for plain JS where supported. Angular component class is **always `.ts`**; this flag aligns other TS-related choices where relevant. |
|
|
107
|
+
| **`--scss`** | **Angular only:** use **`*.component.scss`** instead of **`.css`**. |
|
|
108
|
+
| **`--client`** | **Next.js only:** insert **`'use client'`** at top of file (client boundary). |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Examples by stack
|
|
113
|
+
|
|
114
|
+
<details>
|
|
115
|
+
<summary><strong>React</strong></summary>
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
cg g Avatar -f react --ts --out ./src/components
|
|
119
|
+
cg g Avatar -f react --out ./src/components
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Creates `Avatar.tsx` or `Avatar.jsx`.
|
|
123
|
+
|
|
124
|
+
</details>
|
|
125
|
+
|
|
126
|
+
<details>
|
|
127
|
+
<summary><strong>Vue 3</strong></summary>
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cg g SearchBar -f vue --ts --out ./components
|
|
131
|
+
cg g SearchBar -f vue --out ./components
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Creates `SearchBar.vue`.
|
|
135
|
+
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
<details>
|
|
139
|
+
<summary><strong>Angular</strong></summary>
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
cg g MetricsTile -f angular --out ./src/app/widgets
|
|
143
|
+
cg g MetricsTile -f angular --scss --out ./src/app/widgets
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Creates `<kebab>/` containing `*.component.ts`, `*.component.html`, and `*.component.css` or `*.scss`.
|
|
147
|
+
|
|
148
|
+
</details>
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary><strong>Svelte</strong></summary>
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
cg g Toast -f svelte --ts --out ./lib
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Creates `Toast.svelte`.
|
|
158
|
+
|
|
159
|
+
</details>
|
|
160
|
+
|
|
161
|
+
<details>
|
|
162
|
+
<summary><strong>SolidJS</strong></summary>
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
cg g Counter -f solid --ts --out ./src/ui
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Creates `Counter.tsx` / `Counter.jsx`.
|
|
169
|
+
|
|
170
|
+
</details>
|
|
171
|
+
|
|
172
|
+
<details>
|
|
173
|
+
<summary><strong>Next.js</strong></summary>
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
cg g Sidebar -f next --ts --out ./components
|
|
177
|
+
cg g Sidebar -f next --ts --client --out ./components
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Creates `Sidebar.tsx` or `Sidebar.jsx`. Use **`--client`** when the scaffold uses hooks or browser-only APIs in the App Router.
|
|
181
|
+
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Programmatic use (advanced)
|
|
187
|
+
|
|
188
|
+
Published entry is ESM **`src/index.js`**. You may import (**after** resolving from `node_modules` in your toolchain):
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
import { generateComponent, FRAMEWORKS } from "component-gen-cli";
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Typical callers run the **`cg`** CLI instead.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## How the npm readme is updated
|
|
199
|
+
|
|
200
|
+
The page at **npmjs.com** shows **`README.md` from your package tarball**. After you edit this file **at the repo root**:
|
|
201
|
+
|
|
202
|
+
1. Bump **`version`** in **`package.json`** (required for each new publish unless you unpublished).
|
|
203
|
+
2. Run **`npm publish --access public`** (add **`--otp <code>`** if npm asks).
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Contributing & issues
|
|
208
|
+
|
|
209
|
+
Use your repository’s tracker for bugs and ideas. Pull requests improving templates or frameworks are welcome once you open a fork and keep changes focused.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
MIT
|
package/bin/cli.js
CHANGED
|
@@ -10,17 +10,68 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
10
10
|
const pkgPath = join(__dirname, "..", "package.json");
|
|
11
11
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
12
12
|
|
|
13
|
+
const examplesBlock = `
|
|
14
|
+
Examples:
|
|
15
|
+
npx component-gen-cli@latest generate MyCard -f react --ts --out ./src/components
|
|
16
|
+
cg g Navbar -f vue --out ./src/components
|
|
17
|
+
cg g Chart -f angular --scss --out ./src/app
|
|
18
|
+
cg g Panel -f svelte --ts --out ./lib
|
|
19
|
+
cg g Icon -f solid --ts --out ./src/ui
|
|
20
|
+
cg g Drawer -f next --ts --client --out ./components
|
|
21
|
+
|
|
22
|
+
Tips:
|
|
23
|
+
Use "cg frameworks" or "cg examples" anytime.
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const frameworksBlock = FRAMEWORKS.map((fw) => ` • ${fw}`).join("\n");
|
|
27
|
+
|
|
13
28
|
const program = new Command();
|
|
14
29
|
|
|
30
|
+
program.configureHelp({
|
|
31
|
+
sortSubcommands: true,
|
|
32
|
+
});
|
|
33
|
+
|
|
15
34
|
program
|
|
16
35
|
.name("cg")
|
|
17
|
-
.description(
|
|
18
|
-
|
|
36
|
+
.description(
|
|
37
|
+
`Generate starter components for JS/TS (${FRAMEWORKS.join(", ")})`
|
|
38
|
+
)
|
|
39
|
+
.version(pkg.version ?? "0.0.0")
|
|
40
|
+
.addHelpText("after", `\nQuick start:${examplesBlock}\n`);
|
|
41
|
+
|
|
42
|
+
program
|
|
43
|
+
.command("examples")
|
|
44
|
+
.alias("guide")
|
|
45
|
+
.description("Show copy-paste usage examples")
|
|
46
|
+
.action(() => {
|
|
47
|
+
console.log(`component-gen-cli — usage examples`);
|
|
48
|
+
console.log(examplesBlock);
|
|
49
|
+
console.log(
|
|
50
|
+
`Commands:\n cg generate <name> -f … (alias: cg g …)\n cg frameworks list supported targets`
|
|
51
|
+
);
|
|
52
|
+
console.log(`\nDetailed flags: cg generate --help or cg g -h`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
program
|
|
56
|
+
.command("frameworks")
|
|
57
|
+
.aliases(["fw", "targets"])
|
|
58
|
+
.description(`List frameworks (${FRAMEWORKS.length} supported)`)
|
|
59
|
+
.action(() => {
|
|
60
|
+
console.log("Supported frameworks (use -f or --framework):");
|
|
61
|
+
console.log(frameworksBlock);
|
|
62
|
+
console.log(`
|
|
63
|
+
Optional language:
|
|
64
|
+
--typescript / --ts TypeScript where supported (.tsx, <script lang="ts">, etc.)
|
|
65
|
+
Angular only:
|
|
66
|
+
--scss use .scss instead of .css
|
|
67
|
+
Next.js only:
|
|
68
|
+
--client prepend 'use client' for client components`);
|
|
69
|
+
});
|
|
19
70
|
|
|
20
71
|
program
|
|
21
72
|
.command("generate")
|
|
22
73
|
.alias("g")
|
|
23
|
-
.argument("<name>", "Component name (
|
|
74
|
+
.argument("<name>", "Component name (e.g. UserCard, user-card)")
|
|
24
75
|
.addOption(
|
|
25
76
|
new Option("-f, --framework <fw>", `Framework (${FRAMEWORKS.join("|")})`)
|
|
26
77
|
.choices([...FRAMEWORKS])
|
|
@@ -28,9 +79,10 @@ program
|
|
|
28
79
|
)
|
|
29
80
|
.option("-o, --out <dir>", "Output directory (default: current directory)", ".")
|
|
30
81
|
.option("--ts, --typescript", "Use TypeScript where applicable", false)
|
|
31
|
-
.option("--scss", "Use SCSS for style files (Angular
|
|
82
|
+
.option("--scss", "Use SCSS for style files (Angular)", false)
|
|
32
83
|
.option("--client", "Next.js: add \"use client\" directive", false)
|
|
33
|
-
.description("
|
|
84
|
+
.description("Write component file(s)")
|
|
85
|
+
.addHelpText("after", `\n${examplesBlock.trim()}\n`)
|
|
34
86
|
.action(async (name, opts) => {
|
|
35
87
|
try {
|
|
36
88
|
const result = await generateComponent(name, opts);
|
|
@@ -44,4 +96,10 @@ program
|
|
|
44
96
|
}
|
|
45
97
|
});
|
|
46
98
|
|
|
47
|
-
|
|
99
|
+
const argv = process.argv.slice(2);
|
|
100
|
+
if (argv.length === 0) {
|
|
101
|
+
program.outputHelp({ error: false });
|
|
102
|
+
process.exit(0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
program.parse(process.argv);
|