allow copy from /build in github.io case (#260)

* allow copy from /build in github.io case

* Comment explaining the ! in the path.join
This commit is contained in:
Ricky Vetter 2017-12-05 20:59:11 -08:00 committed by Joel Marcey
parent 97612cf20b
commit 8074b96c79

View file

@ -8,6 +8,7 @@
*/
const shell = require('shelljs');
const path = require('path');
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
@ -32,6 +33,8 @@ 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(
@ -68,7 +71,7 @@ if (CURRENT_BRANCH === DEPLOYMENT_BRANCH) {
shell.exit(1);
}
if (shell.exec(`node ${__dirname}/build-files.js`).code) {
if (shell.exec(`node ${path.join(__dirname, "build-files.js")}`).code) {
shell.echo('Error: generating html failed');
shell.exit(1);
}
@ -108,11 +111,15 @@ shell.exec('git rm -rf .');
shell.cd('../..');
shell.cp(
'-R',
`build/${PROJECT_NAME}/*`,
`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}/`
"-R",
// in github.io case, project is deployed to root. need to not recursively
// copy the deployment-branch to be.
// The !(...) represents the same thing as "everything but this"
// Copies everything in /build except the directory after the !.
path.join("build", PROJECT_PATH, `!(${PROJECT_NAME}-${DEPLOYMENT_BRANCH})`),
path.join("build", `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`)
);
shell.cd(`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
shell.cd(path.join("build", `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`));
const currentCommit = shell.exec('git rev-parse HEAD').stdout.trim();
@ -128,9 +135,7 @@ if (shell.exec(`git push origin ${DEPLOYMENT_BRANCH}`).code !== 0) {
shell.exit(1);
} else {
shell.echo(
`Website is live at: https://${ORGANIZATION_NAME}.github.io/${
PROJECT_NAME
}/`
`Website is live at: https://${ORGANIZATION_NAME}.github.io/${PROJECT_PATH}`
);
shell.exit(0);
}