Skip to content

Commit

Permalink
Always use PROJECT_NAME, even for user and org pages (#384)
Browse files Browse the repository at this point in the history
* Always use PROJECT_NAME, even for user and org pages

The symptom was that if we had a user or org page (e.g., https://JoelMarcey.github.io), we would try to copy files to a directory within a directory, getting errors like:

```
Error: Copying build assets failed with error 'Error: Cannot copy '/Users/joelm/dev/JoelMarcey.github.io/website/build' to a subdirectory of itself, '/Users/joelm/dev/JoelMarcey.github.io/website/build/JoelMarcey.github.io-master'.'
```

This is because we were setting the end of `fromPath` to empty if we were using an org or user page.

But we don't need to do that. The `PROJECT_NAME` (set in `siteConfig.js` as `projectName`) is the user or org repo

e.g., https://github.com/JoelMarcey/JoelMarcey.github.io/ has a `projectName` of `JoelMarcey.github.io` with an `organizationName` of `JoelMarcey`.

So now the `fromPath` and `toPath` look like:

`fromPath`: `build/JoelMarcey.github.io`
`toPath`: `buuid/JoelMarcey.github.io-master`
  • Loading branch information
JoelMarcey authored Jan 9, 2018
1 parent 654916a commit c14a8d2
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/publish-gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const USE_SSH = process.env.USE_SSH;
// github.io indicates organization repos that deploy via master. All others use gh-pages.
const DEPLOYMENT_BRANCH =
PROJECT_NAME.indexOf('.github.io') !== -1 ? 'master' : 'gh-pages';
const PROJECT_PATH =
PROJECT_NAME.indexOf('.github.io') !== -1 ? '' : PROJECT_NAME;

if (!ORGANIZATION_NAME) {
shell.echo(
Expand Down Expand Up @@ -109,7 +107,7 @@ shell.exec('git rm -rf .');

shell.cd('../..');

fromPath = path.join('build', PROJECT_PATH, '/');
fromPath = path.join('build', `${PROJECT_NAME}`);
toPath = path.join('build', `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
// In github.io case, project is deployed to root. Need to not recursively
// copy the deployment-branch to be.
Expand Down Expand Up @@ -152,7 +150,7 @@ fs.copy(
} else if (commitResults.code === 0) {
// The commit might return a non-zero value when site is up to date.
shell.echo(
`Website is live at: https://${ORGANIZATION_NAME}.github.io/${PROJECT_PATH}`
`Website is live at: https://${ORGANIZATION_NAME}.github.io/${PROJECT_NAME}`
);
shell.exit(0);
}
Expand Down

0 comments on commit c14a8d2

Please sign in to comment.