-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateProjectStructureFromText.js
More file actions
146 lines (137 loc) · 5.52 KB
/
createProjectStructureFromText.js
File metadata and controls
146 lines (137 loc) · 5.52 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const fs = require('fs');
const path = require('path');
// Sample folder structure in string format
const folderStructure = `
/codebet-backend
│
├── /src
│ ├── /config # Configuration files (e.g., environment variables, database connection)
│ │ ├── config.js
│ │ ├── db.js
│ │ └── dotenv.js
│ │
│ ├── /controllers # Controllers handle the request and response logic
│ │ ├── authController.js
│ │ ├── userController.js
│ │ ├── groupController.js
│ │ ├── challengeController.js
│ │ ├── walletController.js
│ │ ├── leaderboardController.js
│ │ ├── notificationController.js
│ │ └── adminController.js
│ │
│ ├── /models # Mongoose models/schemas
│ │ ├── User.js
│ │ ├── Group.js
│ │ ├── Challenge.js
│ │ ├── Submission.js
│ │ ├── Wallet.js
│ │ ├── Transaction.js
│ │ ├── Notification.js
│ │ └── Admin.js
│ │
│ ├── /routes # API routes
│ │ ├── authRoutes.js
│ │ ├── userRoutes.js
│ │ ├── groupRoutes.js
│ │ ├── challengeRoutes.js
│ │ ├── walletRoutes.js
│ │ ├── leaderboardRoutes.js
│ │ ├── notificationRoutes.js
│ │ └── adminRoutes.js
│ │
│ ├── /middleware # Express middleware (e.g., authentication, error handling)
│ │ ├── authMiddleware.js
│ │ ├── errorMiddleware.js
│ │ ├── validationMiddleware.js
│ │ └── adminMiddleware.js
│ │
│ ├── /services # Services that handle business logic and integrate with third-party APIs
│ │ ├── authService.js
│ │ ├── userService.js
│ │ ├── groupService.js
│ │ ├── challengeService.js
│ │ ├── walletService.js
│ │ ├── leaderboardService.js
│ │ ├── notificationService.js
│ │ └── adminService.js
│ │
│ ├── /utils # Utility functions and helpers
│ │ ├── jwtUtils.js
│ │ ├── cryptoUtils.js
│ │ ├── responseUtils.js
│ │ ├── logger.js
│ │ └── constants.js
│ │
│ ├── /tests # Unit and integration tests
│ │ ├── auth.test.js
│ │ ├── user.test.js
│ │ ├── group.test.js
│ │ ├── challenge.test.js
│ │ ├── wallet.test.js
│ │ └── integration.test.js
│ │
│ ├── /docs # Documentation (e.g., API documentation using Swagger)
│ │ ├── swagger.yaml
│ │ └── readme.md
│ │
│ ├── app.js # Express app setup
│ ├── server.js # Server entry point
│ ├── .env # Environment variables
│ ├── .gitignore # Git ignore file
│ ├── package.json # Node.js dependencies and scripts
│ └── README.md # Project documentation
│
└── /scripts # Scripts for tasks like database seeding, migrations, etc.
├── seed.js
└── migrate.js
`;
// Function to parse the folder structure string and create directories/files
function parseStructure(basePath, structure) {
const lines = structure.trim().split('\n');
let currentPath = basePath;
let pathStack = [currentPath];
let currentIndent = 0;
lines.forEach(line => {
const trimmedLine = line.trim();
if (trimmedLine === '' || trimmedLine === '│') return;
const match = trimmedLine.match(/^(│\s*)*([├└]── )(.+)/);
if (match) {
const indent = (match[1] || '').length / 2;
const name = match[3].split('#')[0].trim();
// Adjust current path based on indent level
if (indent > currentIndent) {
currentPath = pathStack[pathStack.length - 1];
} else if (indent < currentIndent) {
for (let i = 0; i <= currentIndent - indent; i++) {
pathStack.pop();
}
currentPath = pathStack[pathStack.length - 1];
}
currentIndent = indent;
const fullPath = path.join(currentPath, name);
if (name.includes('.')) {
// It's a file
fs.writeFileSync(fullPath, '');
console.log(`Created file: ${fullPath}`);
} else {
// It's a directory
fs.mkdirSync(fullPath, { recursive: true });
console.log(`Created directory: ${fullPath}`);
currentPath = fullPath;
pathStack.push(currentPath);
}
} else if (trimmedLine.startsWith('/')) {
// Root directory
currentPath = path.join(basePath, trimmedLine.slice(1));
fs.mkdirSync(currentPath, { recursive: true });
console.log(`Created root directory: ${currentPath}`);
pathStack = [currentPath];
currentIndent = 0;
}
});
}
// Run the function with the desired base path and folder structure
const basePath = path.join(__dirname, 'codebet-backend');
parseStructure(basePath, folderStructure);
console.log('Project structure created successfully!');