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 +101 -10
- package/package.json +1 -1
- package/templates/js-base/api/hello.js +8 -1
- package/templates/js-base/package.json +1 -1
- package/templates/js-base/services/logger.js +4 -0
- package/templates/js-firebase/api/hello.js +8 -2
- package/templates/js-firebase/package.json +1 -6
- package/templates/js-firebase/services/firebase.js +11 -0
- package/templates/js-mongo/api/hello.js +9 -2
- package/templates/js-mongo/package.json +1 -6
- package/templates/js-mongo/services/db.js +7 -0
- package/templates/js-sql/api/hello.js +5 -2
- package/templates/js-sql/package.json +2 -6
- package/templates/js-sql/services/db.js +7 -0
- package/templates/js-supabase/api/hello.js +9 -2
- package/templates/js-supabase/package.json +1 -6
- package/templates/js-supabase/services/supabase.js +9 -0
- package/templates/js-base/index.js +0 -1
- package/templates/js-firebase/server.js +0 -3
- package/templates/js-mongo/server.js +0 -3
- package/templates/js-sql/server.js +0 -3
- package/templates/js-supabase/server.js +0 -3
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
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,3 +1,10 @@
|
|
|
1
|
+
const logger = require("../services/logger");
|
|
2
|
+
|
|
1
3
|
module.exports = (req, res) => {
|
|
2
|
-
|
|
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
|
};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 +0,0 @@
|
|
|
1
|
-
console.log("Welcome to your new Zerra application!");
|