1"use strict"; 2var __importDefault = (this && this.__importDefault) || function (mod) { 3 return (mod && mod.__esModule) ? mod : { "default": mod }; 4}; 5Object.defineProperty(exports, "__esModule", { value: true }); 6exports.guessRepoUrl = exports.findGitHubProfileUrl = exports.findGitHubEmail = exports.findMyName = exports.newStep = void 0; 7const chalk_1 = __importDefault(require("chalk")); 8const cross_spawn_1 = __importDefault(require("cross-spawn")); 9const github_username_1 = __importDefault(require("github-username")); 10const ora_1 = __importDefault(require("ora")); 11async function newStep(title, action, options = {}) { 12 const disabled = process.env.CI || process.env.EXPO_DEBUG; 13 const step = (0, ora_1.default)({ 14 text: chalk_1.default.bold(title), 15 isEnabled: !disabled, 16 stream: disabled ? process.stdout : process.stderr, 17 ...options, 18 }); 19 step.start(); 20 try { 21 return await action(step); 22 } 23 catch (error) { 24 step.fail(); 25 console.error(error); 26 process.exit(1); 27 } 28} 29exports.newStep = newStep; 30/** 31 * Finds user's name by reading it from the git config. 32 */ 33async function findMyName() { 34 try { 35 return cross_spawn_1.default.sync('git', ['config', '--get', 'user.name']).stdout.toString().trim(); 36 } 37 catch { 38 return ''; 39 } 40} 41exports.findMyName = findMyName; 42/** 43 * Finds user's email by reading it from the git config. 44 */ 45async function findGitHubEmail() { 46 try { 47 return cross_spawn_1.default.sync('git', ['config', '--get', 'user.email']).stdout.toString().trim(); 48 } 49 catch { 50 return ''; 51 } 52} 53exports.findGitHubEmail = findGitHubEmail; 54/** 55 * Get the GitHub username from an email address if the email can be found in any commits on GitHub. 56 */ 57async function findGitHubProfileUrl(email) { 58 try { 59 const username = (await (0, github_username_1.default)(email)) ?? ''; 60 return `https://github.com/${username}`; 61 } 62 catch { 63 return ''; 64 } 65} 66exports.findGitHubProfileUrl = findGitHubProfileUrl; 67/** 68 * Guesses the repository URL based on the author profile URL and the package slug. 69 */ 70async function guessRepoUrl(authorUrl, slug) { 71 if (/^https?:\/\/github.com\/[^/]+/.test(authorUrl)) { 72 const normalizedSlug = slug.replace(/^@/, '').replace(/\//g, '-'); 73 return `${authorUrl}/${normalizedSlug}`; 74 } 75 return ''; 76} 77exports.guessRepoUrl = guessRepoUrl; 78//# sourceMappingURL=utils.js.map