From adf7959b83256d1b656797fb5157834842318a6f Mon Sep 17 00:00:00 2001 From: myjeong19 Date: Mon, 24 Mar 2025 19:38:23 +0900 Subject: [PATCH 1/3] feat. Improve Notion Bookmark Block Metadata Processing --- package-lock.json | 15 ++++++++ package.json | 3 +- src/lib/download-image.helper.ts | 39 ++++++++------------ src/lib/download-image.ts | 24 ++++++------- src/lib/dump-page.ts | 54 ++++++++++++++++++++++++---- src/lib/index.ts | 62 ++++++++++++++++++-------------- vite.config.ts | 22 ++++++------ 7 files changed, 135 insertions(+), 84 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1030756..1a2d763 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,21 @@ "vitest": "^2.1.1" } }, + "../api-sdk/package": { + "name": "@notionpresso/api-sdk", + "version": "0.0.1", + "extraneous": true, + "license": "ISC", + "dependencies": { + "@notionhq/client": "^2.2.3", + "@types/cheerio": "^0.22.35", + "cheerio": "1.0.0-rc.12" + }, + "devDependencies": { + "cp": "^0.2.0", + "typescript": "^4.9.4" + } + }, "node_modules/@cozy-blog/notion-client": { "version": "0.0.22", "resolved": "https://registry.npmjs.org/@cozy-blog/notion-client/-/notion-client-0.0.22.tgz", diff --git a/package.json b/package.json index 76764b0..2b659a2 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "tsc && vite build", "preview": "vite preview", "test": "vitest", - "prepare": "ts-patch install && typia patch" + "prepare": "ts-patch install && typia patch", + "cli": "node ./dist/notionpresso.es.js" }, "devDependencies": { "@ryoppippi/unplugin-typia": "^1.0.6", diff --git a/src/lib/download-image.helper.ts b/src/lib/download-image.helper.ts index 7720519..2e1a608 100644 --- a/src/lib/download-image.helper.ts +++ b/src/lib/download-image.helper.ts @@ -1,32 +1,24 @@ -import { Block } from "@cozy-blog/notion-client"; -import { ImageBlockObjectResponse } from "@notionhq/client/build/src/api-endpoints"; +import type { Block } from '@notionpresso/api-sdk'; +import type { ImageBlockObjectResponse } from '@notionhq/client/build/src/api-endpoints'; export type ImageBlockObjectResponseExtended = ImageBlockObjectResponse & { blocks: Block[]; }; -export function isImageBlock( - block: Block, -): block is ImageBlockObjectResponseExtended { - return block.type === "image"; +export function isImageBlock(block: Block): block is ImageBlockObjectResponseExtended { + return block.type === 'image'; } function isExternalImage( - image: ImageBlockObjectResponseExtended["image"], -): image is Extract< - ImageBlockObjectResponseExtended["image"], - { type: "external" } -> { - return image.type === "external"; + image: ImageBlockObjectResponseExtended['image'] +): image is Extract { + return image.type === 'external'; } function isFileImage( - image: ImageBlockObjectResponseExtended["image"], -): image is Extract< - ImageBlockObjectResponseExtended["image"], - { type: "file" } -> { - return image.type === "file"; + image: ImageBlockObjectResponseExtended['image'] +): image is Extract { + return image.type === 'file'; } export function getImageUrl(block: ImageBlockObjectResponseExtended): string { @@ -35,18 +27,15 @@ export function getImageUrl(block: ImageBlockObjectResponseExtended): string { } else if (isFileImage(block.image)) { return block.image.file.url; } - throw new Error("Invalid image type"); + throw new Error('Invalid image type'); } -export function updateImageUrl( - block: ImageBlockObjectResponseExtended, - newUrl: string, -): void { +export function updateImageUrl(block: ImageBlockObjectResponseExtended, newUrl: string): void { if (isExternalImage(block.image)) { block.image.external.url = newUrl; } else if (isFileImage(block.image)) { block.image.file.url = newUrl; } else { - throw new Error("Invalid image type"); + throw new Error('Invalid image type'); } -} \ No newline at end of file +} diff --git a/src/lib/download-image.ts b/src/lib/download-image.ts index 08718c1..aba04a7 100644 --- a/src/lib/download-image.ts +++ b/src/lib/download-image.ts @@ -1,12 +1,8 @@ -import * as fs from "fs"; -import * as path from "path"; -import { getFileExtension } from "./file-extension-utils"; -import { Block } from "@cozy-blog/notion-client"; -import { - getImageUrl, - isImageBlock, - updateImageUrl, -} from "./download-image.helper"; +import * as fs from 'fs'; +import * as path from 'path'; +import { getFileExtension } from './file-extension-utils'; +import type { Block } from '@notionpresso/api-sdk'; +import { getImageUrl, isImageBlock, updateImageUrl } from './download-image.helper'; async function downloadImage({ url, @@ -19,7 +15,7 @@ async function downloadImage({ const arrayBuffer = await response.arrayBuffer(); await fs.promises.writeFile(outputPath, Buffer.from(arrayBuffer)); - return response.headers.get("Content-Type") || ""; + return response.headers.get('Content-Type') || ''; } async function updateImageOnBlock( @@ -32,7 +28,7 @@ async function updateImageOnBlock( imageDir: string; pageId: string; }, - imageCounter: { count: number }, + imageCounter: { count: number } ): Promise { if (isImageBlock(block)) { const originalUrl = getImageUrl(block); @@ -82,9 +78,9 @@ export async function updateImageOnBlocks({ pageId: string; imageCounter?: { count: number }; }): Promise { - const updatePromises = blocks.map((block) => - updateImageOnBlock({ block, imageDir, pageId }, imageCounter), + const updatePromises = blocks.map(block => + updateImageOnBlock({ block, imageDir, pageId }, imageCounter) ); await Promise.all(updatePromises); -} \ No newline at end of file +} diff --git a/src/lib/dump-page.ts b/src/lib/dump-page.ts index 2784661..f92ba91 100644 --- a/src/lib/dump-page.ts +++ b/src/lib/dump-page.ts @@ -1,22 +1,64 @@ -import { Client } from "@cozy-blog/notion-client"; -import * as fs from "fs"; -import * as path from "path"; -import { updateImageOnBlocks } from "./download-image"; +import Client, { bookmarkPreprocessors } from '@notionpresso/api-sdk'; +import * as fs from 'fs'; +import * as path from 'path'; +import { updateImageOnBlocks } from './download-image'; + +interface Meta { + meta?: boolean; + fields?: string[]; +} + +function removeOriginalBookmarkProperty(blocks: any[]): any[] { + return blocks.map(block => { + if (block.type === 'notionpresso_bookmark' && block.bookmark) { + const { bookmark, ...rest } = block; + return rest; + } + + if (block.blocks?.length) { + return { + ...block, + blocks: removeOriginalBookmarkProperty(block.blocks), + }; + } + + return block; + }); +} export async function fetchAndSavePageData({ client, pageId, outputDir, imageOutDir, + meta, }: { client: Client; pageId: string; outputDir: string; imageOutDir: string; + meta?: Meta; }): Promise { // Fetch full page data const fullPage = await client.fetchFullPage(pageId); + if (meta?.meta) { + console.log('Fetching bookmark metadata...'); + + try { + fullPage.blocks = await bookmarkPreprocessors.processBlocks(fullPage.blocks, { + meta: meta.meta, + fields: meta.fields, + }); + + fullPage.blocks = removeOriginalBookmarkProperty(fullPage.blocks); + + console.log('Bookmark metadata fetch completed'); + } catch (error) { + console.error('Error transforming bookmarks:', (error as Error).message); + } + } + // Create image directory fs.mkdirSync(imageOutDir, { recursive: true }); @@ -33,8 +75,8 @@ export async function fetchAndSavePageData({ fs.mkdirSync(outputDir, { recursive: true }); // Write the updated data to index.json (overwrite if it exists) - fs.writeFileSync(outputFile, JSON.stringify(fullPage, null, 2), "utf-8"); + fs.writeFileSync(outputFile, JSON.stringify(fullPage, null, 2), 'utf-8'); console.log(`Page data saved to ${outputFile}`); console.log(`Images saved to ${imageOutDir}`); -} \ No newline at end of file +} diff --git a/src/lib/index.ts b/src/lib/index.ts index 6ca1129..547b1da 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,40 +1,44 @@ #!/usr/bin/env node -import { Command } from "commander"; -import { Client } from "@cozy-blog/notion-client"; -import { extractPageIdFromUrl } from "./page-id-extractor"; -import * as path from "path"; -import { fetchAndSavePageData } from "./dump-page"; -import typia from "typia"; +import { Command } from 'commander'; +import Client from '@notionpresso/api-sdk'; +import { extractPageIdFromUrl } from './page-id-extractor'; +import * as path from 'path'; +import { fetchAndSavePageData } from './dump-page'; +import typia from 'typia'; -const DEFAULT_OUTPUT_DIR = "notion-data"; -const DEFAULT_IMAGE_OUT_DIR = "public/notion-data"; +const DEFAULT_OUTPUT_DIR = 'notion-data'; +const DEFAULT_IMAGE_OUT_DIR = 'public/notion-data'; +const DEFAULT_FIELDS = ['title', 'url', 'description', 'favicon', 'image']; interface CLIOptions { page: string; auth: string; dir?: string; imageDir?: string; + meta?: boolean; + fields?: string; } const program = new Command(); program - .requiredOption("--page ", "Notion page URL") - .requiredOption("--auth ", "Notion API authentication token") - .option("--dir ", "Output directory", "notion-data") + .requiredOption('--page ', 'Notion page URL') + .requiredOption('--auth ', 'Notion API authentication token') + .option('--dir ', 'Output directory', 'notion-data') + .option('--image-dir ', 'Output directory for images', 'public/notion-data') .option( - "--image-dir ", - "Output directory for images", - "public/notion-data", - ); + '--meta', + 'Fetch bookmark metadata (includes only title, url, description, favicon, image by default)' + ) + .option('--fields ', 'List of fields to include in bookmark (comma separated, optional)'); program.parse(process.argv); const options = program.opts(); if (!typia.is(options)) { - console.error("Invalid options", options); + console.error('Invalid options', options); process.exit(1); } @@ -42,22 +46,26 @@ const pageId = extractPageIdFromUrl(options.page); const outputDir = path.join(process.cwd(), options.dir || DEFAULT_OUTPUT_DIR); -const imageOutDir = path.join( - process.cwd(), - options.imageDir || DEFAULT_IMAGE_OUT_DIR, - pageId, -); +const imageOutDir = path.join(process.cwd(), options.imageDir || DEFAULT_IMAGE_OUT_DIR, pageId); const client = new Client({ auth: options.auth }); -/** - * fetch and save page data - */ +const meta = { + meta: options.meta, + fields: options.fields ? options.fields.split(',') : options.meta ? DEFAULT_FIELDS : undefined, +}; + (async () => { try { - await fetchAndSavePageData({ client, pageId, outputDir, imageOutDir }); + await fetchAndSavePageData({ + client, + pageId, + outputDir, + imageOutDir, + meta, + }); } catch (error: any) { - console.error("Error fetching page data:", error.message); + console.error('Error fetching page data:', error.message); process.exit(1); } -})(); \ No newline at end of file +})(); diff --git a/vite.config.ts b/vite.config.ts index 9d9ed81..9fc1234 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,29 +1,29 @@ -import { defineConfig } from "vite"; -import { resolve } from "path"; -import UnpluginTypia from "@ryoppippi/unplugin-typia/vite"; +import { defineConfig } from 'vite'; +import { resolve } from 'path'; +import UnpluginTypia from '@ryoppippi/unplugin-typia/vite'; // Library name -const LIB_NAME = "NotionPresso"; +const LIB_NAME = 'NotionPresso'; export default defineConfig({ build: { // Library specific build configuration lib: { // Set the entry point of the library - entry: resolve(__dirname, "src/lib/index.ts"), + entry: resolve(__dirname, 'src/lib/index.ts'), name: LIB_NAME, - fileName: (format) => `${LIB_NAME.toLowerCase()}.${format}.js`, + fileName: format => `${LIB_NAME.toLowerCase()}.${format}.js`, }, rollupOptions: { // Specify external dependencies not to be bundled - external: ["@cozy-blog/notion-client", "commander", "path", "fs"], + external: ['@notionpresso/api-sdk', 'commander', 'path', 'fs'], output: { // Global variable mapping for UMD build globals: { - "@cozy-blog/notion-client": "NotionClient", - commander: "commander", - path: "path", - fs: "fs", + '@notionpresso/api-sdk': 'NotionClient', + commander: 'commander', + path: 'path', + fs: 'fs', }, }, }, From 2d58a09957bda8209cc0cb7b96c8a9abfc877994 Mon Sep 17 00:00:00 2001 From: myjeong19 Date: Mon, 24 Mar 2025 19:55:01 +0900 Subject: [PATCH 2/3] 0.0.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1a2d763..91c8712 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@notionpresso/cli", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@notionpresso/cli", - "version": "0.0.2", + "version": "0.0.3", "dependencies": { "@cozy-blog/notion-client": "^0.0.22", "commander": "^12.1.0", diff --git a/package.json b/package.json index 2b659a2..3c03d2a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@notionpresso/cli", "private": false, - "version": "0.0.2", + "version": "0.0.3", "type": "module", "scripts": { "dev": "vite", From d78330694f4ea575302cd16f91d4e6bd74ea1b89 Mon Sep 17 00:00:00 2001 From: myjeong19 Date: Wed, 26 Mar 2025 19:57:25 +0900 Subject: [PATCH 3/3] refactor. Prettier --- .prettierrc | 6 ++++ src/lib/download-image.helper.ts | 37 +++++++++++++-------- src/lib/download-image.mock.ts | 2 +- src/lib/download-image.ts | 18 +++++++---- src/lib/dump-page.ts | 31 ++++++++++-------- src/lib/file-extension-utils.ts | 8 ++--- src/lib/index.ts | 55 ++++++++++++++++++++------------ src/lib/page-id-extractor.ts | 2 +- 8 files changed, 99 insertions(+), 60 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..5a7704c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": false, + "trailingComma": "es5", + "tabWidth": 2, + "semi": true +} diff --git a/src/lib/download-image.helper.ts b/src/lib/download-image.helper.ts index 2e1a608..9fe51ac 100644 --- a/src/lib/download-image.helper.ts +++ b/src/lib/download-image.helper.ts @@ -1,24 +1,32 @@ -import type { Block } from '@notionpresso/api-sdk'; -import type { ImageBlockObjectResponse } from '@notionhq/client/build/src/api-endpoints'; +import type { Block } from "@notionpresso/api-sdk"; +import type { ImageBlockObjectResponse } from "@notionhq/client/build/src/api-endpoints"; export type ImageBlockObjectResponseExtended = ImageBlockObjectResponse & { blocks: Block[]; }; -export function isImageBlock(block: Block): block is ImageBlockObjectResponseExtended { - return block.type === 'image'; +export function isImageBlock( + block: Block +): block is ImageBlockObjectResponseExtended { + return block.type === "image"; } function isExternalImage( - image: ImageBlockObjectResponseExtended['image'] -): image is Extract { - return image.type === 'external'; + image: ImageBlockObjectResponseExtended["image"] +): image is Extract< + ImageBlockObjectResponseExtended["image"], + { type: "external" } +> { + return image.type === "external"; } function isFileImage( - image: ImageBlockObjectResponseExtended['image'] -): image is Extract { - return image.type === 'file'; + image: ImageBlockObjectResponseExtended["image"] +): image is Extract< + ImageBlockObjectResponseExtended["image"], + { type: "file" } +> { + return image.type === "file"; } export function getImageUrl(block: ImageBlockObjectResponseExtended): string { @@ -27,15 +35,18 @@ export function getImageUrl(block: ImageBlockObjectResponseExtended): string { } else if (isFileImage(block.image)) { return block.image.file.url; } - throw new Error('Invalid image type'); + throw new Error("Invalid image type"); } -export function updateImageUrl(block: ImageBlockObjectResponseExtended, newUrl: string): void { +export function updateImageUrl( + block: ImageBlockObjectResponseExtended, + newUrl: string +): void { if (isExternalImage(block.image)) { block.image.external.url = newUrl; } else if (isFileImage(block.image)) { block.image.file.url = newUrl; } else { - throw new Error('Invalid image type'); + throw new Error("Invalid image type"); } } diff --git a/src/lib/download-image.mock.ts b/src/lib/download-image.mock.ts index e2e1154..7cab83a 100644 --- a/src/lib/download-image.mock.ts +++ b/src/lib/download-image.mock.ts @@ -76,4 +76,4 @@ export const fileImageBlockFactory = */ export const externalImageBlockFactory = fileImageBlockFactory.extend({ image: externalImageFactory.build(), -}); \ No newline at end of file +}); diff --git a/src/lib/download-image.ts b/src/lib/download-image.ts index aba04a7..68cd751 100644 --- a/src/lib/download-image.ts +++ b/src/lib/download-image.ts @@ -1,8 +1,12 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import { getFileExtension } from './file-extension-utils'; -import type { Block } from '@notionpresso/api-sdk'; -import { getImageUrl, isImageBlock, updateImageUrl } from './download-image.helper'; +import * as fs from "fs"; +import * as path from "path"; +import { getFileExtension } from "./file-extension-utils"; +import type { Block } from "@notionpresso/api-sdk"; +import { + getImageUrl, + isImageBlock, + updateImageUrl, +} from "./download-image.helper"; async function downloadImage({ url, @@ -15,7 +19,7 @@ async function downloadImage({ const arrayBuffer = await response.arrayBuffer(); await fs.promises.writeFile(outputPath, Buffer.from(arrayBuffer)); - return response.headers.get('Content-Type') || ''; + return response.headers.get("Content-Type") || ""; } async function updateImageOnBlock( @@ -78,7 +82,7 @@ export async function updateImageOnBlocks({ pageId: string; imageCounter?: { count: number }; }): Promise { - const updatePromises = blocks.map(block => + const updatePromises = blocks.map((block) => updateImageOnBlock({ block, imageDir, pageId }, imageCounter) ); diff --git a/src/lib/dump-page.ts b/src/lib/dump-page.ts index f92ba91..93fdb81 100644 --- a/src/lib/dump-page.ts +++ b/src/lib/dump-page.ts @@ -1,7 +1,7 @@ -import Client, { bookmarkPreprocessors } from '@notionpresso/api-sdk'; -import * as fs from 'fs'; -import * as path from 'path'; -import { updateImageOnBlocks } from './download-image'; +import Client, { bookmarkPreprocessors } from "@notionpresso/api-sdk"; +import * as fs from "fs"; +import * as path from "path"; +import { updateImageOnBlocks } from "./download-image"; interface Meta { meta?: boolean; @@ -9,8 +9,8 @@ interface Meta { } function removeOriginalBookmarkProperty(blocks: any[]): any[] { - return blocks.map(block => { - if (block.type === 'notionpresso_bookmark' && block.bookmark) { + return blocks.map((block) => { + if (block.type === "notionpresso_bookmark" && block.bookmark) { const { bookmark, ...rest } = block; return rest; } @@ -43,19 +43,22 @@ export async function fetchAndSavePageData({ const fullPage = await client.fetchFullPage(pageId); if (meta?.meta) { - console.log('Fetching bookmark metadata...'); + console.log("Fetching bookmark metadata..."); try { - fullPage.blocks = await bookmarkPreprocessors.processBlocks(fullPage.blocks, { - meta: meta.meta, - fields: meta.fields, - }); + fullPage.blocks = await bookmarkPreprocessors.processBlocks( + fullPage.blocks, + { + meta: meta.meta, + fields: meta.fields, + } + ); fullPage.blocks = removeOriginalBookmarkProperty(fullPage.blocks); - console.log('Bookmark metadata fetch completed'); + console.log("Bookmark metadata fetch completed"); } catch (error) { - console.error('Error transforming bookmarks:', (error as Error).message); + console.error("Error transforming bookmarks:", (error as Error).message); } } @@ -75,7 +78,7 @@ export async function fetchAndSavePageData({ fs.mkdirSync(outputDir, { recursive: true }); // Write the updated data to index.json (overwrite if it exists) - fs.writeFileSync(outputFile, JSON.stringify(fullPage, null, 2), 'utf-8'); + fs.writeFileSync(outputFile, JSON.stringify(fullPage, null, 2), "utf-8"); console.log(`Page data saved to ${outputFile}`); console.log(`Images saved to ${imageOutDir}`); diff --git a/src/lib/file-extension-utils.ts b/src/lib/file-extension-utils.ts index f7e2a0f..48a1149 100644 --- a/src/lib/file-extension-utils.ts +++ b/src/lib/file-extension-utils.ts @@ -28,7 +28,7 @@ const mimeTypeToExtensionMap: Record< }; export function getFileExtensionFromContentType( - contentType: string, + contentType: string ): SupportedImageExtension | undefined { return mimeTypeToExtensionMap[contentType as SupportedImageMimeType]; } @@ -42,7 +42,7 @@ export function getFileExtensionFromUrl(url: string): string { export function getFileExtension( contentType: string, - originalUrl: string, + originalUrl: string ): SupportedImageExtension { const extensionFromContentType = getFileExtensionFromContentType(contentType); if (extensionFromContentType) return extensionFromContentType; @@ -51,11 +51,11 @@ export function getFileExtension( if ( extensionFromUrl && Object.values(mimeTypeToExtensionMap).includes( - extensionFromUrl as SupportedImageExtension, + extensionFromUrl as SupportedImageExtension ) ) { return extensionFromUrl as SupportedImageExtension; } return DEFAULT_IMAGE_EXTENSION; -} \ No newline at end of file +} diff --git a/src/lib/index.ts b/src/lib/index.ts index 547b1da..090d037 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,15 +1,15 @@ #!/usr/bin/env node -import { Command } from 'commander'; -import Client from '@notionpresso/api-sdk'; -import { extractPageIdFromUrl } from './page-id-extractor'; -import * as path from 'path'; -import { fetchAndSavePageData } from './dump-page'; -import typia from 'typia'; +import { Command } from "commander"; +import Client from "@notionpresso/api-sdk"; +import { extractPageIdFromUrl } from "./page-id-extractor"; +import * as path from "path"; +import { fetchAndSavePageData } from "./dump-page"; +import typia from "typia"; -const DEFAULT_OUTPUT_DIR = 'notion-data'; -const DEFAULT_IMAGE_OUT_DIR = 'public/notion-data'; -const DEFAULT_FIELDS = ['title', 'url', 'description', 'favicon', 'image']; +const DEFAULT_OUTPUT_DIR = "notion-data"; +const DEFAULT_IMAGE_OUT_DIR = "public/notion-data"; +const DEFAULT_FIELDS = ["title", "url", "description", "favicon", "image"]; interface CLIOptions { page: string; @@ -23,22 +23,29 @@ interface CLIOptions { const program = new Command(); program - .requiredOption('--page ', 'Notion page URL') - .requiredOption('--auth ', 'Notion API authentication token') - .option('--dir ', 'Output directory', 'notion-data') - .option('--image-dir ', 'Output directory for images', 'public/notion-data') + .requiredOption("--page ", "Notion page URL") + .requiredOption("--auth ", "Notion API authentication token") + .option("--dir ", "Output directory", "notion-data") .option( - '--meta', - 'Fetch bookmark metadata (includes only title, url, description, favicon, image by default)' + "--image-dir ", + "Output directory for images", + "public/notion-data" ) - .option('--fields ', 'List of fields to include in bookmark (comma separated, optional)'); + .option( + "--meta", + "Fetch bookmark metadata (includes only title, url, description, favicon, image by default)" + ) + .option( + "--fields ", + "List of fields to include in bookmark (comma separated, optional)" + ); program.parse(process.argv); const options = program.opts(); if (!typia.is(options)) { - console.error('Invalid options', options); + console.error("Invalid options", options); process.exit(1); } @@ -46,13 +53,21 @@ const pageId = extractPageIdFromUrl(options.page); const outputDir = path.join(process.cwd(), options.dir || DEFAULT_OUTPUT_DIR); -const imageOutDir = path.join(process.cwd(), options.imageDir || DEFAULT_IMAGE_OUT_DIR, pageId); +const imageOutDir = path.join( + process.cwd(), + options.imageDir || DEFAULT_IMAGE_OUT_DIR, + pageId +); const client = new Client({ auth: options.auth }); const meta = { meta: options.meta, - fields: options.fields ? options.fields.split(',') : options.meta ? DEFAULT_FIELDS : undefined, + fields: options.fields + ? options.fields.split(",") + : options.meta + ? DEFAULT_FIELDS + : undefined, }; (async () => { @@ -65,7 +80,7 @@ const meta = { meta, }); } catch (error: any) { - console.error('Error fetching page data:', error.message); + console.error("Error fetching page data:", error.message); process.exit(1); } })(); diff --git a/src/lib/page-id-extractor.ts b/src/lib/page-id-extractor.ts index d34f77f..bcd3d33 100644 --- a/src/lib/page-id-extractor.ts +++ b/src/lib/page-id-extractor.ts @@ -28,4 +28,4 @@ export function extractPageIdFromUrl(url: string): string { ].join("-"); return formattedId; -} \ No newline at end of file +}