UNPKG

ts-express-kit

Version:

A TypeScript starter kit for building Express applications with best practices.

48 lines (47 loc) 1.75 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const fs_1 = require("fs"); function runCommand(command) { try { (0, child_process_1.execSync)(command, { stdio: 'inherit' }); return true; } catch (e) { console.error(`Failed to execute ${command}`, e); return false; } } const repoName = process.argv[2]; if (!repoName) { console.error('Please provide a project name: npx ts-express-kit my-backend-app'); process.exit(1); } // GitHub repository URL const GITHUB_REPO_URL = 'https://github.com/nazmulhasannasim333/ts-express-kit'; const gitCheckoutCommand = `git clone --depth 1 ${GITHUB_REPO_URL} ${repoName}`; const installDepsCommand = `cd ${repoName} && npm install`; console.log(`Cloning the repository with name ${repoName}`); const checkedOut = runCommand(gitCheckoutCommand); if (!checkedOut) process.exit(-1); // Remove .git folder so it's not a git repo const gitDir = `${repoName}/.git`; if ((0, fs_1.existsSync)(gitDir)) { (0, fs_1.rmSync)(gitDir, { recursive: true, force: true }); console.log('.git folder removed from cloned project.'); } // Remove bin folder so user project is clean const binDir = `${repoName}/bin`; if ((0, fs_1.existsSync)(binDir)) { (0, fs_1.rmSync)(binDir, { recursive: true, force: true }); console.log('bin folder removed from cloned project.'); } console.log(`Installing dependencies for ${repoName}`); const installedDeps = runCommand(installDepsCommand); if (!installedDeps) process.exit(-1); console.log('Congratulations! You are ready. Follow the next steps:'); console.log(`1. cd ${repoName}`); console.log('2. npm run dev');