Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
lancejpollard committed Jan 18, 2024
1 parent f3b6baf commit 7b7c968
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
4 changes: 2 additions & 2 deletions code/cli/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 28 additions & 5 deletions code/cli/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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}.`)
}
Expand Down
4 changes: 2 additions & 2 deletions code/shared/type/source/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
},
},
},
Expand All @@ -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' } },
},
},
},
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions test/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7b7c968

Please sign in to comment.