From 7b7c9680f4938fb9cb9edd5c9284e01c720360b0 Mon Sep 17 00:00:00 2001 From: Lance Pollard Date: Thu, 18 Jan 2024 11:29:38 -0800 Subject: [PATCH] save --- code/cli/logging.ts | 4 ++-- code/cli/task.ts | 33 ++++++++++++++++++++++++----- code/shared/type/source/document.ts | 4 ++-- readme.md | 1 + test/cli.sh | 16 ++++++++++---- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/code/cli/logging.ts b/code/cli/logging.ts index 48f6532..3094231 100644 --- a/code/cli/logging.ts +++ b/code/cli/logging.ts @@ -33,14 +33,14 @@ export function logSpinner(text: string) { return ora().start(text) } -export function logOutput(text: string, color = true) { +export function logOutput(text: string, color = true, type = 'link') { if (!text) { return } if (color) { logWithSpace( - ` ${tint('link <', B)}${tint(text, G)}${tint('>', B)}`, + ` ${tint(`${type} <`, B)}${tint(text, G)}${tint('>', B)}`, ) } else { log(text) diff --git a/code/cli/task.ts b/code/cli/task.ts index b2d5266..5f358be 100644 --- a/code/cli/task.ts +++ b/code/cli/task.ts @@ -89,8 +89,19 @@ export async function call(task: Task, source) { if (source.help) { return showHelpForConvert(form) } - const input = transferInput(source, buildInputMapping(form)) - return await convertDocumentWithPandoc(input) + let spinner + + try { + spinner = logStart(`Converting document...`, isColor) + const input = transferInput(source, buildInputMapping(form)) + const out = await convertDocumentWithPandoc(input) + spinner?.stop() + logOutput(out, isColor) + return + } catch (e) { + spinner?.stop() + throw e + } } if ( @@ -103,8 +114,20 @@ export async function call(task: Task, source) { if (source.help) { return showHelpForConvert(form) } - const input = transferInput(source, buildInputMapping(form)) - return await convertDocumentWithCalibre(input) + + let spinner + + try { + spinner = logStart(`Converting document...`, isColor) + const input = transferInput(source, buildInputMapping(form)) + const out = await convertDocumentWithCalibre(input) + spinner?.stop() + logOutput(out, isColor) + return + } catch (e) { + spinner?.stop() + throw e + } } if ( @@ -221,7 +244,7 @@ export async function call(task: Task, source) { ) ) { if (await verifyImageWithImageMagick(base)) { - logOutput(`Image is a ${base.input.format}.`) + logOutput(`Image is a ${base.input.format}.`, true, 'note') } else { logOutputError(`Image is not ${base.input.format}.`) } diff --git a/code/shared/type/source/document.ts b/code/shared/type/source/document.ts index 4a42ce5..cddae2e 100644 --- a/code/shared/type/source/document.ts +++ b/code/shared/type/source/document.ts @@ -584,7 +584,7 @@ export const build_command_to_convert_document_with_calibre: Form = { format: { like: 'calibre_input_format', name: { mark: 'I' } }, file: { link: { - path: { like: 'string' }, + path: { like: 'string', name: { mark: 'i' } }, }, }, }, @@ -594,7 +594,7 @@ export const build_command_to_convert_document_with_calibre: Form = { format: { like: 'calibre_output_format', name: { mark: 'O' } }, file: { link: { - path: { like: 'string' }, + path: { like: 'string', name: { mark: 'o' } }, }, }, }, diff --git a/readme.md b/readme.md index 5ed7b57..10867c6 100644 --- a/readme.md +++ b/readme.md @@ -56,6 +56,7 @@ brew install jupyter pip install nbconvert pip install docx2pdf brew install atool +echo 'export PATH=/Applications/calibre.app/Contents/MacOS/:$PATH' >> ~/.profile ``` To use `docx2pdf` you need to have the Microsoft Word app installed on your machine as well. diff --git a/test/cli.sh b/test/cli.sh index 8f0806e..4ff6dc4 100755 --- a/test/cli.sh +++ b/test/cli.sh @@ -4,8 +4,16 @@ mkdir test/hold alias task="pnpm tsx code/cli" -task convert -I png -i test/file/image/fire.png -O jpg -o test/hold/fire.jpg -task verify -I jpg -i test/hold/fire.jpg +# task convert -I png -i test/file/image/fire.png -O jpg -o test/hold/fire.jpg +# task verify -I jpg -i test/hold/fire.jpg -task convert -I cr2 -i test/file/image/trees.cr2 -O jpg -o test/hold/trees.jpg -task verify -I jpg -i test/hold/trees.jpg +# task convert -I cr2 -i test/file/image/trees.cr2 -O jpg -o test/hold/trees.jpg +# task verify -I jpg -i test/hold/trees.jpg + +# # task convert -I rar -i test/file/archive/archive.rar -O zip -o test/hold/archive.rar.zip + +# task convert -I ttf -i test/file/font/etch.ttf -O woff -o test/hold/etch.woff + +# task convert -I epub -i test/file/document/childrens-literature.epub -O mobi -o test/hold/childrens-literature.mobi + +task convert -I docx -i test/file/document/sample.docx -O markdown -o test/hold/sample.docx.markdown