create-react-folder-structure 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.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/bin/cli.js +178 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright Amol Mahor (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# create-react-folder-structure 🚀
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/create-react-folder-structure)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
> **All-in-One Command**: Initializes a fresh **Vite + React + Tailwind + Shadcn UI** project and automatically scaffolds a clean, scalable folder structure with zero component clutter.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ⚡ One Single Command
|
|
11
|
+
|
|
12
|
+
To initialize a new project and scaffold all folders in one step:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx create-react-folder-structure my-app
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
or run inside an empty directory:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx create-react-folder-structure .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🛠️ What This Single Command Does
|
|
27
|
+
|
|
28
|
+
1. **Initializes Shadcn UI + Vite**:
|
|
29
|
+
Automatically runs `shadcn@latest init --preset b0 --template vite` (sets up Vite, TypeScript, Tailwind CSS, and Shadcn configuration).
|
|
30
|
+
2. **Generates Pure Folder Structure**:
|
|
31
|
+
Instantly creates your clean architecture folders inside `src/`—**folders only**, with no dummy components or unwanted files!
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 📂 Generated Structure (Directories Only)
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
src/
|
|
39
|
+
├── components/
|
|
40
|
+
│ ├── shared/ # Business-specific shared components
|
|
41
|
+
│ └── ui/ # Where shadcn places button.tsx, dialog.tsx, etc.
|
|
42
|
+
├── layouts/ # Layout containers (Sidebar, Header, MainLayout)
|
|
43
|
+
├── pages/ # Clean, empty pages folder
|
|
44
|
+
├── routes/ # Routing configs
|
|
45
|
+
├── hooks/ # Custom React hooks
|
|
46
|
+
├── services/ # API clients & backend communication
|
|
47
|
+
├── contexts/ # Global React state providers
|
|
48
|
+
├── constants/ # Static enums, endpoints, role IDs
|
|
49
|
+
├── types/ # TypeScript interfaces and domain models
|
|
50
|
+
├── utils/ # Utility functions and date/formatting helpers
|
|
51
|
+
└── validation/ # Schema validation (Zod, Yup, etc.)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## ⚙️ Options & CLI Flags
|
|
57
|
+
|
|
58
|
+
| Command / Flag | Description |
|
|
59
|
+
| :--- | :--- |
|
|
60
|
+
| `npx create-react-folder-structure [name]` | Full setup: Init Shadcn Vite + scaffold folders *(Default)* |
|
|
61
|
+
| `--folders-only` | Skip Shadcn init; only scaffold folders in an existing project |
|
|
62
|
+
| `--minimal` | Minimal folders (`components`, `pages`, `hooks`, `services`, `utils`, `validation`) |
|
|
63
|
+
| `-h`, `--help` | Show command help and documentation |
|
|
64
|
+
| `-v`, `--version` | Show package version |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🔒 Non-Destructive Guarantee
|
|
69
|
+
|
|
70
|
+
Safe to run in existing projects. Existing files and directories will **never** be overwritten.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 📄 License
|
|
75
|
+
|
|
76
|
+
MIT © Amol Mahor 2026
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { spawnSync } from 'child_process';
|
|
6
|
+
|
|
7
|
+
// ANSI terminal colors
|
|
8
|
+
const colors = {
|
|
9
|
+
reset: '\x1b[0m',
|
|
10
|
+
bright: '\x1b[1m',
|
|
11
|
+
dim: '\x1b[2m',
|
|
12
|
+
cyan: '\x1b[36m',
|
|
13
|
+
green: '\x1b[32m',
|
|
14
|
+
yellow: '\x1b[33m',
|
|
15
|
+
red: '\x1b[31m',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const rawArgs = process.argv.slice(2);
|
|
19
|
+
|
|
20
|
+
// Handle --help or -h
|
|
21
|
+
if (rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
22
|
+
console.log(`
|
|
23
|
+
${colors.bright}${colors.cyan}create-react-folder-structure${colors.reset} - All-in-One Vite + Shadcn + Folder Structure Scaffolder
|
|
24
|
+
|
|
25
|
+
${colors.bright}DESCRIPTION:${colors.reset}
|
|
26
|
+
Runs in ONE single command:
|
|
27
|
+
1. Initializes a fresh Vite + React + Tailwind project with Shadcn UI (--preset b0)
|
|
28
|
+
2. Scaffolds a clean, production-grade folder structure (folders only, zero component clutter)
|
|
29
|
+
|
|
30
|
+
${colors.bright}USAGE:${colors.reset}
|
|
31
|
+
npx create-react-folder-structure [project-name] [options]
|
|
32
|
+
npx react-folder-structure [project-name] [options]
|
|
33
|
+
|
|
34
|
+
${colors.bright}EXAMPLES:${colors.reset}
|
|
35
|
+
# Create a new project from scratch (runs Shadcn init + Folder structure):
|
|
36
|
+
npx create-react-folder-structure my-app
|
|
37
|
+
|
|
38
|
+
# Run inside an empty folder:
|
|
39
|
+
npx create-react-folder-structure .
|
|
40
|
+
|
|
41
|
+
# Only scaffold folders in an existing project (skip Shadcn init):
|
|
42
|
+
npx create-react-folder-structure --folders-only
|
|
43
|
+
|
|
44
|
+
${colors.bright}OPTIONS:${colors.reset}
|
|
45
|
+
--folders-only Skip Shadcn initialization; only generate the folder structure
|
|
46
|
+
--minimal Create minimal folders (components, pages, hooks, services, utils, validation)
|
|
47
|
+
--full Create full enterprise folders (Default)
|
|
48
|
+
-h, --help Display this help message
|
|
49
|
+
-v, --version Show current package version
|
|
50
|
+
`);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Handle --version or -v
|
|
55
|
+
if (rawArgs.includes('--version') || rawArgs.includes('-v')) {
|
|
56
|
+
const pkgPath = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '../package.json');
|
|
57
|
+
try {
|
|
58
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
59
|
+
console.log(`v${pkg.version}`);
|
|
60
|
+
} catch {
|
|
61
|
+
console.log('v1.0.0');
|
|
62
|
+
}
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const cwd = process.cwd();
|
|
67
|
+
const isFoldersOnly = rawArgs.includes('--folders-only');
|
|
68
|
+
const isMinimal = rawArgs.includes('--minimal');
|
|
69
|
+
|
|
70
|
+
// Extract project name if provided
|
|
71
|
+
const nonFlagArgs = rawArgs.filter((arg) => !arg.startsWith('-'));
|
|
72
|
+
const projectName = nonFlagArgs[0];
|
|
73
|
+
|
|
74
|
+
let targetProjectDir = cwd;
|
|
75
|
+
if (projectName && projectName !== '.') {
|
|
76
|
+
targetProjectDir = path.resolve(cwd, projectName);
|
|
77
|
+
if (!fs.existsSync(targetProjectDir)) {
|
|
78
|
+
fs.mkdirSync(targetProjectDir, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const hasPackageJson = fs.existsSync(path.join(targetProjectDir, 'package.json'));
|
|
83
|
+
const shouldInitShadcn = !isFoldersOnly && (!hasPackageJson || rawArgs.includes('--init'));
|
|
84
|
+
|
|
85
|
+
console.log(`
|
|
86
|
+
${colors.bright}${colors.cyan}================================================================${colors.reset}
|
|
87
|
+
${colors.bright}🚀 All-in-One Vite + Shadcn + React Folder Structure Creator${colors.reset}
|
|
88
|
+
Target: ${colors.green}${path.relative(cwd, targetProjectDir) || '.'}/${colors.reset}
|
|
89
|
+
${colors.bright}${colors.cyan}================================================================${colors.reset}
|
|
90
|
+
`);
|
|
91
|
+
|
|
92
|
+
// -------------------------------------------------------------
|
|
93
|
+
// STEP 1: Initialize Shadcn UI + Vite (--preset b0)
|
|
94
|
+
// -------------------------------------------------------------
|
|
95
|
+
if (shouldInitShadcn) {
|
|
96
|
+
console.log(`${colors.bright}📦 Step 1/2: Initializing project with Shadcn UI & Vite (--preset b0)...${colors.reset}\n`);
|
|
97
|
+
|
|
98
|
+
const shadcnArgs = ['-y', 'shadcn@latest', 'init', '--preset', 'b0', '--template', 'vite', '-y'];
|
|
99
|
+
|
|
100
|
+
const initResult = spawnSync('npx', shadcnArgs, {
|
|
101
|
+
cwd: targetProjectDir,
|
|
102
|
+
stdio: 'inherit',
|
|
103
|
+
shell: true,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (initResult.status !== 0) {
|
|
107
|
+
console.error(`\n${colors.red}❌ Failed to initialize project with Shadcn UI.${colors.reset}`);
|
|
108
|
+
process.exit(initResult.status || 1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log(`\n${colors.green}✔ Step 1 complete: Shadcn + Vite project initialized!${colors.reset}\n`);
|
|
112
|
+
} else {
|
|
113
|
+
console.log(`${colors.dim}↷ Step 1 skipped: Existing project detected (or --folders-only passed).${colors.reset}\n`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// -------------------------------------------------------------
|
|
117
|
+
// STEP 2: Scaffold Pure Folder Structure (No Dummy Components)
|
|
118
|
+
// -------------------------------------------------------------
|
|
119
|
+
console.log(`${colors.bright}📁 Step 2/2: Scaffolding Folder Structure...${colors.reset}`);
|
|
120
|
+
|
|
121
|
+
let targetBaseDir = targetProjectDir;
|
|
122
|
+
const srcDir = path.join(targetProjectDir, 'src');
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(srcDir)) {
|
|
125
|
+
targetBaseDir = srcDir;
|
|
126
|
+
} else if (path.basename(targetProjectDir) !== 'src') {
|
|
127
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
128
|
+
targetBaseDir = srcDir;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const standardFolders = [
|
|
132
|
+
'components/shared',
|
|
133
|
+
'layouts',
|
|
134
|
+
'pages',
|
|
135
|
+
'routes',
|
|
136
|
+
'hooks',
|
|
137
|
+
'services',
|
|
138
|
+
'contexts',
|
|
139
|
+
'constants',
|
|
140
|
+
'types',
|
|
141
|
+
'utils',
|
|
142
|
+
'validation',
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const minimalFolders = [
|
|
146
|
+
'components',
|
|
147
|
+
'pages',
|
|
148
|
+
'hooks',
|
|
149
|
+
'services',
|
|
150
|
+
'utils',
|
|
151
|
+
'validation',
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
const foldersToCreate = isMinimal ? minimalFolders : standardFolders;
|
|
155
|
+
|
|
156
|
+
let createdFoldersCount = 0;
|
|
157
|
+
let skippedFoldersCount = 0;
|
|
158
|
+
|
|
159
|
+
for (const folder of foldersToCreate) {
|
|
160
|
+
const fullPath = path.join(targetBaseDir, folder);
|
|
161
|
+
if (!fs.existsSync(fullPath)) {
|
|
162
|
+
fs.mkdirSync(fullPath, { recursive: true });
|
|
163
|
+
console.log(` ${colors.green}✔ Created:${colors.reset} src/${folder}/`);
|
|
164
|
+
createdFoldersCount++;
|
|
165
|
+
} else {
|
|
166
|
+
skippedFoldersCount++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.log(`
|
|
171
|
+
${colors.bright}${colors.green}🎉 Done! Your project is completely configured & ready!${colors.reset}
|
|
172
|
+
• Shadcn UI + Vite: ${colors.green}Initialized (--preset b0)${colors.reset}
|
|
173
|
+
• Folder Structure: ${colors.green}${createdFoldersCount} created${colors.reset}, ${skippedFoldersCount} existed
|
|
174
|
+
• Files: ${colors.dim}0 files created (folders only)${colors.reset}
|
|
175
|
+
|
|
176
|
+
${colors.bright}To get started:${colors.reset}
|
|
177
|
+
${projectName && projectName !== '.' ? ` cd ${projectName}\n` : ''} npm run dev
|
|
178
|
+
`);
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-react-folder-structure",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI to scaffold a clean, production-ready React folder structure with zero component clutter",
|
|
5
|
+
"main": "bin/cli.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-react-folder-structure": "bin/cli.js",
|
|
9
|
+
"react-folder-structure": "bin/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react",
|
|
13
|
+
"vite",
|
|
14
|
+
"shadcn",
|
|
15
|
+
"folder-structure",
|
|
16
|
+
"scaffold",
|
|
17
|
+
"cli"
|
|
18
|
+
],
|
|
19
|
+
"author": "Amol Mahor",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"files": [
|
|
22
|
+
"bin",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|