neatnode
Version:
Plug & Play Node.js backend starter templates ā build REST APIs, socket servers, and more in seconds.
75 lines (65 loc) ⢠1.91 kB
JavaScript
import inquirer from "inquirer";
import { createProject } from "./actions/createProject.js";
import templates from "./config/templates.js";
async function main() {
console.log("\nš Welcome to NodeNeat CLI!\n");
// Step 1: Ask for project name
const { projectName } = await inquirer.prompt([
{
name: "projectName",
type: "input",
message: "Enter your project folder name:",
default: "my-app",
validate: (input) => input.trim() !== "" || "Project name cannot be empty."
}
]);
// Step 2: Choose template
const { template } = await inquirer.prompt([
{
name: "template",
type: "list",
message: "Choose a template:",
choices: templates.map((t) => t.name)
}
]);
const chosen = templates.find((t) => t.name === template);
// Step 3: Optional prompt if REST API
let includeCrud = false;
let crudName = "";
if (chosen.name === "Basic Express") {
const answer = await inquirer.prompt([
{
name: "includeCrud",
type: "confirm",
message: "Include example Todo CRUD setup?",
default: true
}
]);
includeCrud = answer.includeCrud;
crudName = "todo";
}
if (chosen.name === "REST API") {
const answer = await inquirer.prompt([
{
name: "includeCrud",
type: "confirm",
message: "Include example User CRUD setup?",
default: true
}
]);
includeCrud = answer.includeCrud;
crudName = "user";
}
// Step 4: Create the project
await createProject({
projectName,
templatePath: chosen.path,
includeCrud,
crudName
});
console.log(`\nā
Project "${projectName}" created successfully using "${chosen.name}" template.\n`);
}
main().catch((err) => {
console.error("ā Error:", err.message);
});