Add Dasel Converter
This commit is contained in:
parent
e668b828ea
commit
c3e4f676fc
2 changed files with 64 additions and 0 deletions
59
src/converters/dasel.ts
Normal file
59
src/converters/dasel.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
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<string> {
|
||||||
|
const args: string[] = [];
|
||||||
|
|
||||||
|
args.push("--file", filePath);
|
||||||
|
args.push("--read", fileType);
|
||||||
|
args.push("--write", convertTo);
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import { MAX_CONVERT_PROCESS } from "../helpers/env";
|
||||||
import { normalizeFiletype, normalizeOutputFiletype } from "../helpers/normalizeFiletype";
|
import { normalizeFiletype, normalizeOutputFiletype } from "../helpers/normalizeFiletype";
|
||||||
import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
|
import { convert as convertassimp, properties as propertiesassimp } from "./assimp";
|
||||||
import { convert as convertCalibre, properties as propertiesCalibre } from "./calibre";
|
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 convertDvisvgm, properties as propertiesDvisvgm } from "./dvisvgm";
|
||||||
import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
|
import { convert as convertFFmpeg, properties as propertiesFFmpeg } from "./ffmpeg";
|
||||||
import {
|
import {
|
||||||
|
|
@ -82,6 +83,10 @@ const properties: Record<
|
||||||
properties: propertiesCalibre,
|
properties: propertiesCalibre,
|
||||||
converter: convertCalibre,
|
converter: convertCalibre,
|
||||||
},
|
},
|
||||||
|
dasel: {
|
||||||
|
properties: propertiesDasel,
|
||||||
|
converter: convertDasel,
|
||||||
|
},
|
||||||
libreoffice: {
|
libreoffice: {
|
||||||
properties: propertiesLibreOffice,
|
properties: propertiesLibreOffice,
|
||||||
converter: convertLibreOffice,
|
converter: convertLibreOffice,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue