substr/utils.ts

35 lines
822 B
TypeScript

export async function checkIfFileExists(filePath: string): Promise<boolean> {
try {
await Deno.lstat(filePath);
return true;
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
return false;
} else {
throw error;
}
}
}
export async function createSubtrTmpDirectories(): Promise<void> {
const dirs = [
"/tmp/substr/img/",
];
for (const path of dirs) {
await Deno.mkdir(path, { recursive: true });
}
}
export async function runCommand(cmd: string, args: string[]) {
const command = new Deno.Command(cmd, { args });
const { code, stdout, stderr } = await command.output();
if (code === 1) {
console.log(new TextDecoder().decode(stdout));
console.log(new TextDecoder().decode(stderr));
}
return { success: code === 0, stdout, stderr };
}