Skip to content

Commit 8f47cee

Browse files
committed
Split out the command line stuff to own file
1 parent 485848b commit 8f47cee

File tree

3 files changed

+70
-60
lines changed

3 files changed

+70
-60
lines changed

src/index.ts

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,10 @@
11
#!/usr/bin/env node
22

3-
import { Option, program } from "commander";
4-
import { setLogLevel } from "./log";
3+
import { run } from "./run";
54

6-
import { notionPull, DocuNotionOptions } from "./pull";
7-
const pkg = require("../package.json");
8-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
9-
console.log(`docu-notion version ${pkg.version}`);
5+
run();
106

11-
program.name("docu-notion").description("");
12-
program.usage("-n <token> -r <root> [options]");
13-
program
14-
.requiredOption(
15-
"-n, --notion-token <string>",
16-
"notion api token, which looks like secret_3bc1b50XFYb15123RHF243x43450XFY33250XFYa343"
17-
)
18-
.requiredOption(
19-
"-r, --root-page <string>",
20-
"The 31 character ID of the page which is the root of your docs page in notion. The code will look like 9120ec9960244ead80fa2ef4bc1bba25. This page must have a child page named 'Outline'"
21-
)
22-
.option(
23-
"-m, --markdown-output-path <string>",
24-
"Root of the hierarchy for md files. WARNING: node-pull-mdx will delete files from this directory. Note also that if it finds localized images, it will create an i18n/ directory as a sibling.",
25-
"./docs"
26-
)
27-
.option(
28-
"-t, --status-tag <string>",
29-
"Database pages without a Notion page property 'status' matching this will be ignored. Use '*' to ignore status altogether.",
30-
"Publish"
31-
)
32-
.option(
33-
"--locales <codes>",
34-
"Comma-separated list of iso 639-2 codes, the same list as in docusaurus.config.js, minus the primary (i.e. 'en'). This is needed for image localization.",
35-
parseLocales,
36-
[]
37-
)
38-
.addOption(
39-
new Option("-l, --log-level <level>", "Log level").choices([
40-
"info",
41-
"verbose",
42-
"debug",
43-
])
44-
)
45-
.option(
46-
"-i, --img-output-path <string>",
47-
"Path to directory where images will be stored. If this is not included, images will be placed in the same directory as the document that uses them, which then allows for localization of screenshots."
48-
)
49-
.option(
50-
"-p, --img-prefix-in-markdown <string>",
51-
"When referencing an image from markdown, prefix with this path instead of the full img-output-path. Should be used only in conjunction with --img-output-path."
52-
);
7+
// for plugins to import
538

54-
program.showHelpAfterError();
55-
program.parse();
56-
setLogLevel(program.opts().logLevel);
57-
console.log(JSON.stringify(program.opts));
58-
notionPull(program.opts() as DocuNotionOptions).then(() =>
59-
console.log("docu-notion Finished.")
60-
);
61-
62-
function parseLocales(value: string): string[] {
63-
return value.split(",").map(l => l.trim().toLowerCase());
64-
}
9+
export * as Log from "./log";
10+
export * from "./config/configuration";

src/run.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Option, program } from "commander";
2+
import { setLogLevel } from "./log";
3+
4+
import { notionPull, DocuNotionOptions } from "./pull";
5+
6+
export function run() {
7+
const pkg = require("../package.json");
8+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
9+
console.log(`docu-notion version ${pkg.version}`);
10+
11+
program.name("docu-notion").description("");
12+
program.usage("-n <token> -r <root> [options]");
13+
program
14+
.requiredOption(
15+
"-n, --notion-token <string>",
16+
"notion api token, which looks like secret_3bc1b50XFYb15123RHF243x43450XFY33250XFYa343"
17+
)
18+
.requiredOption(
19+
"-r, --root-page <string>",
20+
"The 31 character ID of the page which is the root of your docs page in notion. The code will look like 9120ec9960244ead80fa2ef4bc1bba25. This page must have a child page named 'Outline'"
21+
)
22+
.option(
23+
"-m, --markdown-output-path <string>",
24+
"Root of the hierarchy for md files. WARNING: node-pull-mdx will delete files from this directory. Note also that if it finds localized images, it will create an i18n/ directory as a sibling.",
25+
"./docs"
26+
)
27+
.option(
28+
"-t, --status-tag <string>",
29+
"Database pages without a Notion page property 'status' matching this will be ignored. Use '*' to ignore status altogether.",
30+
"Publish"
31+
)
32+
.option(
33+
"--locales <codes>",
34+
"Comma-separated list of iso 639-2 codes, the same list as in docusaurus.config.js, minus the primary (i.e. 'en'). This is needed for image localization.",
35+
parseLocales,
36+
[]
37+
)
38+
.addOption(
39+
new Option("-l, --log-level <level>", "Log level").choices([
40+
"info",
41+
"verbose",
42+
"debug",
43+
])
44+
)
45+
.option(
46+
"-i, --img-output-path <string>",
47+
"Path to directory where images will be stored. If this is not included, images will be placed in the same directory as the document that uses them, which then allows for localization of screenshots."
48+
)
49+
.option(
50+
"-p, --img-prefix-in-markdown <string>",
51+
"When referencing an image from markdown, prefix with this path instead of the full img-output-path. Should be used only in conjunction with --img-output-path."
52+
);
53+
54+
program.showHelpAfterError();
55+
program.parse();
56+
setLogLevel(program.opts().logLevel);
57+
console.log(JSON.stringify(program.opts));
58+
notionPull(program.opts() as DocuNotionOptions).then(() =>
59+
console.log("docu-notion Finished.")
60+
);
61+
}
62+
function parseLocales(value: string): string[] {
63+
return value.split(",").map(l => l.trim().toLowerCase());
64+
}

src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function doNotionBlockTransforms(
7373
config.plugins.forEach(plugin => {
7474
if (plugin.notionBlockModifications) {
7575
plugin.notionBlockModifications.forEach(transform => {
76-
logDebug("transforming block with plugin: ", plugin.name);
76+
logDebug("transforming block with plugin", plugin.name);
7777
transform.modify(block);
7878
});
7979
}

0 commit comments

Comments
 (0)