UNPKG

toystack

Version:

![Toystack CLI](https://framerusercontent.com/images/6KcXakCf8FI9LB2mJXNjcHIreDA.png)

110 lines (109 loc) 4.19 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentRepositoryAndBranch = getCurrentRepositoryAndBranch; exports.getGitUserName = getGitUserName; exports.getCurrentRepositoryName = getCurrentRepositoryName; exports.buildProject = buildProject; exports.pathExists = pathExists; exports.identifyFramework = identifyFramework; const child_process_1 = require("child_process"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); function getCurrentRepositoryAndBranch() { try { const repositoryName = (0, child_process_1.execSync)("basename `git rev-parse --show-toplevel`") .toString() .trim(); const branchName = (0, child_process_1.execSync)("git rev-parse --abbrev-ref HEAD") .toString() .trim(); return { repositoryName, branchName }; } catch (error) { console.error("Error fetching repository or branch:", error); return null; } } function getGitUserName() { try { return (0, child_process_1.execSync)("git config user.name").toString().trim(); } catch (error) { console.error("Error fetching git user name:", error); return null; } } function getCurrentRepositoryName() { try { const repositoryName = (0, child_process_1.execSync)("basename `git rev-parse --show-toplevel`") .toString() .trim(); return repositoryName; } catch (error) { console.error("Error fetching repository name :", error); return null; } } function buildProject(directory) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { const buildCommand = "npm run build"; (0, child_process_1.exec)(buildCommand, { cwd: directory }, (error, stdout) => { if (error) { console.error("Build failed:", error.message); reject(`Build failed: ${error.message}`); return; } console.log(stdout); resolve(); }); }); }); } function pathExists(targetPath) { try { return fs_1.default.existsSync(targetPath); } catch (error) { console.error(`Error checking path: ${error}`); return false; } } function identifyFramework(projectPath) { try { const packageJsonPath = path_1.default.join(projectPath, "package.json"); if (!fs_1.default.existsSync(packageJsonPath)) { throw new Error("package.json not found in the specified directory."); } const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8")); const dependencies = packageJson.dependencies || {}; const devDependencies = packageJson.devDependencies || {}; // Detect frameworks const isReact = "react" in dependencies || "react" in devDependencies; const isAstro = "astro" in dependencies || "astro" in devDependencies; // Determine framework type if (isAstro) { return "Astro"; } else if (isReact) { return "React"; } } catch (error) { console.error("Error:", error); return false; } }