@pavlos-samaras/react-cli 2.0.2 → 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/dist/commands/generate/utils/generateComponent.d.ts.map +1 -1
- package/dist/commands/generate/utils/generateComponent.js +7 -6
- package/dist/commands/generate/utils/generateComponent.js.map +1 -1
- package/dist/commands/generate/utils/generateHook.d.ts.map +1 -1
- package/dist/commands/generate/utils/generateHook.js +3 -2
- package/dist/commands/generate/utils/generateHook.js.map +1 -1
- package/dist/commands/generate/utils/runGenerateComponent.js +1 -1
- package/dist/commands/generate/utils/runGenerateComponent.js.map +1 -1
- package/dist/commands/generate/utils/runGenerateHook.js +1 -1
- package/dist/commands/generate/utils/runGenerateHook.js.map +1 -1
- package/dist/commands/new/new.constants.d.ts +2 -0
- package/dist/commands/new/new.constants.d.ts.map +1 -1
- package/dist/commands/new/new.constants.js +2 -0
- package/dist/commands/new/new.constants.js.map +1 -1
- package/dist/commands/new/new.d.ts.map +1 -1
- package/dist/commands/new/new.js +16 -27
- package/dist/commands/new/new.js.map +1 -1
- package/dist/commands/new/new.types.d.ts +7 -0
- package/dist/commands/new/new.types.d.ts.map +1 -0
- package/dist/commands/new/new.types.js +2 -0
- package/dist/commands/new/new.types.js.map +1 -0
- package/dist/commands/new/utils/general.d.ts +3 -0
- package/dist/commands/new/utils/general.d.ts.map +1 -0
- package/dist/commands/new/utils/general.js +6 -0
- package/dist/commands/new/utils/general.js.map +1 -0
- package/dist/commands/new/utils/runCommand.d.ts +2 -0
- package/dist/commands/new/utils/runCommand.d.ts.map +1 -0
- package/dist/commands/new/utils/runCommand.js +7 -0
- package/dist/commands/new/utils/runCommand.js.map +1 -0
- package/dist/commands/new/utils/runCreateVite.d.ts +2 -0
- package/dist/commands/new/utils/runCreateVite.d.ts.map +1 -0
- package/dist/commands/new/utils/runCreateVite.js +32 -0
- package/dist/commands/new/utils/runCreateVite.js.map +1 -0
- package/dist/commands/new/utils/runCustomTemplate.d.ts +3 -0
- package/dist/commands/new/utils/runCustomTemplate.d.ts.map +1 -0
- package/dist/commands/new/utils/runCustomTemplate.js +25 -0
- package/dist/commands/new/utils/runCustomTemplate.js.map +1 -0
- package/dist/utils/general.d.ts +4 -0
- package/dist/utils/general.d.ts.map +1 -0
- package/dist/utils/general.js +3 -0
- package/dist/utils/general.js.map +1 -0
- package/package.json +3 -2
- package/templates/component.tpl +9 -0
- package/templates/hook.tpl +3 -0
- package/templates/react/README.md +12 -0
- package/templates/react/eslint.config.js +29 -0
- package/templates/react/index.html +13 -0
- package/templates/react/jsconfig.json +13 -0
- package/templates/react/package.json +30 -0
- package/templates/react/public/favicon.svg +1 -0
- package/templates/react/src/app/App.jsx +12 -0
- package/templates/react/src/app/providers.jsx +13 -0
- package/templates/react/src/app/routes.jsx +19 -0
- package/templates/react/src/config/queryClient.config.js +12 -0
- package/templates/react/src/lib/queryClient.jsx +6 -0
- package/templates/react/src/main.jsx +13 -0
- package/templates/react/src/pages/home/Home.jsx +11 -0
- package/templates/react/src/pages/home/Home.module.scss +0 -0
- package/templates/react/vite.config.js +18 -0
- package/templates/react-ts/README.md +75 -0
- package/templates/react-ts/eslint.config.js +22 -0
- package/templates/react-ts/index.html +13 -0
- package/templates/react-ts/package-lock.json +3221 -0
- package/templates/react-ts/package.json +33 -0
- package/templates/react-ts/public/favicon.svg +1 -0
- package/templates/react-ts/src/app/App.tsx +12 -0
- package/templates/react-ts/src/app/providers.tsx +16 -0
- package/templates/react-ts/src/app/routes.tsx +19 -0
- package/templates/react-ts/src/config/queryClient.config.ts +14 -0
- package/templates/react-ts/src/lib/queryClient.tsx +6 -0
- package/templates/react-ts/src/main.tsx +13 -0
- package/templates/react-ts/src/pages/home/Home.module.scss +0 -0
- package/templates/react-ts/src/pages/home/Home.tsx +11 -0
- package/templates/react-ts/tsconfig.app.json +29 -0
- package/templates/react-ts/tsconfig.json +7 -0
- package/templates/react-ts/tsconfig.node.json +23 -0
- package/templates/react-ts/vite.config.ts +18 -0
- package/templates/stylesheet.tpl +3 -0
- package/dist/templates/component.d.ts +0 -3
- package/dist/templates/component.d.ts.map +0 -1
- package/dist/templates/component.js +0 -11
- package/dist/templates/component.js.map +0 -1
- package/dist/templates/hook.d.ts +0 -3
- package/dist/templates/hook.d.ts.map +0 -1
- package/dist/templates/hook.js +0 -5
- package/dist/templates/hook.js.map +0 -1
- package/dist/templates/stylesheet.d.ts +0 -3
- package/dist/templates/stylesheet.d.ts.map +0 -1
- package/dist/templates/stylesheet.js +0 -7
- package/dist/templates/stylesheet.js.map +0 -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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateComponent.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateComponent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateComponent.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateComponent.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAiB/D,eAAO,MAAM,iBAAiB,WACpB,MAAM,QACR,MAAM,WACH,OAAO,KACf,OAAO,CAAC,SAAS,CA+BnB,CAAC"}
|
|
@@ -2,9 +2,7 @@ import path from "path";
|
|
|
2
2
|
import prompts from "prompts";
|
|
3
3
|
import { loadConfig } from "../../../utils/loadConfig.js";
|
|
4
4
|
import { isTypescriptUsed } from "../../../utils/validators.js";
|
|
5
|
-
import
|
|
6
|
-
import buildStylesheetTemplate from "../../../templates/stylesheet.js";
|
|
7
|
-
import buildHookTemplate from "../../../templates/hook.js";
|
|
5
|
+
import { getTemplate } from "../../../utils/general.js";
|
|
8
6
|
// Utilities
|
|
9
7
|
const askForStyle = async () => {
|
|
10
8
|
const answer = await prompts({
|
|
@@ -27,15 +25,18 @@ export const generateComponent = async (folder, name, options) => {
|
|
|
27
25
|
return {
|
|
28
26
|
JSX: {
|
|
29
27
|
path: path.join(folder, `${name}.${langExt}x`),
|
|
30
|
-
content:
|
|
28
|
+
content: getTemplate("component")
|
|
29
|
+
.replace(/__NAME__/g, name)
|
|
30
|
+
.replace(/__CLASSNAME__/, name.toLowerCase())
|
|
31
|
+
.replace(/.scss/g, `.${stylesheetExt}`),
|
|
31
32
|
},
|
|
32
33
|
stylesheet: {
|
|
33
34
|
path: path.join(folder, `${name}.module.${stylesheetExt}`),
|
|
34
|
-
content:
|
|
35
|
+
content: getTemplate("stylesheet").replace(/__CLASSNAME__/, name.toLowerCase()),
|
|
35
36
|
},
|
|
36
37
|
hook: {
|
|
37
38
|
path: path.join(folder, `use${name}.${langExt}`),
|
|
38
|
-
content:
|
|
39
|
+
content: getTemplate("hook").replace(/__NAME__/g, name),
|
|
39
40
|
},
|
|
40
41
|
test: {
|
|
41
42
|
path: path.join(folder, `${name}.test.${langExt}`),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateComponent.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"generateComponent.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,YAAY;AACZ,MAAM,WAAW,GAAG,KAAK,IAAqB,EAAE;IAC9C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC3B,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,yBAAyB;QAClC,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK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AAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAChD,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;SACxD;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,SAAS,OAAO,EAAE,CAAC;YAClD,OAAO,EAAE,EAAE;SACZ;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateHook.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateHook.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"generateHook.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateHook.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD,eAAO,MAAM,YAAY,WACf,MAAM,QACR,MAAM,WACH,OAAO;;;EAUjB,CAAC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
2
3
|
import { loadConfig } from "../../../utils/loadConfig.js";
|
|
3
4
|
import { isTypescriptUsed } from "../../../utils/validators.js";
|
|
4
|
-
import
|
|
5
|
+
import { getTemplate } from "../../../utils/general.js";
|
|
5
6
|
export const generateHook = async (folder, name, options) => {
|
|
6
7
|
const config = loadConfig() ?? {};
|
|
7
8
|
const useTs = options.ts ?? config.typescript ?? isTypescriptUsed();
|
|
8
9
|
const langExt = useTs ? "ts" : "js";
|
|
9
10
|
return {
|
|
10
11
|
path: path.join(folder, `${name}.${langExt}`),
|
|
11
|
-
content:
|
|
12
|
+
content: getTemplate("hook").replace(/__NAME__/g, name),
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=generateHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateHook.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateHook.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"generateHook.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateHook.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAc,EACd,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC,UAAU,IAAI,gBAAgB,EAAE,CAAC;IACpE,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;QAC7C,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -10,7 +10,7 @@ export const runGenerateComponent = async (rootDir, name, options) => {
|
|
|
10
10
|
process.exitCode = 1;
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
const folder = createDir(`${rootDir}/${options.dir ?? "
|
|
13
|
+
const folder = createDir(`${rootDir}/${options.dir ?? "components"}/${name}`);
|
|
14
14
|
if (!folder) {
|
|
15
15
|
warning(`Folder ${name} already exists!`);
|
|
16
16
|
process.exitCode = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runGenerateComponent.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACvC,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"runGenerateComponent.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACvC,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC,CAAC;IAC9E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,CAAC,GAAG,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -10,7 +10,7 @@ export const runGenerateHook = async (rootDir, name, options) => {
|
|
|
10
10
|
process.exitCode = 1;
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
const folder = createDir(`${rootDir}/${options.dir ?? "
|
|
13
|
+
const folder = createDir(`${rootDir}/${options.dir ?? "hooks"}/${name}`);
|
|
14
14
|
if (!folder) {
|
|
15
15
|
warning(`Folder ${name} already exists!`);
|
|
16
16
|
process.exitCode = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runGenerateHook.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;QACrC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"runGenerateHook.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;QACrC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;IACzE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACvD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,CAAC,GAAG,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new.constants.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,QAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"new.constants.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,QAA2B,CAAC;AACzD,eAAO,MAAM,SAAS,YAAI,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,CAAU,CAAC;AACrF,eAAO,MAAM,gBAAgB,YAAI,WAAW,EAAE,WAAW,CAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new.constants.js","sourceRoot":"","sources":["../../../src/commands/new/new.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"new.constants.js","sourceRoot":"","sources":["../../../src/commands/new/new.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,CAAU,CAAC;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,WAAW,CAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,eAAO,MAAM,kBAAkB,YAAa,OAAO,SAqClD,CAAC"}
|
package/dist/commands/new/new.js
CHANGED
|
@@ -1,50 +1,39 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import { spawnSync } from "child_process";
|
|
4
3
|
import { error, info, warning } from "../../utils/console.js";
|
|
5
|
-
import { VALID_REACT_NAME } from "./new.constants.js";
|
|
4
|
+
import { CUSTOM_TEMPLATES, TEMPLATES, VALID_REACT_NAME, } from "./new.constants.js";
|
|
5
|
+
import { runCustomTemplate } from "./utils/runCustomTemplate.js";
|
|
6
|
+
import { runCreateVite } from "./utils/runCreateVite.js";
|
|
7
|
+
import { isCustomTemplate, isInvalidTemplate } from "./utils/general.js";
|
|
6
8
|
export const registerNewCommand = (program) => {
|
|
7
9
|
program
|
|
8
10
|
.command("new <name>")
|
|
9
11
|
.description("Create a new React project with Vite")
|
|
10
|
-
.
|
|
12
|
+
.option("-t, --template <template>", "apply a react Vite template. Use (custom-ts or custom-js) for a custom src layout")
|
|
13
|
+
.action((name, options) => {
|
|
11
14
|
if (!VALID_REACT_NAME.test(name)) {
|
|
12
15
|
error(`Invalid name ${name}`);
|
|
13
16
|
process.exitCode = 1;
|
|
14
17
|
return;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
if (isInvalidTemplate(options.template)) {
|
|
20
|
+
const templates = [...TEMPLATES, ...CUSTOM_TEMPLATES].join(", ");
|
|
21
|
+
error(`Invalid template ${options.template}`);
|
|
22
|
+
info(`You can choose between: ${templates}`);
|
|
19
23
|
process.exitCode = 1;
|
|
20
24
|
return;
|
|
21
25
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
const vitePassed = result.status === 0;
|
|
27
|
-
if (!vitePassed && !fs.existsSync(target)) {
|
|
28
|
-
error("Vite failed before creating the project.");
|
|
26
|
+
const target = path.join(process.cwd(), name);
|
|
27
|
+
if (fs.existsSync(target)) {
|
|
28
|
+
warning(`Folder ${name} already exists!`);
|
|
29
29
|
process.exitCode = 1;
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
+
runCreateVite(name, target, options.template);
|
|
32
33
|
fs.writeFileSync(path.join(target, "ct.config.json"), "{}");
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
const retry = spawnSync("npm install --legacy-peer-deps", {
|
|
36
|
-
cwd: target,
|
|
37
|
-
stdio: "inherit",
|
|
38
|
-
shell: true,
|
|
39
|
-
});
|
|
40
|
-
if (retry.status !== 0) {
|
|
41
|
-
error("Install failed again. Finish it manually:");
|
|
42
|
-
info(`cd ${name}\nnpm install --legacy-peer-deps`);
|
|
43
|
-
process.exitCode = 1;
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
34
|
+
if (isCustomTemplate(options.template)) {
|
|
35
|
+
runCustomTemplate(target, options);
|
|
46
36
|
}
|
|
47
|
-
info(`\nDone! Next steps:\n\ncd ${name}\nnpm run dev`);
|
|
48
37
|
});
|
|
49
38
|
};
|
|
50
39
|
//# sourceMappingURL=new.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAIzE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CACL,2BAA2B,EAC3B,mFAAmF,CACpF;SACA,MAAM,CAAC,CAAC,IAAY,EAAE,OAAgB,EAAE,EAAE;QACzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,KAAK,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,IAAI,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,MAAM,SAAS,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjE,KAAK,CAAC,oBAAoB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9C,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;YAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE9C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CUSTOM_TEMPLATES, TEMPLATES } from "./new.constants.js";
|
|
2
|
+
export type Template = (typeof TEMPLATES)[number];
|
|
3
|
+
export type CustomTemplate = (typeof CUSTOM_TEMPLATES)[number];
|
|
4
|
+
export interface Options {
|
|
5
|
+
template?: Template | CustomTemplate;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=new.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.types.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,QAAQ,GAAG,cAAc,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.types.js","sourceRoot":"","sources":["../../../src/commands/new/new.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/general.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,cAAe,MAAM,6BAGR,CAAC;AAE5C,eAAO,MAAM,gBAAgB,cAAe,MAAM,6BACiB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CUSTOM_TEMPLATES, TEMPLATES } from "../new.constants.js";
|
|
2
|
+
export const isInvalidTemplate = (template) => template &&
|
|
3
|
+
!CUSTOM_TEMPLATES.includes(template) &&
|
|
4
|
+
!TEMPLATES.includes(template);
|
|
5
|
+
export const isCustomTemplate = (template) => template && CUSTOM_TEMPLATES.includes(template);
|
|
6
|
+
//# sourceMappingURL=general.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/general.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGlE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAiB,EAAE,EAAE,CACrD,QAAQ;IACR,CAAC,gBAAgB,CAAC,QAAQ,CAAC,QAA0B,CAAC;IACtD,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAoB,CAAC,CAAC;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAiB,EAAE,EAAE,CACpD,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,CAAC,QAA0B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCommand.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,MAAM,WAAW,MAAM,mEAKvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runCommand.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,MAAe,EAAE,EAAE,CAC7D,SAAS,CAAC,OAAO,EAAE;IACjB,GAAG,CAAC,MAAM,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAC9B,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,IAAI;CACZ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runCreateVite.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCreateVite.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,aAAa,SAClB,MAAM,UACJ,MAAM,aACH,MAAM,SAmBlB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { warning, error, info } from "../../../utils/console.js";
|
|
3
|
+
import { TEMPLATES } from "../new.constants.js";
|
|
4
|
+
import { runCommand } from "./runCommand.js";
|
|
5
|
+
// Utility
|
|
6
|
+
const retryInstallDependencies = (name, target) => {
|
|
7
|
+
warning("Install failed (dependency conflict). Retrying with --legacy-peer-deps...");
|
|
8
|
+
const retry = runCommand("npm install --legacy-peer-deps", target);
|
|
9
|
+
if (retry.status !== 0) {
|
|
10
|
+
error("Install failed again. Finish it manually:");
|
|
11
|
+
info(`cd ${name}\nnpm install --legacy-peer-deps`);
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const runCreateVite = (name, target, template) => {
|
|
17
|
+
const createViteCommand = template
|
|
18
|
+
? TEMPLATES.includes(template)
|
|
19
|
+
? `npm create vite@latest ${name} -- --template ${template} --no-interactive`
|
|
20
|
+
: `npm create vite@latest ${name} -- --template ${template.endsWith("-ts") ? "react-ts" : "react"} --no-interactive`
|
|
21
|
+
: `npm create vite@latest ${name}`;
|
|
22
|
+
const result = runCommand(createViteCommand);
|
|
23
|
+
const vitePassed = result.status === 0;
|
|
24
|
+
if (!vitePassed && !fs.existsSync(target)) {
|
|
25
|
+
error("Vite failed before creating the project.");
|
|
26
|
+
process.exitCode = 1;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!vitePassed)
|
|
30
|
+
retryInstallDependencies(name, target);
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=runCreateVite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runCreateVite.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCreateVite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,i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AAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runCustomTemplate.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCustomTemplate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,eAAO,MAAM,iBAAiB,WAAY,MAAM,WAAW,OAAO,SAkBjE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
// Utility
|
|
4
|
+
const removeDefaultFiles = (target, files) => {
|
|
5
|
+
for (const file in files)
|
|
6
|
+
fs.rmSync(path.join(target, file), { force: true });
|
|
7
|
+
fs.rmSync(path.join(target, "src/assets"), { recursive: true, force: true });
|
|
8
|
+
};
|
|
9
|
+
export const runCustomTemplate = (target, options) => {
|
|
10
|
+
if (!options.template)
|
|
11
|
+
return;
|
|
12
|
+
const isTs = options.template.endsWith("-ts");
|
|
13
|
+
const variant = isTs ? "react-ts" : "react";
|
|
14
|
+
const overlay = new URL(`../../../../templates/${variant}`, import.meta.url);
|
|
15
|
+
const ext = isTs ? "tsx" : "jsx";
|
|
16
|
+
const filesToRemove = [
|
|
17
|
+
`src/App.${ext}`,
|
|
18
|
+
"src/App.css",
|
|
19
|
+
"src/index.css",
|
|
20
|
+
".oxlintrc.json",
|
|
21
|
+
];
|
|
22
|
+
removeDefaultFiles(target, filesToRemove);
|
|
23
|
+
fs.cpSync(overlay, target, { recursive: true });
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=runCustomTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runCustomTemplate.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCustomTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,UAAU;AACV,MAAM,kBAAkB,GA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AK,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,CAAC;AAE7D,eAAO,MAAM,WAAW,aAAc,QAAQ,WAI3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general.js","sourceRoot":"","sources":["../../src/utils/general.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAkB,EAAE,EAAE,CAChD,EAAE,CAAC,YAAY,CACb,IAAI,GAAG,CAAC,mBAAmB,QAAQ,MAAM,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAC3D,OAAO,CACR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pavlos-samaras/react-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"author": "sammern-stack",
|
|
5
5
|
"description": "A CLI to generate React code",
|
|
6
6
|
"keywords": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"typescript": "^7.0.2"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
|
-
"dist"
|
|
35
|
+
"dist",
|
|
36
|
+
"templates"
|
|
36
37
|
]
|
|
37
38
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# React + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
6
|
+
|
|
7
|
+
export default defineConfig([
|
|
8
|
+
globalIgnores(['dist']),
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.{js,jsx}'],
|
|
11
|
+
extends: [
|
|
12
|
+
js.configs.recommended,
|
|
13
|
+
reactHooks.configs.flat.recommended,
|
|
14
|
+
reactRefresh.configs.vite,
|
|
15
|
+
],
|
|
16
|
+
languageOptions: {
|
|
17
|
+
ecmaVersion: 2020,
|
|
18
|
+
globals: globals.browser,
|
|
19
|
+
parserOptions: {
|
|
20
|
+
ecmaVersion: 'latest',
|
|
21
|
+
ecmaFeatures: { jsx: true },
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
])
|