legendaryjs
Version:
LegendaryJS – The ultimate backend framework for speed, power, and simplicity.
76 lines (67 loc) • 2.28 kB
JavaScript
const fs = require('fs');
const path = require('path');
function generate(type = '') {
const lcType = type.toLowerCase();
const routesDir = path.join(process.cwd(), 'routes');
const configPath = path.join(process.cwd(), 'legendary.config.js');
fs.mkdirSync(routesDir, { recursive: true });
const templates = {
portfolio: {
routes: [
{ method: "GET", path: "/profile", response: { name: "Haidar", role: "Engineer" } },
{ method: "GET", path: "/skills", response: { skills: ["Node.js", "MongoDB"] } },
{ method: "POST", path: "/contact", response: { message: "Message received." } }
],
config: {
port: 3000,
routes: ["./routes/api.v1.json"],
dashboard: true,
docs: true
}
},
ecommerce: {
routes: [
{ method: "GET", path: "/products", response: { items: [] } },
{ method: "POST", path: "/cart", response: { message: "Added to cart" } },
{ method: "POST", path: "/checkout", response: { status: "Success" } },
{ method: "GET", path: "/orders", response: { orders: [] } }
],
config: {
port: 4000,
routes: ["./routes/api.v1.json"],
auth: { jwt: true },
db: { mongo: true },
dashboard: true,
docs: true
}
},
crm: {
routes: [
{ method: "GET", path: "/clients", response: { clients: [] } },
{ method: "POST", path: "/deals", response: { success: true } },
{ method: "GET", path: "/notes", response: { notes: [] } }
],
config: {
port: 5000,
routes: ["./routes/api.v1.json"],
auth: { jwt: true },
devtools: true,
dashboard: true,
docs: true
}
}
};
if (!templates[lcType]) {
return console.warn(`❌ Unknown starter kit: ${type}`);
}
fs.writeFileSync(
path.join(routesDir, 'api.v1.json'),
JSON.stringify({ routes: templates[lcType].routes }, null, 2)
);
fs.writeFileSync(
configPath,
'module.exports = ' + JSON.stringify(templates[lcType].config, null, 2)
);
console.log(`✅ LegendaryJS ${type} starter kit generated.`);
}
module.exports = { generate };