component-gen-cli 1.0.0 → 1.0.1
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 +141 -0
- package/bin/cli.js +64 -6
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# component-gen-cli (`cg`)
|
|
2
|
+
|
|
3
|
+
CLI to scaffold starter **components** across common **JavaScript / TypeScript** stacks.
|
|
4
|
+
|
|
5
|
+
## Supported frameworks
|
|
6
|
+
|
|
7
|
+
| Flag `-f` | What you get |
|
|
8
|
+
|-----------|----------------|
|
|
9
|
+
| `react` | `.jsx` or `.tsx` functional component |
|
|
10
|
+
| `vue` | Single-file `.vue` (Vue 3, `<script setup>`) |
|
|
11
|
+
| `angular` | Standalone Angular component (`ts` + `.html` + `.css`/`.scss`) |
|
|
12
|
+
| `svelte` | `.svelte` file |
|
|
13
|
+
| `solid` | Solid JSX component |
|
|
14
|
+
| `next` | Next.js-ready React file; `--client` adds `'use client'` |
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- **Node.js 18+**
|
|
19
|
+
- Optionally **authenticated npm** (`npm login`) — only if publishing this package yourself
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
**No install — use via npx:**
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx component-gen-cli@latest --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Global:**
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install -g component-gen-cli
|
|
33
|
+
cg --help
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The binaries are **`cg`** and **`component-gen`** (same program).
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Commands
|
|
41
|
+
|
|
42
|
+
Run **`cg`** with **no arguments** for the main help panel (examples included).
|
|
43
|
+
|
|
44
|
+
### `cg generate` (alias `cg g`)
|
|
45
|
+
|
|
46
|
+
Creates file(s). **`-f`** / **`--framework`** is required.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cg generate <Name> --framework <react|vue|angular|svelte|solid|next> [options]
|
|
50
|
+
cg g <Name> -f react [options]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Option | Effect |
|
|
54
|
+
|--------|--------|
|
|
55
|
+
| `-o`, `--out <dir>` | Output folder (default: `.`) |
|
|
56
|
+
| `--typescript`, `--ts` | TypeScript where applicable |
|
|
57
|
+
| `--scss` | Angular: use `.scss` instead of `.css` |
|
|
58
|
+
| `--client` | Next.js: add `"use client"` |
|
|
59
|
+
|
|
60
|
+
**Help for flags only:**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
cg generate --help
|
|
64
|
+
cg g -h
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### `cg examples` (alias `cg guide`)
|
|
68
|
+
|
|
69
|
+
Prints usage examples without opening the generic help screen.
|
|
70
|
+
|
|
71
|
+
### `cg frameworks` (aliases **`fw`**, **`targets`**)
|
|
72
|
+
|
|
73
|
+
Lists supported frameworks and related flags.
|
|
74
|
+
|
|
75
|
+
### Built-in Commander help
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
cg help
|
|
79
|
+
cg help generate
|
|
80
|
+
cg --help
|
|
81
|
+
cg -h
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Copy-paste examples
|
|
87
|
+
|
|
88
|
+
**React (TypeScript)**
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npx component-gen-cli@latest generate MyCard -f react --ts --out ./src/components
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**React (JavaScript)**
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cg g Footer -f react --out ./src/components
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Vue**
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
cg g Navbar -f vue --ts --out ./src/components
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Angular (+ SCSS)**
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
cg g ChartPanel -f angular --scss --out ./src/app
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Svelte**
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
cg g Sidebar -f svelte --ts --out ./src/lib
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Solid**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
cg g IconBtn -f solid --ts --out ./src/ui
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Next.js (client component)**
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
cg g Modal -f next --ts --client --out ./components
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Publish a new release (maintainers)
|
|
133
|
+
|
|
134
|
+
1. Bump **`version`** in `package.json`.
|
|
135
|
+
2. `npm publish --access public` — add `--otp <code>` if npm requires 2FA.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
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);
|