create-zerra-app 1.2.0 → 1.2.2

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/index.js CHANGED
@@ -26,6 +26,16 @@ program
26
26
  { name: "Firebase", value: "js-firebase" },
27
27
  ],
28
28
  },
29
+ {
30
+ type: "list",
31
+ name: "language",
32
+ message: "Choose your primary language:",
33
+ choices: [
34
+ { name: "JavaScript", value: "js" },
35
+ { name: "TypeScript", value: "ts" },
36
+ ],
37
+ default: "js",
38
+ },
29
39
  {
30
40
  type: "confirm",
31
41
  name: "includeAuth",
@@ -44,7 +54,10 @@ program
44
54
  { name: "Automatic Input Validation (Schema)", value: "validation", checked: true },
45
55
  { name: "Multipart File Uploads (req.files)", value: "multipart", checked: true },
46
56
  { name: "Smart Error Handling (_error.js)", value: "errors", checked: true },
47
- { name: "Dev Dashboard (/__zerra)", value: "dashboard", checked: true }
57
+ { name: "Dev Dashboard (/__zerra)", value: "dashboard", checked: true },
58
+ { name: "Static File Serving (public/)", value: "static", checked: true },
59
+ { name: "Built-in Rate Limiting", value: "rateLimiting", checked: false },
60
+ { name: "Cron Job Scheduler (jobs/)", value: "cron", checked: true }
48
61
  ]
49
62
  },
50
63
  {
@@ -66,6 +79,7 @@ program
66
79
  console.log(` - Project Name: \x1b[36m${projectName}\x1b[0m`);
67
80
  console.log(` - Database: \x1b[33m${answers.database.replace('js-', '')}\x1b[0m`);
68
81
  console.log(` - Auth Starter: \x1b[32m${answers.includeAuth ? 'Enabled' : 'Disabled'}\x1b[0m`);
82
+ console.log(` - Language: \x1b[36m${answers.language.toUpperCase()}\x1b[0m`);
69
83
  console.log(` - Features: \x1b[35m${answers.features.join(', ') || 'None'}\x1b[0m`);
70
84
  console.log(` - Auto-Install: \x1b[32m${answers.installDeps ? 'Yes' : 'No'}\x1b[0m`);
71
85
  console.log(` - Git Init: \x1b[32m${answers.initGit ? 'Yes' : 'No'}\x1b[0m`);
@@ -143,9 +157,67 @@ program
143
157
  if (fs.existsSync(pkgPath)) {
144
158
  const pkg = await fs.readJson(pkgPath);
145
159
  pkg.name = projectName;
160
+
161
+ if (answers.language === 'ts') {
162
+ pkg.devDependencies = {
163
+ ...(pkg.devDependencies || {}),
164
+ "typescript": "^5.0.0",
165
+ "@types/node": "^20.0.0",
166
+ "tsx": "^4.0.0"
167
+ };
168
+ pkg.scripts = {
169
+ ...(pkg.scripts || {}),
170
+ "dev": "tsx watch server.js",
171
+ "build": "tsc",
172
+ "start": "node server.js"
173
+ };
174
+ }
146
175
  await fs.writeJson(pkgPath, pkg, { spaces: 2 });
147
176
  }
148
177
 
178
+ // 3.5 Handle TypeScript File Renaming and tsconfig
179
+ if (answers.language === 'ts') {
180
+ console.log(` TypeScript-ifying your project...`);
181
+
182
+ // Generate tsconfig.json
183
+ const tsconfig = {
184
+ compilerOptions: {
185
+ target: "ESNext",
186
+ module: "CommonJS",
187
+ moduleResolution: "node",
188
+ esModuleInterop: true,
189
+ forceConsistentCasingInFileNames: true,
190
+ strict: true,
191
+ skipLibCheck: true,
192
+ outDir: "./dist"
193
+ },
194
+ include: ["api/**/*", "services/**/*", "server.js", "zerra.config.json"]
195
+ };
196
+ await fs.writeJson(path.join(targetPath, "tsconfig.json"), tsconfig, { spaces: 2 });
197
+
198
+ // Recursive function to rename .js to .ts
199
+ const renameJsToTs = async (dir) => {
200
+ const files = await fs.readdir(dir);
201
+ for (const file of files) {
202
+ const fullPath = path.join(dir, file);
203
+ const stat = await fs.stat(fullPath);
204
+ if (stat.isDirectory()) {
205
+ await renameJsToTs(fullPath);
206
+ } else if (file.endsWith(".js") && !file.startsWith("server.js")) {
207
+ const newPath = fullPath.replace(/\.js$/, ".ts");
208
+ await fs.move(fullPath, newPath);
209
+ }
210
+ }
211
+ };
212
+
213
+ if (fs.existsSync(path.join(targetPath, "api"))) {
214
+ await renameJsToTs(path.join(targetPath, "api"));
215
+ }
216
+ if (fs.existsSync(path.join(targetPath, "services"))) {
217
+ await renameJsToTs(path.join(targetPath, "services"));
218
+ }
219
+ }
220
+
149
221
  // 4. Generate zerra.config.json based on feature selection
150
222
  const featureConfig = {
151
223
  logging: answers.features.includes('logging'),
@@ -155,12 +227,28 @@ program
155
227
  validation: answers.features.includes('validation'),
156
228
  multipart: answers.features.includes('multipart'),
157
229
  errors: answers.features.includes('errors'),
158
- dashboard: answers.features.includes('dashboard')
230
+ dashboard: answers.features.includes('dashboard'),
231
+ static: answers.features.includes('static'),
232
+ rateLimiting: answers.features.includes('rateLimiting'),
233
+ cron: answers.features.includes('cron')
159
234
  };
160
235
 
161
236
  const configJsonPath = path.join(targetPath, 'zerra.config.json');
162
237
  await fs.writeJson(configJsonPath, { features: featureConfig, plugins: [] }, { spaces: 2 });
163
238
 
239
+ // 4.5 Generate .gitignore for the new project
240
+ const gitignoreContent = `node_modules/
241
+ dist/
242
+ build/
243
+ .env
244
+ .env.local
245
+ .env.*.local
246
+ *.log
247
+ .DS_Store
248
+ ${answers.language === 'ts' ? '*.tsbuildinfo' : ''}
249
+ `;
250
+ await fs.writeFile(path.join(targetPath, '.gitignore'), gitignoreContent);
251
+
164
252
  const { execSync } = require("child_process");
165
253
 
166
254
  if (answers.installDeps) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-zerra-app",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -5,6 +5,6 @@
5
5
  "dev": "node server.js"
6
6
  },
7
7
  "dependencies": {
8
- "zerra-core": "^1.2.0"
8
+ "zerra-core": "^1.2.1"
9
9
  }
10
10
  }