@bruxx/cli-tool
Version:
`BRX TEMPLATE` is a production-ready boilerplate for modern React projects. It eliminates the tedious setup process, letting you jump straight into coding with a preconfigured, optimized environment. Built with best practices, it’s designed for scalabilit
60 lines (47 loc) • 1.76 kB
JavaScript
import { spawnSync } from "child_process";
import fs, { rmSync } from "fs";
import path from "path";
import pc from "picocolors";
import { REPO_INFO } from "../repo";
export async function cloneRepository(projectName, cloneOption) {
const repoUrl = REPO_INFO.source[cloneOption];
if (!repoUrl) {
throw new Error(`Invalid clone option: ${cloneOption}`);
}
const result = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: ["inherit", "inherit", "inherit"],
});
const { status: exitCode } = result;
if (exitCode !== 0) {
throw new Error("Failed to clone repository.");
}
console.log(pc.green(`Repository cloned successfully into ${projectName}`));
}
export async function initializeGitRepository(projectName) {
const { status: exitCode } = spawnSync("git", ["init"], {
cwd: projectName,
stdio: ["inherit", "inherit", "inherit"],
});
if (exitCode !== 0) {
throw new Error("Failed to initialize Git repository.");
}
console.log(pc.green("Git repository initialized successfully."));
}
export async function removeGitFolder(projectName) {
const gitFolderPath = path.join(projectName, ".git");
try {
if (!fs.existsSync(gitFolderPath)) {
console.log(pc.yellow(".git folder does not exist. Skipping removal."));
return;
}
rmSync(gitFolderPath, { recursive: true, force: true });
console.log(pc.green(".git folder removed successfully."));
} catch (error) {
if (error instanceof Error) {
console.error(pc.red(`Error removing .git folder: ${error.message}`));
} else {
console.error(pc.red("Error removing .git folder."));
}
throw new Error("Failed to remove .git folder.");
}
}