UNPKG

create-new-express-app

Version:

A CLI tool to create a TypeScript Express application with best practices

53 lines (52 loc) 2.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createExpressApp = createExpressApp; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const picocolors_1 = __importDefault(require("picocolors")); const package_manager_1 = require("./cli/package-manager"); const git_1 = require("./git"); // Import the tryGitInit function async function createExpressApp(projectDirectory, shouldInstall = true) { const templatePath = path_1.default.resolve(__dirname, "../templates/app-ts"); const targetPath = path_1.default.resolve(process.cwd(), projectDirectory); try { // const writable = await isWriteable(targetPath); // if (!writable) { // console.error(pc.red(`The directory ${targetPath} is not writable.`)); // return; // } fs_extra_1.default.copySync(templatePath, targetPath, { dereference: true }); console.log(picocolors_1.default.green(`Express app created at ${targetPath}`)); process.chdir(targetPath); // Change the current working directory to the target path let packageManager; if (shouldInstall) { // Prompt user for package manager packageManager = await (0, package_manager_1.promptForPackageManager)(); // Install dependencies await (0, package_manager_1.installDependencies)(targetPath, packageManager); console.log(picocolors_1.default.green("Dependencies installed successfully.")); } else { console.log(picocolors_1.default.yellow("Skipping dependency installation. Run your package manager's install command manually.")); packageManager = "npm"; // Default for display purposes } // Initialize Git repository const gitInitialized = (0, git_1.tryGitInit)(targetPath); if (gitInitialized) { console.log(picocolors_1.default.green("Initialized a new Git repository.")); } else { console.log(picocolors_1.default.red("Failed to initialize a Git repository.")); } console.log(picocolors_1.default.green("You can now start your development server by running the following commands:")); console.log(picocolors_1.default.cyan(`cd ${projectDirectory}`)); console.log(picocolors_1.default.cyan(`${packageManager} run dev`)); console.log(picocolors_1.default.green("Happy coding!")); } catch (error) { console.error(picocolors_1.default.red(`Failed to create Express app: ${error.message}`)); } }