From 95ca56fadf80e1a97557b1681afdb74152119d8d Mon Sep 17 00:00:00 2001 From: Donald Labaj Date: Thu, 2 Apr 2026 04:09:16 -0400 Subject: [PATCH] fix: Updated to inform the user where there site is located after a github deploy. --- src/__tests__/gh-pages.test.ts | 14 ++++++++++++++ src/gh-pages.ts | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/__tests__/gh-pages.test.ts b/src/__tests__/gh-pages.test.ts index 7bcd837..276cc26 100644 --- a/src/__tests__/gh-pages.test.ts +++ b/src/__tests__/gh-pages.test.ts @@ -29,6 +29,7 @@ import { execa } from 'execa'; import ghPages from 'gh-pages'; import { getGitHubPagesPublicPath, + getGitHubPagesSiteUrl, normalizeDeployBasePath, runDeployToGitHubPages, } from '../gh-pages.js'; @@ -75,6 +76,16 @@ describe('runDeployToGitHubPages', () => { expect(getGitHubPagesPublicPath('octocat', 'Hello-World')).toBe('/Hello-World/'); }); + it('builds HTTPS site URL for project pages', () => { + expect(getGitHubPagesSiteUrl('octocat', 'Hello-World')).toBe( + 'https://octocat.github.io/Hello-World/' + ); + }); + + it('builds HTTPS site URL for user/org pages repo', () => { + expect(getGitHubPagesSiteUrl('octocat', 'octocat.github.io')).toBe('https://octocat.github.io/'); + }); + it('normalizes base path overrides', () => { expect(normalizeDeployBasePath('/')).toBe('/'); expect(normalizeDeployBasePath('my-app')).toBe('/my-app/'); @@ -159,6 +170,9 @@ describe('runDeployToGitHubPages', () => { expect(consoleLogSpy).toHaveBeenCalledWith( expect.stringContaining('Deployed to GitHub Pages') ); + expect(consoleLogSpy).toHaveBeenCalledWith( + expect.stringContaining('https://user.github.io/repo/') + ); }); it('uses yarn when yarn.lock exists', async () => { diff --git a/src/gh-pages.ts b/src/gh-pages.ts index 58f1ebc..fa93d44 100644 --- a/src/gh-pages.ts +++ b/src/gh-pages.ts @@ -54,6 +54,20 @@ export function getGitHubPagesPublicPath(owner: string, repo: string): string { return `/${repoSegment}/`; } +/** + * Public HTTPS URL for the site on GitHub Pages (user/org pages vs project pages). + */ +export function getGitHubPagesSiteUrl(owner: string, repo: string): string { + const repoSegment = repo.replace(/\.git$/i, ''); + const repoLower = repoSegment.toLowerCase(); + const ownerLower = owner.toLowerCase(); + const host = `${ownerLower}.github.io`; + if (repoLower === `${ownerLower}.github.io`) { + return `https://${host}/`; + } + return `https://${host}/${repoSegment}/`; +} + /** * Normalize CLI/base override: "/" or "" → root; otherwise ensure leading and trailing "/". */ @@ -263,6 +277,11 @@ export async function runDeployToGitHubPages( ); }); console.log('\nāœ… Deployed to GitHub Pages.'); + if (parsed) { + const siteUrl = getGitHubPagesSiteUrl(parsed.owner, parsed.repo); + console.log(`🌐 Your site: ${siteUrl}`); + console.log(' (URL may take a minute to update after the first deploy.)\n'); + } console.log(' Enable GitHub Pages in your repo: Settings → Pages → Source: branch "' + branch + '".'); if (publicPath !== '/') { const basename = publicPath.replace(/\/$/, '');