mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 01:57:29 +00:00
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const exec = require("child_process").exec;
|
|
const shellescape = require("shell-escape");
|
|
|
|
const testFolder = path.join(
|
|
__dirname,
|
|
"../../webamp/experiments/automatedScreenshots/screenshots/"
|
|
);
|
|
const files = fs
|
|
.readdirSync(testFolder)
|
|
.filter(skinPath => skinPath.endsWith(".png"));
|
|
|
|
const genAverage = img => {
|
|
return new Promise((resolve, reject) => {
|
|
const imgPath = shellescape([path.join(testFolder, img)]);
|
|
const command = `convert ${imgPath} -scale 1x1\! -format '%[pixel:u]' info:-`;
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error !== null) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
resolve(stdout);
|
|
});
|
|
});
|
|
};
|
|
|
|
const getFileData = async files => {
|
|
const fileData = {};
|
|
for (let i = 0; i < files.length; i++) {
|
|
const file = files[i];
|
|
const md5 = path.basename(file, ".png");
|
|
// Intentional blocking async loop so we don't use too many child
|
|
// Processes
|
|
fileData[md5] = {
|
|
color: (await genAverage(file)).slice(1)
|
|
};
|
|
}
|
|
return fileData;
|
|
};
|
|
|
|
getFileData(files).then(data => {
|
|
const json = JSON.stringify(data);
|
|
fs.writeFileSync("src/skins.json", json, "utf8");
|
|
});
|