UNPKG

@equinor/fusion-framework-cli

Version:

[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](./LICENSE)

24 lines 1.07 kB
import { execSync } from 'node:child_process'; /** * Resolves the URL of the Git remote named "origin" for the current repository. * * This function executes a shell command to retrieve the remote URL and converts * SSH-style URLs (e.g., `git@github.com:user/repo.git`) to HTTPS-style URLs * (e.g., `https://github.com/user/repo`). It also removes the `.git` suffix * from the URL if present. * * @returns The resolved Git remote URL as a string, or `undefined` if the command * fails or the remote "origin" is not configured. */ export const resolveGitRemoteUrl = () => { try { const origin = execSync('git remote get-url origin').toString().trim(); return origin.replace('git@github.com:', 'https://github.com/').replace(/\.git$/, ''); } catch (error) { // most likely due to not being in a git repository or no remote named "origin" return undefined; // Return undefined if the command fails or origin is not set } }; export default resolveGitRemoteUrl; //# sourceMappingURL=resolve-git-remote-url.js.map