Skip to content

Commit 973b77c

Browse files
committed
feat: Add grouping of messages in Github Actions, and lazy debug logging
1 parent 53d4816 commit 973b77c

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

src/log.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,33 @@ export function warning(s: string): void {
1414
export function info(s: string): void {
1515
console.log(s);
1616
}
17-
export function heading(s: string): void {
18-
console.log(chalk.blue(s));
17+
18+
// make sure to call endGroup(), eventually, after calling this
19+
export function group(s: string): void {
20+
console.log(chalk.blue(wrapForCI(s, "group")));
21+
}
22+
23+
// github actions needs an ::endgroup:: to end a group
24+
export function endGroup(): void {
25+
console.log(wrapForCI("", "endgroup"));
1926
}
27+
2028
export function verbose(s: string): void {
2129
if (logLevel === "verbose" || logLevel === "debug")
2230
console.log(chalk.green(s));
2331
}
32+
33+
// use this one if the debug info would take time to construct,
34+
// so you want to skip doing it if not in debug mode
35+
export function logDebugFn(
36+
label: string,
37+
runIfLoggingDebug: () => string
38+
): void {
39+
if (logLevel === "debug") {
40+
logDebug(label, runIfLoggingDebug());
41+
}
42+
}
43+
2444
export function logDebug(label: string, info: string): void {
2545
if (logLevel === "debug") {
2646
console.log(chalk.dim(wrapForCI(`[${label}]`, "debug")));

src/plugins/HeadingTransformer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NotionToMarkdown } from "notion-to-md";
22
import { NotionBlock } from "../types";
33
import { IPlugin } from "./pluginTypes";
4+
import { logDebug } from "../log";
45

56
// Makes links to headings work in docusaurus
67
// https://github.com/sillsdev/docu-notion/issues/20
@@ -13,6 +14,11 @@ async function headingTransformer(
1314

1415
const markdown = await notionToMarkdown.blockToMarkdown(block);
1516

17+
logDebug(
18+
"headingTransformer, markdown of a heading before adding id",
19+
markdown
20+
);
21+
1622
// To make heading links work in docusaurus, we append an id. E.g.
1723
// ### Hello World {#my-explicit-id}
1824
// See https://docusaurus.io/docs/markdown-features/toc#heading-ids.

src/pull.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ import { NotionPage, PageType } from "./NotionPage";
77
import { initImageHandling, cleanupOldImages } from "./images";
88

99
import * as Path from "path";
10-
import { error, heading, info, logDebug, verbose, warning } from "./log";
10+
import {
11+
endGroup,
12+
error,
13+
group,
14+
info,
15+
logDebug,
16+
verbose,
17+
warning,
18+
} from "./log";
1119
import { IDocuNotionContext } from "./plugins/pluginTypes";
1220
import { getMarkdownForPage } from "./transform";
1321
import {
@@ -70,21 +78,22 @@ export async function notionPull(options: DocuNotionOptions): Promise<void> {
7078

7179
info("Connecting to Notion...");
7280

73-
heading(
81+
group(
7482
"Stage 1: walk children of the page named 'Outline', looking for pages..."
7583
);
7684
await getPagesRecursively(options, "", options.rootPage, 0, true);
7785
logDebug("getPagesRecursively", JSON.stringify(pages, null, 2));
7886
info(`Found ${pages.length} pages`);
79-
info(``);
80-
heading(
87+
endGroup();
88+
group(
8189
`Stage 2: convert ${pages.length} Notion pages to markdown and save locally...`
8290
);
8391
await outputPages(options, config, pages);
84-
info(``);
85-
heading("Stage 3: clean up old files & images...");
92+
endGroup();
93+
group("Stage 3: clean up old files & images...");
8694
await layoutStrategy.cleanupOldFiles();
8795
await cleanupOldImages();
96+
endGroup();
8897
}
8998

9099
async function outputPages(

src/transform.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
IDocuNotionContext,
44
IRegexMarkdownModification,
55
} from "./plugins/pluginTypes";
6-
import { error, info, logDebug, verbose, warning } from "./log";
6+
import { error, info, logDebug, logDebugFn, verbose, warning } from "./log";
77
import { NotionPage } from "./NotionPage";
88
import { IDocuNotionConfig } from "./config/configuration";
99
import { NotionBlock } from "./types";
@@ -27,7 +27,7 @@ export async function getMarkdownForPage(
2727

2828
const blocks = await context.getBlockChildren(page.pageId);
2929

30-
logDebug("pull", JSON.stringify(blocks));
30+
logDebugFn("markdown from page", () => JSON.stringify(blocks, null, 2));
3131

3232
const body = await getMarkdownFromNotionBlocks(context, config, blocks);
3333
const frontmatter = getFrontMatter(page); // todo should be a plugin
@@ -217,6 +217,10 @@ function registerNotionToMarkdownCustomTransforms(
217217
config.plugins.forEach(plugin => {
218218
if (plugin.notionToMarkdownTransforms) {
219219
plugin.notionToMarkdownTransforms.forEach(transform => {
220+
logDebug(
221+
"registering custom transform",
222+
`${plugin.name} for ${transform.type}`
223+
);
220224
docunotionContext.notionToMarkdown.setCustomTransformer(
221225
transform.type,
222226
(block: any) => {

0 commit comments

Comments
 (0)