Skip to content

Commit a4e20aa

Browse files
authored
Merge pull request #402 from ben-burwood/dasel
2 parents aee9677 + 1cc4862 commit a4e20aa

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ FROM base AS release
4747
RUN apt-get update && apt-get install -y \
4848
assimp-utils \
4949
calibre \
50+
dasel \
5051
dcraw \
5152
dvisvgm \
5253
ffmpeg \

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ A self-hosted online file converter. Supports over a thousand different formats.
4242
| [FFmpeg](https://ffmpeg.org/) | Video | ~472 | ~199 |
4343
| [Potrace](https://potrace.sourceforge.net/) | Raster to vector | 4 | 11 |
4444
| [VTracer](https://github.com/visioncortex/vtracer) | Raster to vector | 8 | 1 |
45+
| [Dasel](https://github.com/TomWright/dasel) | Data Files | 5 | 4 |
4546

4647
<!-- many ffmpeg fileformats are duplicates -->
4748

src/converters/dasel.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import fs from "fs";
2+
import { execFile as execFileOriginal } from "node:child_process";
3+
import { ExecFileFn } from "./types";
4+
5+
export const properties = {
6+
from: {
7+
document: ["yaml", "toml", "json", "xml", "csv"],
8+
},
9+
to: {
10+
document: ["yaml", "toml", "json", "csv"],
11+
},
12+
};
13+
14+
export async function convert(
15+
filePath: string,
16+
fileType: string,
17+
convertTo: string,
18+
targetPath: string,
19+
options?: unknown,
20+
execFile: ExecFileFn = execFileOriginal, // to make it mockable
21+
): Promise<string> {
22+
const args: string[] = [];
23+
24+
args.push("--file", filePath);
25+
args.push("--read", fileType);
26+
args.push("--write", convertTo);
27+
28+
return new Promise((resolve, reject) => {
29+
execFile("dasel", args, (error, stdout, stderr) => {
30+
if (error) {
31+
reject(`error: ${error}`);
32+
return;
33+
}
34+
35+
if (stderr) {
36+
console.error(`stderr: ${stderr}`);
37+
}
38+
39+
fs.writeFile(targetPath, stdout, (err: NodeJS.ErrnoException | null) => {
40+
if (err) {
41+
reject(`Failed to write output: ${err}`);
42+
} else {
43+
resolve("Done");
44+
}
45+
});
46+
});
47+
});
48+
}

src/converters/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MAX_CONVERT_PROCESS } from "../helpers/env";
44
import { normalizeFiletype, normalizeOutputFiletype } from "../helpers/normalizeFiletype";
55
import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
66
import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";
7+
import { convert as convertDasel, properties as propertiesDasel } from "./dasel";
78
import { convert as convertDvisvgm, properties as propertiesDvisvgm } from "./dvisvgm";
89
import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
910
import {
@@ -82,6 +83,10 @@ const properties: Record<
8283
properties: propertiesCalibre,
8384
converter: convertCalibre,
8485
},
86+
dasel: {
87+
properties: propertiesDasel,
88+
converter: convertDasel,
89+
},
8590
libreoffice: {
8691
properties: propertiesLibreOffice,
8792
converter: convertLibreOffice,

src/helpers/printVersions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ if (process.env.NODE_ENV === "production") {
8484
}
8585
});
8686

87+
exec("dasel --version", (error, stdout) => {
88+
if (error) {
89+
console.error("dasel is not installed.");
90+
}
91+
92+
if (stdout) {
93+
console.log(stdout.split("\n")[0]);
94+
}
95+
});
96+
8797
exec("xelatex -version", (error, stdout) => {
8898
if (error) {
8999
console.error("Tex Live with XeTeX is not installed.");

0 commit comments

Comments
 (0)