UNPKG

@tmraaex/create-structure

Version:

CLI-verktyg för att skapa en standardiserad projektstruktur med TypeScript

80 lines (67 loc) 2.64 kB
#!/usr/bin/env node import { select, input } from "@inquirer/prompts"; import path from "path"; import { createDirs } from "./src/createDirs.js"; import { createExpressStructure } from "./src/templates/expressTemplate.js"; import { createGitignore } from "./src/createGitignore.js"; import { createReactStructure } from "./src/templates/reactTemplate.js"; const run = async () => { try { // Get project name and template choice from the user const projectName = await input({ message: "Vad vill du att projektet ska heta?", default: "my-project", }); const answers = await getUserInput(); // Define the root directory for the project const root = path.join(process.cwd(), projectName); // This is where the project will be created directly // Create the root directory createDirs(root); // Create the project directory at root createGitignore(root); // Create project structure based on chosen template await createProjectStructure(root, answers, projectName); console.log(`🚀 Projektet "${projectName}" skapades framgångsrikt!`); } catch (error) { console.error("❌ Något gick fel: ", error.message); } }; // Function to get user input for project name and template const getUserInput = async () => { const answers = { template: await select({ message: "Vilken typ av projekt vill du skapa?", choices: [ { name: "Express", value: "Express" }, { name: "React (vite)", value: "React (vite)" }, ], }), }; // If the selected template is "Express", ask about database choice if (answers.template === "Express") { answers.database = await select({ message: "Vilken databas vill du använda?", choices: [ { name: "MongoDB", value: "mongodb" }, { name: "MySQL (ORM)", value: "mysql (orm)" }, { name: "MySQL (raw)", value: "mysql (raw)" }, { name: "Custom (no database)", value: "custom" }, ], }); } return answers; }; // Function to create project structure based on the template const createProjectStructure = async (root, answers, projectName) => { switch (answers.template) { case "Express": createExpressStructure(root, answers.database); break; case "React (vite)": // Correctly handle creating the React (vite) project in the correct folder createReactStructure(root, projectName); // We pass root here and handle the project name break; default: console.log("⚠️ Okänd mall, inget skapas."); } }; run();