feat: replace exec with execFile
This commit is contained in:
parent
c1b75a13fd
commit
9263d17609
10 changed files with 869 additions and 855 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -119,10 +119,8 @@ export async function convert(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const command = `assimp export "${filePath}" "${targetPath}"`;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
execFile("assimp", ["export", filePath, targetPath], (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -64,10 +64,8 @@ export async function convert(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const command = `ebook-convert "${filePath}" "${targetPath}"`;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
execFile("ebook-convert", [filePath, targetPath], (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
// This could be done dynamically by running `ffmpeg -formats` and parsing the output
|
// This could be done dynamically by running `ffmpeg -formats` and parsing the output
|
||||||
export const properties = {
|
export const properties = {
|
||||||
|
|
@ -691,19 +691,28 @@ export async function convert(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let extra = "";
|
let extraArgs: string[] = [];
|
||||||
let message = "Done";
|
let message = "Done";
|
||||||
|
|
||||||
if (convertTo === "ico") {
|
if (convertTo === "ico") {
|
||||||
// make sure image is 256x256 or smaller
|
// make sure image is 256x256 or smaller
|
||||||
extra = `-filter:v "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease"`;
|
extraArgs = ['-filter:v', "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease"];
|
||||||
message = "Done: resized to 256x256";
|
message = "Done: resized to 256x256";
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = `ffmpeg ${process.env.FFMPEG_ARGS || ""} -i "${filePath}" ${extra} "${targetPath}"`;
|
// Parse FFMPEG_ARGS environment variable into array
|
||||||
|
const ffmpegArgs = process.env.FFMPEG_ARGS ? process.env.FFMPEG_ARGS.split(/\s+/) : [];
|
||||||
|
|
||||||
|
// Build arguments array
|
||||||
|
const args = [
|
||||||
|
...ffmpegArgs,
|
||||||
|
"-i", filePath,
|
||||||
|
...extraArgs,
|
||||||
|
targetPath
|
||||||
|
];
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
execFile("ffmpeg", args, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -317,8 +317,9 @@ export function convert(
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(
|
execFile(
|
||||||
`gm convert "${filePath}" "${targetPath}"`,
|
"gm",
|
||||||
|
["convert", filePath, targetPath],
|
||||||
(error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,8 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
images: [
|
images: ["svg", "pdf", "eps", "ps", "wmf", "emf", "png"],
|
||||||
"svg",
|
|
||||||
"pdf",
|
|
||||||
"eps",
|
|
||||||
"ps",
|
|
||||||
"wmf",
|
|
||||||
"emf",
|
|
||||||
"png"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
images: [
|
images: [
|
||||||
|
|
@ -31,7 +23,7 @@ export const properties = {
|
||||||
"svgz",
|
"svgz",
|
||||||
"tex",
|
"tex",
|
||||||
"wmf",
|
"wmf",
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -44,7 +36,10 @@ export const properties = {
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(`inkscape "${filePath}" -o "${targetPath}"`, (error, stdout, stderr) => {
|
execFile(
|
||||||
|
"inkscape",
|
||||||
|
[filePath, "-o", targetPath],
|
||||||
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +53,7 @@ export const properties = {
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("Done");
|
resolve("Done");
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
// declare possible conversions
|
// declare possible conversions
|
||||||
export const properties = {
|
export const properties = {
|
||||||
|
|
@ -52,7 +52,7 @@ export function convert(
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(`${tool} "${filePath}" "${targetPath}"`, (error, stdout, stderr) => {
|
execFile(tool, [filePath, targetPath], (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -129,14 +129,21 @@ export function convert(
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// set xelatex here
|
// set xelatex here
|
||||||
const xelatex = ["pdf", "latex"];
|
const xelatex = ["pdf", "latex"];
|
||||||
let option = "";
|
|
||||||
|
// Build arguments array
|
||||||
|
const args: string[] = [];
|
||||||
|
|
||||||
if (xelatex.includes(convertTo)) {
|
if (xelatex.includes(convertTo)) {
|
||||||
option = "--pdf-engine=xelatex";
|
args.push("--pdf-engine=xelatex");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args.push(filePath);
|
||||||
|
args.push("-f", fileType);
|
||||||
|
args.push("-t", convertTo);
|
||||||
|
args.push("-o", targetPath);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(
|
execFile("pandoc", args, (error, stdout, stderr) => {
|
||||||
`pandoc ${option} "${filePath}" -f ${fileType} -t ${convertTo} -o "${targetPath}"`,
|
|
||||||
(error, stdout, stderr) => {
|
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +157,6 @@ export function convert(
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("Done");
|
resolve("Done");
|
||||||
},
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -18,7 +18,7 @@ export function convert(
|
||||||
options?: unknown,
|
options?: unknown,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(`resvg "${filePath}" "${targetPath}"`, (error, stdout, stderr) => {
|
execFile("resvg", [filePath, targetPath], (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
|
|
||||||
// declare possible conversions
|
// declare possible conversions
|
||||||
export const properties = {
|
export const properties = {
|
||||||
|
|
@ -120,8 +119,9 @@ export function convert(
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(
|
execFile(
|
||||||
`vips ${action} "${filePath}" "${targetPath}"`,
|
"vips",
|
||||||
|
[action, filePath, targetPath],
|
||||||
(error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { exec } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
from: {
|
from: {
|
||||||
|
|
@ -24,8 +24,15 @@ export function convert(
|
||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
.join("/")
|
.join("/")
|
||||||
.replace("./", "");
|
.replace("./", "");
|
||||||
exec(
|
|
||||||
`latexmk -xelatex -interaction=nonstopmode -output-directory="${outputPath}" "${filePath}"`,
|
execFile(
|
||||||
|
"latexmk",
|
||||||
|
[
|
||||||
|
"-xelatex",
|
||||||
|
"-interaction=nonstopmode",
|
||||||
|
`-output-directory=${outputPath}`,
|
||||||
|
filePath,
|
||||||
|
],
|
||||||
(error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(`error: ${error}`);
|
reject(`error: ${error}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue