Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display GitHub Pages URL after ng deploy #107

Closed
Closed
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
1 change: 1 addition & 0 deletions src/engine/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const defaults = {
cname: undefined,
dryRun: false,
remote: 'origin',
ghPagesUrl: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably the prop should just be named url? @JohannesHoppe / @fmalcher what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: Thanks for the PR! It's a great start..🤗

Regarding this part:
I don't think this should be an option at all. There is no need to set this via options, it should be only shown in the output. Such a change would also make the overall PR smaller!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your point: There is no need to set this via options.
Anyway, I'll make another patch to apply the feedback.

git: 'git'
};
55 changes: 55 additions & 0 deletions src/engine/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,61 @@ describe('engine', () => {
expect(finalOptions.repo).toMatch(/angular-schule\/angular-cli-ghpages/);
});

it('should discover the github pages url from https repository url', async () => {
const options = {
repo: 'https://github.com/organisation/your-repo.git'
};
const finalOptions = await engine.prepareOptions(options, logger);

expect(finalOptions.ghPagesUrl).toBe(
'https://organisation.github.io/your-repo'
);
});

it('should discover the github pages url from url w/o .git suffix', async () => {
const options = {
repo: 'https://github.com/organisation/your-repo'
};
const finalOptions = await engine.prepareOptions(options, logger);

expect(finalOptions.ghPagesUrl).toBe(
'https://organisation.github.io/your-repo'
);
});

it('should discover the github pages url from url that ends with splash', async () => {
const options = {
repo: 'https://github.com/organisation/your-repo/'
};
const finalOptions = await engine.prepareOptions(options, logger);

expect(finalOptions.ghPagesUrl).toBe(
'https://organisation.github.io/your-repo'
);
});

it('should discover the github pages url from ssh repository url', async () => {
const options = {
repo: '[email protected]:organisation/your-repo.git'
};
const finalOptions = await engine.prepareOptions(options, logger);

expect(finalOptions.ghPagesUrl).toBe(
'https://organisation.github.io/your-repo'
);
});

it('should discover the github pages url from https repository url that contains with `.git`', async () => {
const options = {
repo: 'https://github.com/organisation/x.gity.git'
};
const finalOptions = await engine.prepareOptions(options, logger);

expect(finalOptions.ghPagesUrl).toBe(
'https://organisation.github.io/x.gity'
);
});

/*
// i was not able to somehow catch an error... :-(
it('should should throw an exception, if remote url could not be discovered', async () => {
Expand Down
13 changes: 12 additions & 1 deletion src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function run(
await publishViaGhPages(ghpages, dir, options, logger);

logger.info(
'🚀 Successfully published via angular-cli-ghpages! Have a nice day!'
`🚀 Successfully published ${options.ghPagesUrl} via angular-cli-ghpages! Have a nice day!`
);
}

Expand Down Expand Up @@ -159,6 +159,17 @@ export async function prepareOptions(
}
}

if (options.repo) {
// Not assume custom domain page
let trimEndDotGit = options.repo
.replace(/\/\s*$/, '')
.replace(/\.git\s*$/, '');
const matchEndsWithRepoName = trimEndDotGit.match(/github.com(\/|:)(.*)\/(.*)$/);
if (matchEndsWithRepoName) {
options.ghPagesUrl = `https://${matchEndsWithRepoName[2]}.github.io/${matchEndsWithRepoName[3]}`;
}
}

return options;
}

Expand Down