create-zerra-app 1.0.2 → 1.1.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/index.js CHANGED
@@ -12,7 +12,7 @@ program
12
12
  .action(async (projectName) => {
13
13
  const targetPath = path.join(process.cwd(), projectName);
14
14
 
15
- // 1. Ask for Database Preference
15
+ // 1. Ask for Database Preference and CLI features
16
16
  const answers = await inquirer.prompt([
17
17
  {
18
18
  type: "list",
@@ -26,25 +26,116 @@ program
26
26
  { name: "Firebase", value: "js-firebase" },
27
27
  ],
28
28
  },
29
+ {
30
+ type: "confirm",
31
+ name: "installDeps",
32
+ message: "Would you like to install dependencies automatically?",
33
+ default: true,
34
+ },
35
+ {
36
+ type: "confirm",
37
+ name: "initGit",
38
+ message: "Would you like to initialize a new git repository?",
39
+ default: true,
40
+ },
41
+ {
42
+ type: "checkbox",
43
+ name: "features",
44
+ message: "Which advanced Zerra features would you like to enable?",
45
+ choices: [
46
+ { name: "Beautiful Request Logging", value: "logging", checked: true },
47
+ { name: "Dynamic Routing ([id].js)", value: "dynamicRouting", checked: true },
48
+ { name: "File-Based Middleware (_middleware.js)", value: "middleware", checked: true },
49
+ { name: "Auto-load Environment Variables (.env)", value: "dotenv", checked: true },
50
+ { name: "Automatic Input Validation (Schema)", value: "validation", checked: true },
51
+ { name: "Multipart File Uploads (req.files)", value: "multipart", checked: true }
52
+ ]
53
+ }
29
54
  ]);
30
55
 
31
- const templatePath = path.join(__dirname, "templates", answers.database);
56
+ const baseTemplatePath = path.join(__dirname, "templates", "js-base");
57
+ const dbTemplatePath = path.join(__dirname, "templates", answers.database);
32
58
 
33
59
  console.log(`\nšŸ—ļø Generating Zerra project: ${projectName}...`);
34
60
 
35
61
  try {
36
- if (!fs.existsSync(templatePath)) {
37
- // Fallback to base if specific template isn't ready yet
38
- console.warn(`āš ļø Template ${answers.database} not found, falling back to base.`);
39
- await fs.copy(path.join(__dirname, "templates", "js-base"), targetPath);
40
- } else {
41
- await fs.copy(templatePath, targetPath);
62
+ // 1. Copy the Base Template (Foundation)
63
+ if (fs.existsSync(baseTemplatePath)) {
64
+ await fs.copy(baseTemplatePath, targetPath);
42
65
  }
43
66
 
44
- console.log(`šŸš€ Zerra project created at ${targetPath}`);
67
+ // 2. Overlay Database-Specific Template (if not base)
68
+ if (answers.database !== "js-base" && fs.existsSync(dbTemplatePath)) {
69
+ // We use a custom copy to handle package.json merging
70
+ await fs.copy(dbTemplatePath, targetPath, {
71
+ overwrite: true,
72
+ filter: (src) => !src.endsWith("package.json"), // Handle package.json separately
73
+ });
74
+
75
+ const dbPkgPath = path.join(dbTemplatePath, "package.json");
76
+ const targetPkgPath = path.join(targetPath, "package.json");
77
+
78
+ if (fs.existsSync(dbPkgPath) && fs.existsSync(targetPkgPath)) {
79
+ const basePkg = await fs.readJson(targetPkgPath);
80
+ const dbPkg = await fs.readJson(dbPkgPath);
81
+
82
+ // Merge dependencies and scripts
83
+ basePkg.dependencies = { ...(basePkg.dependencies || {}), ...(dbPkg.dependencies || {}) };
84
+ basePkg.scripts = { ...(basePkg.scripts || {}), ...(dbPkg.scripts || {}) };
85
+
86
+ await fs.writeJson(targetPkgPath, basePkg, { spaces: 2 });
87
+ }
88
+ }
89
+
90
+ // 3. Customize project name in package.json
91
+ const pkgPath = path.join(targetPath, "package.json");
92
+ if (fs.existsSync(pkgPath)) {
93
+ const pkg = await fs.readJson(pkgPath);
94
+ pkg.name = projectName;
95
+ await fs.writeJson(pkgPath, pkg, { spaces: 2 });
96
+ }
97
+
98
+ // 4. Generate zerra.config.json based on feature selection
99
+ const featureConfig = {
100
+ logging: answers.features.includes('logging'),
101
+ dynamicRouting: answers.features.includes('dynamicRouting'),
102
+ middleware: answers.features.includes('middleware'),
103
+ dotenv: answers.features.includes('dotenv'),
104
+ validation: answers.features.includes('validation'),
105
+ multipart: answers.features.includes('multipart')
106
+ };
107
+
108
+ const configJsonPath = path.join(targetPath, 'zerra.config.json');
109
+ await fs.writeJson(configJsonPath, { features: featureConfig }, { spaces: 2 });
110
+
111
+ const { execSync } = require("child_process");
112
+
113
+ if (answers.installDeps) {
114
+ console.log(`\nšŸ“¦ Installing dependencies...`);
115
+ try {
116
+ execSync("npm install", { cwd: targetPath, stdio: "inherit" });
117
+ } catch (installErr) {
118
+ console.warn(`āš ļø Failed to install dependencies automatically. You may need to run 'npm install' manually.`);
119
+ }
120
+ }
121
+
122
+ if (answers.initGit) {
123
+ try {
124
+ execSync("git init", { cwd: targetPath, stdio: "ignore" });
125
+ execSync("git add .", { cwd: targetPath, stdio: "ignore" });
126
+ execSync('git commit -m "Initial commit from create-zerra-app"', { cwd: targetPath, stdio: "ignore" });
127
+ console.log(`🌱 Initialized a git repository.`);
128
+ } catch (gitErr) {
129
+ // Ignore git errors
130
+ }
131
+ }
132
+
133
+ console.log(`\nšŸš€ Zerra project created successfully at ${targetPath}`);
45
134
  console.log(`\nNext steps:`);
46
135
  console.log(` cd ${projectName}`);
47
- console.log(` npm install`);
136
+ if (!answers.installDeps) {
137
+ console.log(` npm install`);
138
+ }
48
139
  console.log(` npm run dev\n`);
49
140
  } catch (err) {
50
141
  console.error("āŒ Error creating project:", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-zerra-app",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,3 +1,10 @@
1
+ const logger = require("../services/logger");
2
+
1
3
  module.exports = (req, res) => {
2
- res.end("Hello from Zerra! šŸš€");
4
+ logger.info("Hello endpoint was hit!");
5
+ res.json({
6
+ message: "Hello from Zerra! šŸš€",
7
+ timestamp: new Date().toISOString(),
8
+ query: req.query
9
+ });
3
10
  };
@@ -5,6 +5,6 @@
5
5
  "dev": "node server.js"
6
6
  },
7
7
  "dependencies": {
8
- "zerra-core": "^1.0.0"
8
+ "zerra-core": "^1.1.0"
9
9
  }
10
10
  }
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ info: (message) => console.log(`[INFO] ${new Date().toISOString()}: ${message}`),
3
+ error: (message) => console.error(`[ERROR] ${new Date().toISOString()}: ${message}`),
4
+ };
@@ -1,3 +1,9 @@
1
- module.exports = (req, res) => {
2
- res.end("Hello from Zerra! šŸš€");
1
+ const firebase = require("../services/firebase");
2
+
3
+ module.exports = async (req, res) => {
4
+ const snapshot = await firebase.firestore().collection("users").get();
5
+ res.json({
6
+ message: "Hello from Zerra! Firebase is ready.",
7
+ userCount: snapshot.docs.length
8
+ });
3
9
  };
@@ -1,10 +1,5 @@
1
1
  {
2
- "name": "zerra-app",
3
- "version": "1.0.0",
4
- "scripts": {
5
- "dev": "node server.js"
6
- },
7
2
  "dependencies": {
8
- "zerra-core": "^1.0.0"
3
+ "firebase-admin": "^11.0.0"
9
4
  }
10
5
  }
@@ -0,0 +1,11 @@
1
+ // This is a stub for your Firebase Admin SDK
2
+ module.exports = {
3
+ firestore: () => ({
4
+ collection: (name) => ({
5
+ get: async () => {
6
+ console.log(`[FIREBASE] Getting collection: ${name}`);
7
+ return { docs: [] };
8
+ }
9
+ })
10
+ })
11
+ };
@@ -1,3 +1,10 @@
1
- module.exports = (req, res) => {
2
- res.end("Hello from Zerra! šŸš€");
1
+ const db = require("../services/db");
2
+
3
+ module.exports = async (req, res) => {
4
+ const users = await db.find("users", {});
5
+ res.json({
6
+ message: "Hello from Zerra! MongoDB is connected.",
7
+ count: users.length,
8
+ users: users
9
+ });
3
10
  };
@@ -1,10 +1,5 @@
1
1
  {
2
- "name": "zerra-app",
3
- "version": "1.0.0",
4
- "scripts": {
5
- "dev": "node server.js"
6
- },
7
2
  "dependencies": {
8
- "zerra-core": "^1.0.0"
3
+ "mongodb": "^6.0.0"
9
4
  }
10
5
  }
@@ -0,0 +1,7 @@
1
+ // This is a stub for your MongoDB connection (e.g., using Mongoose or mongodb driver)
2
+ module.exports = {
3
+ find: async (collection, query) => {
4
+ console.log(`[MONGO] Finding in ${collection}:`, query);
5
+ return []; // Return mock results
6
+ }
7
+ };
@@ -1,3 +1,6 @@
1
- module.exports = (req, res) => {
2
- res.end("Hello from Zerra! šŸš€");
1
+ const db = require("../services/db");
2
+
3
+ module.exports = async (req, res) => {
4
+ const users = await db.query("SELECT * FROM users");
5
+ res.end(`Hello from Zerra! Database is connected. Found ${users.length} users.`);
3
6
  };
@@ -1,10 +1,6 @@
1
1
  {
2
- "name": "zerra-app",
3
- "version": "1.0.0",
4
- "scripts": {
5
- "dev": "node server.js"
6
- },
7
2
  "dependencies": {
8
- "zerra-core": "^1.0.0"
3
+ "pg": "^8.0.0",
4
+ "mysql2": "^3.0.0"
9
5
  }
10
6
  }
@@ -0,0 +1,7 @@
1
+ // This is a stub for your SQL database connection (e.g., using Knex, Sequelize, or pg)
2
+ module.exports = {
3
+ query: async (sql, params) => {
4
+ console.log(`[DB QUERY] Executing: ${sql} with params:`, params);
5
+ return []; // Return mock results
6
+ }
7
+ };
@@ -1,3 +1,10 @@
1
- module.exports = (req, res) => {
2
- res.end("Hello from Zerra! šŸš€");
1
+ const supabase = require("../services/supabase");
2
+
3
+ module.exports = async (req, res) => {
4
+ const { data, error } = await supabase.from("profiles").select("*");
5
+ res.json({
6
+ message: "Hello from Zerra! Supabase is ready.",
7
+ profiles: data,
8
+ error: error
9
+ });
3
10
  };
@@ -1,10 +1,5 @@
1
1
  {
2
- "name": "zerra-app",
3
- "version": "1.0.0",
4
- "scripts": {
5
- "dev": "node server.js"
6
- },
7
2
  "dependencies": {
8
- "zerra-core": "^1.0.0"
3
+ "@supabase/supabase-js": "^2.0.0"
9
4
  }
10
5
  }
@@ -0,0 +1,9 @@
1
+ // This is a stub for your Supabase client
2
+ module.exports = {
3
+ from: (table) => ({
4
+ select: () => {
5
+ console.log(`[SUPABASE] Selecting from ${table}`);
6
+ return { data: [], error: null };
7
+ }
8
+ })
9
+ };
@@ -1 +0,0 @@
1
- console.log("Welcome to your new Zerra application!");
@@ -1,3 +0,0 @@
1
- const { startServer } = require("zerra-core");
2
-
3
- startServer(3000);
@@ -1,3 +0,0 @@
1
- const { startServer } = require("zerra-core");
2
-
3
- startServer(3000);
@@ -1,3 +0,0 @@
1
- const { startServer } = require("zerra-core");
2
-
3
- startServer(3000);
@@ -1,3 +0,0 @@
1
- const { startServer } = require("zerra-core");
2
-
3
- startServer(3000);