create-sb-react 1.0.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.
Files changed (2) hide show
  1. package/index.js +288 -0
  2. package/package.json +27 -0
package/index.js ADDED
@@ -0,0 +1,288 @@
1
+ #!/usr/bin/env node
2
+
3
+ import inquirer from "inquirer";
4
+ import { execSync } from "child_process";
5
+ import fs from "fs-extra";
6
+
7
+ console.log("🚀 Welcome to SB React CLI");
8
+
9
+ const answers = await inquirer.prompt([
10
+ {
11
+ type: "input",
12
+ name: "projectName",
13
+ message: "Project Name?"
14
+ },
15
+ {
16
+ type: "select",
17
+ name: "language",
18
+ message: "Choose Language",
19
+ choices: [
20
+ {
21
+ name: "JavaScript",
22
+ value: "javascript"
23
+ },
24
+ {
25
+ name: "TypeScript",
26
+ value: "typescript"
27
+ }
28
+ ]
29
+ },
30
+ {
31
+ type: "select",
32
+ name: "style",
33
+ message: "Choose Styling",
34
+ choices: [
35
+ {
36
+ name: "Tailwind",
37
+ value: "tailwind"
38
+ },
39
+ {
40
+ name: "SCSS",
41
+ value: "scss"
42
+ }
43
+ ]
44
+ }
45
+ ]);
46
+
47
+ const template =
48
+ answers.language === "typescript"
49
+ ? "react-ts"
50
+ : "react";
51
+
52
+ console.log("📦 Creating Vite project...");
53
+
54
+ execSync(
55
+ `npx create-vite@latest ${answers.projectName} --template ${template}`,
56
+ {
57
+ stdio: ["pipe", "inherit", "inherit"],
58
+ input: "n\n"
59
+ }
60
+ );
61
+
62
+ process.chdir(answers.projectName);
63
+
64
+ console.log("📦 Installing common packages...");
65
+
66
+ execSync(
67
+ "npm install axios react-router-dom husky",
68
+ {
69
+ stdio: "inherit"
70
+ }
71
+ );
72
+
73
+ console.log("🔤 Installing cspell...");
74
+
75
+ execSync(
76
+ "npm install --save-dev cspell",
77
+ {
78
+ stdio: "inherit"
79
+ }
80
+ );
81
+
82
+ const packageJson = fs.readJsonSync("package.json");
83
+ packageJson.scripts["spell-check"] = "cspell \"src/**/*.{js,jsx,ts,tsx,scss}\"";
84
+ fs.writeJsonSync("package.json", packageJson, { spaces: 2 });
85
+
86
+ fs.writeJsonSync("cspell.json", {
87
+ words: [
88
+ "axios",
89
+ "zustand",
90
+ "tailwind",
91
+ "scss",
92
+ "vite",
93
+ "reactdom",
94
+ "husky"
95
+ ]
96
+ }, { spaces: 2 });
97
+
98
+ console.log("🐶 Setting up Husky...");
99
+
100
+ execSync("git init", { stdio: "inherit" });
101
+ execSync("npx husky init", { stdio: "inherit" });
102
+ fs.writeFileSync(
103
+ ".husky/pre-commit",
104
+ "npm run lint\nnpm run spell-check\nnpm run build\n"
105
+ );
106
+
107
+ if (answers.style === "tailwind") {
108
+ console.log("🎨 Installing Tailwind CSS...");
109
+
110
+ execSync(
111
+ "npm install tailwindcss @tailwindcss/vite",
112
+ {
113
+ stdio: "inherit"
114
+ }
115
+ );
116
+ } else {
117
+ console.log("🎨 Installing SCSS...");
118
+
119
+ execSync(
120
+ "npm install sass",
121
+ {
122
+ stdio: "inherit"
123
+ }
124
+ );
125
+ }
126
+
127
+ console.log("📁 Creating folder structure...");
128
+
129
+ const folders = [
130
+ "src/assets",
131
+ "src/components",
132
+ "src/containers",
133
+ "src/constants",
134
+ "src/hooks",
135
+ "src/routes",
136
+ "src/services",
137
+ "src/styles",
138
+ "src/utils"
139
+ ];
140
+
141
+ folders.forEach(folder => {
142
+ fs.mkdirSync(folder, { recursive: true });
143
+ });
144
+
145
+ console.log("🧹 Removing default Vite files...");
146
+
147
+ fs.removeSync("src/assets/react.svg");
148
+ fs.removeSync("src/App.css");
149
+
150
+ const appFile =
151
+ answers.language === "typescript"
152
+ ? "src/App.tsx"
153
+ : "src/App.jsx";
154
+
155
+ const mainFile =
156
+ answers.language === "typescript"
157
+ ? "src/main.tsx"
158
+ : "src/main.jsx";
159
+
160
+ const viteConfigFile =
161
+ answers.language === "typescript"
162
+ ? "vite.config.ts"
163
+ : "vite.config.js";
164
+
165
+ if (answers.style === "tailwind") {
166
+ fs.writeFileSync(
167
+ viteConfigFile,
168
+ `
169
+ import { defineConfig } from "vite";
170
+ import react from "@vitejs/plugin-react";
171
+ import tailwindcss from "@tailwindcss/vite";
172
+
173
+ export default defineConfig({
174
+ plugins: [react(), tailwindcss()],
175
+ });
176
+ `
177
+ );
178
+
179
+ fs.writeFileSync(
180
+ "src/index.css",
181
+ `
182
+ @import "tailwindcss";
183
+ `
184
+ );
185
+ }
186
+
187
+ if (answers.style === "scss") {
188
+ fs.removeSync("src/index.css");
189
+
190
+ fs.writeFileSync(
191
+ "src/styles/variables.scss",
192
+ `
193
+ $primary: #aa3bff;
194
+ $text: #08060d;
195
+ $bg: #fff;
196
+ $border: #e5e4e7;
197
+ `
198
+ );
199
+
200
+ fs.writeFileSync(
201
+ "src/styles/global.scss",
202
+ `
203
+ @use "variables" as *;
204
+
205
+ body {
206
+ margin: 0;
207
+ padding: 0;
208
+ font-family: sans-serif;
209
+ background: $bg;
210
+ color: $text;
211
+ }
212
+ `
213
+ );
214
+ }
215
+
216
+ if (answers.style === "scss") {
217
+ fs.writeFileSync(
218
+ appFile,
219
+ `
220
+ import "./styles/global.scss";
221
+
222
+ function App() {
223
+ return (
224
+ <div>
225
+ <h1>Hello SB React 🚀</h1>
226
+ </div>
227
+ );
228
+ }
229
+
230
+ export default App;
231
+ `
232
+ );
233
+ } else {
234
+ fs.writeFileSync(
235
+ appFile,
236
+ `
237
+ function App() {
238
+ return (
239
+ <div>
240
+ <h1>Hello SB React 🚀</h1>
241
+ </div>
242
+ );
243
+ }
244
+
245
+ export default App;
246
+ `
247
+ );
248
+ }
249
+
250
+ if (answers.style === "tailwind") {
251
+ fs.writeFileSync(
252
+ mainFile,
253
+ `
254
+ import React from "react";
255
+ import ReactDOM from "react-dom/client";
256
+ import App from "./App";
257
+ import "./index.css";
258
+
259
+ ReactDOM.createRoot(document.getElementById("root")).render(
260
+ <React.StrictMode>
261
+ <App />
262
+ </React.StrictMode>
263
+ );
264
+ `
265
+ );
266
+ } else {
267
+ fs.writeFileSync(
268
+ mainFile,
269
+ `
270
+ import React from "react";
271
+ import ReactDOM from "react-dom/client";
272
+ import App from "./App";
273
+
274
+ ReactDOM.createRoot(document.getElementById("root")).render(
275
+ <React.StrictMode>
276
+ <App />
277
+ </React.StrictMode>
278
+ );
279
+ `
280
+ );
281
+ }
282
+
283
+ console.log("");
284
+ console.log("✅ Project setup completed successfully!");
285
+ console.log("");
286
+ console.log(`👉 cd ${answers.projectName}`);
287
+ console.log("👉 npm run dev");
288
+
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "create-sb-react",
3
+ "version": "1.0.0",
4
+ "description": "React Vite CLI",
5
+ "bin": {
6
+ "create-sb-react": "./index.js"
7
+ },
8
+ "type": "module",
9
+ "preferGlobal": true,
10
+ "files": [
11
+ "index.js"
12
+ ],
13
+ "keywords": [
14
+ "react",
15
+ "vite",
16
+ "cli",
17
+ "tailwind"
18
+ ],
19
+ "author": "Arjunan",
20
+ "license": "ISC",
21
+ "dependencies": {
22
+ "chalk": "^5.3.0",
23
+ "fs-extra": "^11.2.0",
24
+ "inquirer": "^9.2.15",
25
+ "ora": "^8.0.1"
26
+ }
27
+ }