const { getSelectedFile } = await kit("file");
const { promises: fs } = await npm("fs");
const path = await npm("path");
const convert = await npm("heic-convert");
const imagePath = await getSelectedFile();
const { dir, name: imageName, ext } = path.parse(imagePath);
const format = await arg(
  "Which format would you like to convert to:",
  async () => {
    let options = ["JPEG", "PNG"];
    return options.map((format) => {
      return {
        name: format,
        value: format,
      };
    });
  }
);
const buffer = await fs.readFile(imagePath);
const outputBuffer = await convert({
  buffer,
  format,
  quality: 1,
});
const updatedFilePath = `${dir}/${imageName}.${format}`;
await fs.writeFile(updatedFilePath, outputBuffer);