forked from harshgupta20/quickstart-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
102 lines (88 loc) · 3.58 KB
/
index.js
File metadata and controls
102 lines (88 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
import inquirer from "inquirer";
import path from "path";
import { run, createFolder, deleteFile } from './lib/utils.js';
import { initializePWA } from './lib/pwa.js';
import { setupCSSFramework } from './lib/css-frameworks.js';
import { createAxiosSetup, createAppComponent, setupRouterMain, createPWAReadme } from './lib/templates.js';
(async () => {
// 1. Collect user inputs
const answers = await inquirer.prompt([
{
type: "input",
name: "projectName",
message: "Enter project name:"
},
{
type: "list",
name: "cssFramework",
message: "Choose a CSS framework:",
choices: ["Tailwind", "Bootstrap (CDN)", "React Bootstrap", "MUI"]
},
{
type: "confirm",
name: "isPWA",
message: "Do you want to make this a Progressive Web App (PWA)?",
default: false
},
{
type: "checkbox",
name: "packages",
message: "Select optional packages:",
choices: [
{ name: "Axios", value: "axios" },
{ name: "React Icons", value: "react-icons" },
{ name: "React Hook Form", value: "react-hook-form" },
{ name: "Yup", value: "yup" },
{ name: "Formik", value: "formik" },
{ name: "Moment.js", value: "moment" }
]
}
]);
const { projectName, cssFramework, isPWA, packages } = answers;
const projectPath = path.join(process.cwd(), projectName);
console.log(`\n🚀 Creating ${projectName}${isPWA ? ' with PWA capabilities' : ''}...`);
// 2. Create Vite project
run(`npm create vite@latest ${projectName} -- --template react`);
// 3. Create all necessary folder structure first
const folders = ["components", "pages", "hooks", "store", "utils", "assets"];
folders.forEach((folder) => {
createFolder(path.join(projectPath, "src", folder));
});
// 4. Install packages
const defaultPackages = ["react-router-dom"];
const allPackages = [...defaultPackages, ...packages];
if (allPackages.length > 0) {
run(`npm install ${allPackages.join(" ")}`, projectPath);
}
// 5. Setup PWA if selected (after folder structure is created)
if (isPWA) {
initializePWA(projectPath, projectName);
}
// 6. Setup CSS framework
setupCSSFramework(cssFramework, projectPath);
// 7. Setup Axios if selected
if (packages.includes("axios")) {
createAxiosSetup(projectPath);
}
// 8. Clean up default boilerplate files
deleteFile(path.join(projectPath, "src", "App.css"));
if (cssFramework !== "Tailwind") {
deleteFile(path.join(projectPath, "src", "index.css"));
}
// 9. Generate clean templates
createAppComponent(projectPath, projectName, isPWA);
setupRouterMain(projectPath, cssFramework);
// 10. Create comprehensive README
createPWAReadme(projectPath, projectName, cssFramework, packages, isPWA);
// 11. Success message
console.log("\n✅ Setup complete!");
if (isPWA) {
console.log("📱 PWA features enabled - your app can be installed on mobile devices!");
console.log("⚠️ Important: Replace placeholder SVG icons with proper PNG icons for production");
}
console.log(`\nNext steps:\n cd ${projectName}\n npm install\n npm run dev`);
if (isPWA) {
console.log(`\n📱 To test PWA:\n npm run build\n npm run preview\n Open http://localhost:4173 and test install/offline features`);
}
})();