create-zerra-app 1.2.0 → 1.2.1
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 +82 -0
- package/package.json +1 -1
- package/templates/js-base/package.json +1 -1
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",
|
|
@@ -66,6 +76,7 @@ program
|
|
|
66
76
|
console.log(` - Project Name: \x1b[36m${projectName}\x1b[0m`);
|
|
67
77
|
console.log(` - Database: \x1b[33m${answers.database.replace('js-', '')}\x1b[0m`);
|
|
68
78
|
console.log(` - Auth Starter: \x1b[32m${answers.includeAuth ? 'Enabled' : 'Disabled'}\x1b[0m`);
|
|
79
|
+
console.log(` - Language: \x1b[36m${answers.language.toUpperCase()}\x1b[0m`);
|
|
69
80
|
console.log(` - Features: \x1b[35m${answers.features.join(', ') || 'None'}\x1b[0m`);
|
|
70
81
|
console.log(` - Auto-Install: \x1b[32m${answers.installDeps ? 'Yes' : 'No'}\x1b[0m`);
|
|
71
82
|
console.log(` - Git Init: \x1b[32m${answers.initGit ? 'Yes' : 'No'}\x1b[0m`);
|
|
@@ -143,9 +154,67 @@ program
|
|
|
143
154
|
if (fs.existsSync(pkgPath)) {
|
|
144
155
|
const pkg = await fs.readJson(pkgPath);
|
|
145
156
|
pkg.name = projectName;
|
|
157
|
+
|
|
158
|
+
if (answers.language === 'ts') {
|
|
159
|
+
pkg.devDependencies = {
|
|
160
|
+
...(pkg.devDependencies || {}),
|
|
161
|
+
"typescript": "^5.0.0",
|
|
162
|
+
"@types/node": "^20.0.0",
|
|
163
|
+
"tsx": "^4.0.0"
|
|
164
|
+
};
|
|
165
|
+
pkg.scripts = {
|
|
166
|
+
...(pkg.scripts || {}),
|
|
167
|
+
"dev": "tsx watch server.js",
|
|
168
|
+
"build": "tsc",
|
|
169
|
+
"start": "node server.js"
|
|
170
|
+
};
|
|
171
|
+
}
|
|
146
172
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
147
173
|
}
|
|
148
174
|
|
|
175
|
+
// 3.5 Handle TypeScript File Renaming and tsconfig
|
|
176
|
+
if (answers.language === 'ts') {
|
|
177
|
+
console.log(` TypeScript-ifying your project...`);
|
|
178
|
+
|
|
179
|
+
// Generate tsconfig.json
|
|
180
|
+
const tsconfig = {
|
|
181
|
+
compilerOptions: {
|
|
182
|
+
target: "ESNext",
|
|
183
|
+
module: "CommonJS",
|
|
184
|
+
moduleResolution: "node",
|
|
185
|
+
esModuleInterop: true,
|
|
186
|
+
forceConsistentCasingInFileNames: true,
|
|
187
|
+
strict: true,
|
|
188
|
+
skipLibCheck: true,
|
|
189
|
+
outDir: "./dist"
|
|
190
|
+
},
|
|
191
|
+
include: ["api/**/*", "services/**/*", "server.js", "zerra.config.json"]
|
|
192
|
+
};
|
|
193
|
+
await fs.writeJson(path.join(targetPath, "tsconfig.json"), tsconfig, { spaces: 2 });
|
|
194
|
+
|
|
195
|
+
// Recursive function to rename .js to .ts
|
|
196
|
+
const renameJsToTs = async (dir) => {
|
|
197
|
+
const files = await fs.readdir(dir);
|
|
198
|
+
for (const file of files) {
|
|
199
|
+
const fullPath = path.join(dir, file);
|
|
200
|
+
const stat = await fs.stat(fullPath);
|
|
201
|
+
if (stat.isDirectory()) {
|
|
202
|
+
await renameJsToTs(fullPath);
|
|
203
|
+
} else if (file.endsWith(".js") && !file.startsWith("server.js")) {
|
|
204
|
+
const newPath = fullPath.replace(/\.js$/, ".ts");
|
|
205
|
+
await fs.move(fullPath, newPath);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
if (fs.existsSync(path.join(targetPath, "api"))) {
|
|
211
|
+
await renameJsToTs(path.join(targetPath, "api"));
|
|
212
|
+
}
|
|
213
|
+
if (fs.existsSync(path.join(targetPath, "services"))) {
|
|
214
|
+
await renameJsToTs(path.join(targetPath, "services"));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
149
218
|
// 4. Generate zerra.config.json based on feature selection
|
|
150
219
|
const featureConfig = {
|
|
151
220
|
logging: answers.features.includes('logging'),
|
|
@@ -161,6 +230,19 @@ program
|
|
|
161
230
|
const configJsonPath = path.join(targetPath, 'zerra.config.json');
|
|
162
231
|
await fs.writeJson(configJsonPath, { features: featureConfig, plugins: [] }, { spaces: 2 });
|
|
163
232
|
|
|
233
|
+
// 4.5 Generate .gitignore for the new project
|
|
234
|
+
const gitignoreContent = `node_modules/
|
|
235
|
+
dist/
|
|
236
|
+
build/
|
|
237
|
+
.env
|
|
238
|
+
.env.local
|
|
239
|
+
.env.*.local
|
|
240
|
+
*.log
|
|
241
|
+
.DS_Store
|
|
242
|
+
${answers.language === 'ts' ? '*.tsbuildinfo' : ''}
|
|
243
|
+
`;
|
|
244
|
+
await fs.writeFile(path.join(targetPath, '.gitignore'), gitignoreContent);
|
|
245
|
+
|
|
164
246
|
const { execSync } = require("child_process");
|
|
165
247
|
|
|
166
248
|
if (answers.installDeps) {
|
package/package.json
CHANGED