Add Prettier Formatting (#258)

* Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs

* Remove trailing-comma as we are using Node 6 on Circle

* Use latest Node 6 LTS version in Circle

* Remove unused test
This commit is contained in:
Héctor Ramos 2017-12-04 19:21:02 -08:00 committed by Joel Marcey
parent 0cead4b6f9
commit 65421db62e
50 changed files with 1376 additions and 1350 deletions

View file

@ -7,17 +7,17 @@
* LICENSE file in the root directory of this source tree.
*/
const shell = require("shelljs");
const shell = require('shelljs');
if (!shell.which("git")) {
shell.echo("Sorry, this script requires git");
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
const siteConfig = require(process.cwd() + "/siteConfig.js");
const siteConfig = require(process.cwd() + '/siteConfig.js');
const GIT_USER = process.env.GIT_USER;
const CURRENT_BRANCH =
process.env.CIRCLE_BRANCH || shell.exec("git rev-parse --abbrev-ref HEAD");
process.env.CIRCLE_BRANCH || shell.exec('git rev-parse --abbrev-ref HEAD');
const ORGANIZATION_NAME =
siteConfig.organizationName ||
process.env.ORGANIZATION_NAME ||
@ -30,7 +30,8 @@ const IS_PULL_REQUEST =
process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST;
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 DEPLOYMENT_BRANCH =
PROJECT_NAME.indexOf('.github.io') !== -1 ? 'master' : 'gh-pages';
if (!ORGANIZATION_NAME) {
shell.echo(
@ -47,14 +48,16 @@ if (!PROJECT_NAME) {
}
let remoteBranch;
if (USE_SSH === "true") {
if (USE_SSH === 'true') {
remoteBranch = `git@github.com:${ORGANIZATION_NAME}/${PROJECT_NAME}.git`;
} else {
remoteBranch = `https://${GIT_USER}@github.com/${ORGANIZATION_NAME}/${PROJECT_NAME}.git`;
remoteBranch = `https://${GIT_USER}@github.com/${ORGANIZATION_NAME}/${
PROJECT_NAME
}.git`;
}
if (IS_PULL_REQUEST) {
shell.echo("Skipping deploy on a pull request");
shell.echo('Skipping deploy on a pull request');
shell.exit(0);
}
@ -66,18 +69,18 @@ if (CURRENT_BRANCH === DEPLOYMENT_BRANCH) {
}
if (shell.exec(`node ${__dirname}/build-files.js`).code) {
shell.echo("Error: generating html failed");
shell.echo('Error: generating html failed');
shell.exit(1);
}
shell.cd(process.cwd());
shell.cd("build");
shell.cd('build');
if (
shell.exec(`git clone ${remoteBranch} ${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`)
.code !== 0
) {
shell.echo("Error: git clone failed");
shell.echo('Error: git clone failed');
shell.exit(1);
}
@ -91,7 +94,8 @@ if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
} else {
if (
shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`).code !==
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)
.code !==
0
) {
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
@ -99,30 +103,34 @@ if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
}
}
shell.exec("git rm -rf .");
shell.exec('git rm -rf .');
shell.cd("../..");
shell.cd('../..');
shell.cp(
"-R",
'-R',
`build/${PROJECT_NAME}/*`,
`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}/`
);
shell.cd(`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
const currentCommit = shell.exec("git rev-parse HEAD").stdout.trim();
const currentCommit = shell.exec('git rev-parse HEAD').stdout.trim();
shell.exec("git add --all");
shell.exec('git add --all');
shell.exec(
`git commit -m "Deploy website" -m "Deploy website version based on ${currentCommit}"`
`git commit -m "Deploy website" -m "Deploy website version based on ${
currentCommit
}"`
);
if (shell.exec(`git push origin ${DEPLOYMENT_BRANCH}`).code !== 0) {
shell.echo("Error: Git push failed");
shell.echo('Error: Git push failed');
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_NAME
}/`
);
shell.exit(0);
}