Adding a New Converter
ConvertX is designed to be easily extensible. All converter logic resides in src/converters/.
Converter Module Structure
To add a new tool (e.g., mytool), create a file src/converters/mytool.ts. It must export two things:
properties: An object defining compatible input/output formats.convert: An async function that executes the command.
Example Implementation
import { execFile as execFileOriginal } from "node:child_process";
import { ExecFileFn } from "./types";
// 1. Define supported formats
export const properties = {
from: {
category_name: ["input_ext1", "input_ext2"],
},
to: {
category_name: ["output_ext1", "output_ext2"],
},
};
// 2. Define the conversion function
export function convert(
filePath: string,
fileType: string,
convertTo: string,
targetPath: string,
options?: unknown,
execFile: ExecFileFn = execFileOriginal, // Allow injection for testing
): Promise<string> {
return new Promise((resolve, reject) => {
// construct your command arguments
const args = ["-i", filePath, "-o", targetPath];
execFile("my-cli-tool", args, (error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
return;
}
// Log output if necessary
if (stdout) console.log(stdout);
resolve("Done");
});
});
}
Registering the Converter
Once the file is created, you must register it in src/converters/main.ts:
-
Import your module:
import { convert as convertMyTool, properties as propertiesMyTool } from "./mytool"; -
Add it to the
propertiesobject:const properties = { // ... existing converters mytool: { properties: propertiesMyTool, converter: convertMyTool, }, };
System Dependencies
If your converter requires a system binary (e.g., my-cli-tool), you must add it to the Dockerfile. Look for the apt-get install section in the release stage and add your package there.