wrap converters in promises

This commit is contained in:
C4illin 2024-05-25 18:09:28 +02:00
parent 7a9def556d
commit a41e5d8c99
8 changed files with 70 additions and 57 deletions

View file

@ -126,21 +126,25 @@ export function convert(
targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any,
) {
return exec(
`pandoc "${filePath}" -f ${fileType} -t ${convertTo} -o "${targetPath}"`,
(error, stdout, stderr) => {
if (error) {
return error;
}
): Promise<string> {
return new Promise((resolve, reject) => {
exec(
`pandoc "${filePath}" -f ${fileType} -t ${convertTo} -o "${targetPath}"`,
(error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
},
);
if (stderr) {
console.error(`stderr: ${stderr}`);
}
resolve("success");
},
);
});
}