Skip to content

Commit

Permalink
nnnnnnnnnnn
Browse files Browse the repository at this point in the history
Signed-off-by: ClaytonTDM <claytontdm@gmail.com>
  • Loading branch information
ClaytonTDM committed Oct 9, 2024
1 parent 5e65b1b commit f12ae24
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions .github/workflows/gif-to-webp-converter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const { execFile } = require("child_process");
const util = require("util");
const execFilePromise = util.promisify(execFile);
const fs = require("fs").promises;
const path = require("path");
const fs = require("fs").promises;

const gifsiclePath = "gifsicle";
const gifskiPath = "gifski";
const convertPath = "convert";

const textFileExtensions = [
".md",
".json",
".js",
".css",
".html",
".htm",
".htm",
".txt",
".asp",
];

async function isAnimatedGif(filePath) {
try {
const { stdout } = await execFilePromise(gifsiclePath, ["--info", filePath]);
Expand Down Expand Up @@ -84,6 +96,51 @@ async function convertGifToWebp(inputPath, outputPath) {
}
}

async function processDirectory(directoryPath, allConvertedFiles = []) {
try {
const entries = await fs.readdir(directoryPath, {
withFileTypes: true,
});
const convertedFiles = [];

for (const entry of entries) {
const fullPath = path.join(directoryPath, entry.name);

if (entry.isDirectory()) {
await processDirectory(fullPath, allConvertedFiles);
} else if (entry.isFile()) {
if (path.extname(entry.name).toLowerCase() === ".gif") {
const outputPath = path.join(
path.dirname(fullPath),
`${path.basename(fullPath, ".gif")}.webp`
);
const success = await convertGifToWebp(
fullPath,
outputPath
);
if (success) {
convertedFiles.push({
oldName: entry.name,
newName: path.basename(outputPath),
});
}
} else {
await replaceInFile(fullPath, allConvertedFiles);
}
}
}

allConvertedFiles.push(...convertedFiles);

return allConvertedFiles;
} catch (error) {
console.error(
`Error processing directory ${directoryPath}: ${error.message}`
);
return allConvertedFiles;
}
}

async function main() {
const rootDirectory = ".";
console.log(`Starting conversion process in ${rootDirectory}`);
Expand All @@ -92,4 +149,4 @@ async function main() {
console.log(`Total files converted: ${convertedFiles.length}`);
}

main().catch((error) => console.error("An error occurred:", error));
main().catch((error) => console.error("An error occurred:", error));

0 comments on commit f12ae24

Please sign in to comment.