Skip to content

Commit

Permalink
Add better verbose logging in gh-pages plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Oct 15, 2020
1 parent 1e26187 commit bb888f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
19 changes: 19 additions & 0 deletions plugins/gh-pages/__tests__/gh-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ describe("Gh-Pages Plugin", () => {
expect(execSpy).toHaveBeenCalledWith("npx", [
"push-dir",
"--cleanup",
false,
"--remote=undefined",
"--dir=test",
"--branch=gh-pages",
'--message="Update docs [skip ci]"',
]);
});

test("should use verbose logs", async () => {
const logger = dummyLog();
logger.logLevel = "verbose";
const hooks = createTest({ dir: "test" }, { logger });
await hooks.afterRelease.promise({
response: { data: { prerelease: false } },
} as any);
expect(execSpy).toHaveBeenCalledWith("npx", [
"push-dir",
"--cleanup",
"--verbose",
"--remote=undefined",
"--dir=test",
"--branch=gh-pages",
Expand Down
13 changes: 9 additions & 4 deletions plugins/gh-pages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@auto-it/core";
import { execSync } from "child_process";
import * as t from "io-ts";
import endent from 'endent';
import endent from "endent";

const required = t.interface({
/** The directory to push to gh-pages */
Expand Down Expand Up @@ -106,9 +106,14 @@ export default class GhPagesPlugin implements IPlugin {
}

try {
const isVerbose =
auto.logger.logLevel === "verbose" ||
auto.logger.logLevel === "veryVerbose";

await execPromise("npx", [
"push-dir",
"--cleanup",
isVerbose && "--verbose",
`--remote=${auto.remote}`,
`--dir=${this.options.dir}`,
`--branch=${this.options.branch}`,
Expand All @@ -119,22 +124,22 @@ export default class GhPagesPlugin implements IPlugin {
"Oh no! It looks like there was trouble publishing to GitHub Pages 😢"
);

if (error.message.includes('git not clean')) {
if (error.message.includes("git not clean")) {
auto.logger.log.error(endent`
Your repo currently has uncommitted files in it.
For the gh-pages plugin to work your git state must be clean.
You can do one of two things to fix this:
1. Add the files to your gitignore (ex: your built gh-pages website dist files)
2. Commit the files (ex: Something you want to track in the repo)
`)
`);

const status = await execPromise("git", ["status", "--porcelain"]);

if (status) {
auto.logger.log.error("Uncomitted Changes:\n", status);
}
}
}

throw error;
}
Expand Down

0 comments on commit bb888f6

Please sign in to comment.