UNPKG

create-node-blueprint

Version:

A cli tool to generate nodejs project

39 lines (38 loc) 1.69 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { execSync } from "child_process"; import { existsSync } from "fs"; import { join } from "path"; export function initGit(projectPath) { return __awaiter(this, void 0, void 0, function* () { try { // Check if git is installed execSync("git --version", { stdio: "ignore" }); } catch (error) { console.warn("Git is not installed. Skipping git initialization."); return; } const gitConfigPath = join(projectPath, ".git"); // Check if git is already initialized if (existsSync(gitConfigPath)) { console.log("Git repository already exists."); return; } try { // Initialize git repository with hints suppressed execSync("git init --quiet", { cwd: projectPath, stdio: "ignore" }); } catch (error) { console.error("Failed to initialize git repository:", error); throw error; } }); }