@pavlos-samaras/react-cli 2.1.0 → 2.1.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 +68 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
A command-line tool to scaffold React projects, components, and hooks.
|
|
4
4
|
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
- [Install](#install)
|
|
8
|
+
- [Create a React project](#create-a-react-project)
|
|
9
|
+
- [Generate code](#generate-code)
|
|
10
|
+
- [Types](#types)
|
|
11
|
+
- [Options](#options)
|
|
12
|
+
- [Examples](#examples)
|
|
13
|
+
- [Output locations](#output-locations)
|
|
14
|
+
- [Configure generation defaults](#configure-generation-defaults)
|
|
15
|
+
|
|
5
16
|
## Install
|
|
6
17
|
|
|
7
18
|
```bash
|
|
@@ -11,13 +22,38 @@ npm install -g @pavlos-samaras/react-cli
|
|
|
11
22
|
## Create a React project
|
|
12
23
|
|
|
13
24
|
```bash
|
|
25
|
+
ct new <name> [options]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
By default, Vite prompts you to choose a framework and template. Use
|
|
29
|
+
`--template` (or `-t`) to select a React template directly:
|
|
30
|
+
|
|
31
|
+
| Template | Description |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `react` | React with JavaScript |
|
|
34
|
+
| `react-ts` | React with TypeScript |
|
|
35
|
+
| `react-swc` | React with JavaScript and SWC |
|
|
36
|
+
| `react-swc-ts` | React with TypeScript and SWC |
|
|
37
|
+
| `custom-js` | React with JavaScript and the CLI's custom source layout |
|
|
38
|
+
| `custom-ts` | React with TypeScript and the CLI's custom source layout |
|
|
39
|
+
|
|
40
|
+
When a template is specified, Vite runs without its interactive prompts. The
|
|
41
|
+
`custom-js` and `custom-ts` templates apply the CLI's custom layout over the
|
|
42
|
+
corresponding JavaScript or TypeScript React starter.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Use Vite's prompts
|
|
14
46
|
ct new my-app
|
|
47
|
+
|
|
48
|
+
# Select a Vite React template
|
|
49
|
+
ct new my-app --template react-swc-ts
|
|
50
|
+
|
|
51
|
+
# Use the CLI's custom TypeScript layout
|
|
52
|
+
ct new my-app -t custom-ts
|
|
15
53
|
```
|
|
16
54
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
framework and template. Dependencies are not installed automatically; install
|
|
20
|
-
them before starting the project:
|
|
55
|
+
The command creates a `ct.config.json` file in the project. After scaffolding,
|
|
56
|
+
follow Vite's output to install dependencies if needed and start the dev server:
|
|
21
57
|
|
|
22
58
|
```bash
|
|
23
59
|
cd my-app
|
|
@@ -44,12 +80,17 @@ ct generate <type> <name> [options]
|
|
|
44
80
|
|
|
45
81
|
| Option | Description |
|
|
46
82
|
| --- | --- |
|
|
47
|
-
| `-
|
|
48
|
-
| `-
|
|
49
|
-
|
|
|
50
|
-
| `--
|
|
83
|
+
| `-d, --dir <dir>` | Choose the folder for the generated type. Defaults to `components` for components and `hooks` for hooks. |
|
|
84
|
+
| `-f, --feature <feature>` | Generate under `src/features/<feature>/` instead of directly under `src/`. |
|
|
85
|
+
| `-s, --style <style>` | Component stylesheet format: `css` or `scss`. Overrides `ct.config.json`; if neither is set, the CLI prompts. |
|
|
86
|
+
| `--ts` | Force TypeScript output. Otherwise, uses `ct.config.json` when set, then detects TypeScript from `tsconfig.json`. |
|
|
87
|
+
| `--force` | Skip the check that requires the current directory to be detected as a React project. It does not overwrite existing output folders. |
|
|
88
|
+
|
|
89
|
+
Components and hooks are generated only if their destination folder does not
|
|
90
|
+
already exist. The CLI recognizes a React project by the `react` dependency in
|
|
91
|
+
its `package.json`.
|
|
51
92
|
|
|
52
|
-
|
|
93
|
+
### Examples
|
|
53
94
|
|
|
54
95
|
```bash
|
|
55
96
|
# Create a component; choose the stylesheet format when prompted
|
|
@@ -58,31 +99,38 @@ ct g component Button
|
|
|
58
99
|
# Create a TypeScript component with a SCSS module
|
|
59
100
|
ct g component LoginForm --feature auth --style scss --ts
|
|
60
101
|
|
|
102
|
+
# Use a custom folder name for a component
|
|
103
|
+
ct g component Button --dir ui
|
|
104
|
+
|
|
61
105
|
# Create a hook in a feature folder
|
|
62
106
|
ct g hook useSession -f auth
|
|
63
107
|
```
|
|
64
108
|
|
|
65
109
|
### Output locations
|
|
66
110
|
|
|
111
|
+
The default component and hook folders can be changed with `--dir`; `--feature`
|
|
112
|
+
places those folders under `src/features/<feature>/`.
|
|
113
|
+
|
|
67
114
|
| Command | Output |
|
|
68
115
|
| --- | --- |
|
|
69
116
|
| `ct g component Button` | `src/components/Button/` |
|
|
70
117
|
| `ct g component Button -f auth` | `src/features/auth/components/Button/` |
|
|
118
|
+
| `ct g component Button -d ui` | `src/ui/Button/` |
|
|
71
119
|
| `ct g hook useAuth` | `src/hooks/useAuth/useAuth.js` (or `.ts` when TypeScript is enabled) |
|
|
72
120
|
| `ct g hook useAuth -f auth` | `src/features/auth/hooks/useAuth/useAuth.js` (or `.ts` when TypeScript is enabled) |
|
|
73
121
|
|
|
74
|
-
|
|
122
|
+
### Configure generation defaults
|
|
75
123
|
|
|
76
|
-
|
|
124
|
+
Set optional defaults in the project's `ct.config.json`. The `ct new` command
|
|
125
|
+
creates this file as `{}`.
|
|
77
126
|
|
|
78
|
-
```
|
|
79
|
-
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"typescript": true,
|
|
130
|
+
"stylesheet": "scss"
|
|
131
|
+
}
|
|
80
132
|
```
|
|
81
133
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
npm install
|
|
86
|
-
npm run build
|
|
87
|
-
npm link
|
|
88
|
-
```
|
|
134
|
+
`typescript` can be `true` or `false`; when omitted, the CLI checks for
|
|
135
|
+
`tsconfig.json`. The `--ts` option overrides this setting to enable TypeScript.
|
|
136
|
+
`stylesheet` can be `css` or `scss`, and `--style` overrides it for components.
|