Skip to content

Commit 43b4f25

Browse files
authored
Merge pull request #24 from dlabaj/deploy-update
fix: Updated to tell user github pages site location.
2 parents 9d0da4e + 95ca56f commit 43b4f25

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/__tests__/gh-pages.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { execa } from 'execa';
2929
import ghPages from 'gh-pages';
3030
import {
3131
getGitHubPagesPublicPath,
32+
getGitHubPagesSiteUrl,
3233
normalizeDeployBasePath,
3334
runDeployToGitHubPages,
3435
} from '../gh-pages.js';
@@ -75,6 +76,16 @@ describe('runDeployToGitHubPages', () => {
7576
expect(getGitHubPagesPublicPath('octocat', 'Hello-World')).toBe('/Hello-World/');
7677
});
7778

79+
it('builds HTTPS site URL for project pages', () => {
80+
expect(getGitHubPagesSiteUrl('octocat', 'Hello-World')).toBe(
81+
'https://octocat.github.io/Hello-World/'
82+
);
83+
});
84+
85+
it('builds HTTPS site URL for user/org pages repo', () => {
86+
expect(getGitHubPagesSiteUrl('octocat', 'octocat.github.io')).toBe('https://octocat.github.io/');
87+
});
88+
7889
it('normalizes base path overrides', () => {
7990
expect(normalizeDeployBasePath('/')).toBe('/');
8091
expect(normalizeDeployBasePath('my-app')).toBe('/my-app/');
@@ -159,6 +170,9 @@ describe('runDeployToGitHubPages', () => {
159170
expect(consoleLogSpy).toHaveBeenCalledWith(
160171
expect.stringContaining('Deployed to GitHub Pages')
161172
);
173+
expect(consoleLogSpy).toHaveBeenCalledWith(
174+
expect.stringContaining('https://user.github.io/repo/')
175+
);
162176
});
163177

164178
it('uses yarn when yarn.lock exists', async () => {

src/gh-pages.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ export function getGitHubPagesPublicPath(owner: string, repo: string): string {
5454
return `/${repoSegment}/`;
5555
}
5656

57+
/**
58+
* Public HTTPS URL for the site on GitHub Pages (user/org pages vs project pages).
59+
*/
60+
export function getGitHubPagesSiteUrl(owner: string, repo: string): string {
61+
const repoSegment = repo.replace(/\.git$/i, '');
62+
const repoLower = repoSegment.toLowerCase();
63+
const ownerLower = owner.toLowerCase();
64+
const host = `${ownerLower}.github.io`;
65+
if (repoLower === `${ownerLower}.github.io`) {
66+
return `https://${host}/`;
67+
}
68+
return `https://${host}/${repoSegment}/`;
69+
}
70+
5771
/**
5872
* Normalize CLI/base override: "/" or "" → root; otherwise ensure leading and trailing "/".
5973
*/
@@ -263,6 +277,11 @@ export async function runDeployToGitHubPages(
263277
);
264278
});
265279
console.log('\n✅ Deployed to GitHub Pages.');
280+
if (parsed) {
281+
const siteUrl = getGitHubPagesSiteUrl(parsed.owner, parsed.repo);
282+
console.log(`🌐 Your site: ${siteUrl}`);
283+
console.log(' (URL may take a minute to update after the first deploy.)\n');
284+
}
266285
console.log(' Enable GitHub Pages in your repo: Settings → Pages → Source: branch "' + branch + '".');
267286
if (publicPath !== '/') {
268287
const basename = publicPath.replace(/\/$/, '');

0 commit comments

Comments
 (0)