diff --git a/Dockerfile b/Dockerfile index 2f741da..7cdee5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,7 @@ FROM base AS release RUN apt-get update && apt-get install -y \ assimp-utils \ calibre \ + dasel \ dcraw \ dvisvgm \ ffmpeg \ diff --git a/README.md b/README.md index 57125ac..cb31feb 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ A self-hosted online file converter. Supports over a thousand different formats. | [FFmpeg](https://ffmpeg.org/) | Video | ~472 | ~199 | | [Potrace](https://potrace.sourceforge.net/) | Raster to vector | 4 | 11 | | [VTracer](https://github.com/visioncortex/vtracer) | Raster to vector | 8 | 1 | +| [Dasel](https://github.com/TomWright/dasel) | Data Files | 5 | 4 | diff --git a/src/converters/dasel.ts b/src/converters/dasel.ts new file mode 100644 index 0000000..741d325 --- /dev/null +++ b/src/converters/dasel.ts @@ -0,0 +1,48 @@ +import fs from "fs"; +import { execFile as execFileOriginal } from "node:child_process"; +import { ExecFileFn } from "./types"; + +export const properties = { + from: { + document: ["yaml", "toml", "json", "xml", "csv"], + }, + to: { + document: ["yaml", "toml", "json", "csv"], + }, +}; + +export async function convert( + filePath: string, + fileType: string, + convertTo: string, + targetPath: string, + options?: unknown, + execFile: ExecFileFn = execFileOriginal, // to make it mockable +): Promise { + const args: string[] = []; + + args.push("--file", filePath); + args.push("--read", fileType); + args.push("--write", convertTo); + + return new Promise((resolve, reject) => { + execFile("dasel", args, (error, stdout, stderr) => { + if (error) { + reject(`error: ${error}`); + return; + } + + if (stderr) { + console.error(`stderr: ${stderr}`); + } + + fs.writeFile(targetPath, stdout, (err: NodeJS.ErrnoException | null) => { + if (err) { + reject(`Failed to write output: ${err}`); + } else { + resolve("Done"); + } + }); + }); + }); +} diff --git a/src/converters/main.ts b/src/converters/main.ts index f90a3fc..738574d 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -4,6 +4,7 @@ import { MAX_CONVERT_PROCESS } from "../helpers/env"; import { normalizeFiletype, normalizeOutputFiletype } from "../helpers/normalizeFiletype"; import { convert as convertassimp, properties as propertiesassimp } from "./assimp"; import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre"; +import { convert as convertDasel, properties as propertiesDasel } from "./dasel"; import { convert as convertDvisvgm, properties as propertiesDvisvgm } from "./dvisvgm"; import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg"; import { @@ -82,6 +83,10 @@ const properties: Record< properties: propertiesCalibre, converter: convertCalibre, }, + dasel: { + properties: propertiesDasel, + converter: convertDasel, + }, libreoffice: { properties: propertiesLibreOffice, converter: convertLibreOffice, diff --git a/src/helpers/printVersions.ts b/src/helpers/printVersions.ts index eb1a591..bd94729 100644 --- a/src/helpers/printVersions.ts +++ b/src/helpers/printVersions.ts @@ -84,6 +84,16 @@ if (process.env.NODE_ENV === "production") { } }); + exec("dasel --version", (error, stdout) => { + if (error) { + console.error("dasel is not installed."); + } + + if (stdout) { + console.log(stdout.split("\n")[0]); + } + }); + exec("xelatex -version", (error, stdout) => { if (error) { console.error("Tex Live with XeTeX is not installed.");