Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/__tests__/gh-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { execa } from 'execa';
import ghPages from 'gh-pages';
import {
getGitHubPagesPublicPath,
getGitHubPagesSiteUrl,
normalizeDeployBasePath,
runDeployToGitHubPages,
} from '../gh-pages.js';
Expand Down Expand Up @@ -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/');
Expand Down Expand Up @@ -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 () => {
Expand Down
19 changes: 19 additions & 0 deletions src/gh-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/".
*/
Expand Down Expand Up @@ -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(/\/$/, '');
Expand Down
Loading