diff --git a/experiments/skinArchiveTools/lib/collectSkins.js b/experiments/skinArchiveTools/lib/collectSkins.js index dbf29fe7..67a8cbcd 100644 --- a/experiments/skinArchiveTools/lib/collectSkins.js +++ b/experiments/skinArchiveTools/lib/collectSkins.js @@ -6,6 +6,7 @@ const { memoize } = require("lodash"); const md5File = require("md5-file/promise"); const Filehound = require("filehound"); const Utils = require("./utils"); +const { FILE_TYPES } = require("./constants"); const memoizedMd5File = memoize(md5File); @@ -45,7 +46,7 @@ module.exports = async function collectSkins({ fsPromises.writeFile(filenamesPath, pathList); collectionInfo - .filter(info => info.skinType === "PACK") + .filter(info => info.skinType === FILE_TYPES.PACK) .forEach(pack => { const packPath = path.resolve(`./assets/md5Packs/${pack.md5}`); if (fs.existsSync(packPath)) { @@ -58,7 +59,7 @@ module.exports = async function collectSkins({ } }); collectionInfo - .filter(info => info.skinType === "INVALID") + .filter(info => info.skinType === FILE_TYPES.INVALID) .forEach(async invalid => { const filePath = path.resolve(`./assets/md5Invalids/${invalid.md5}.wsz`); if (fs.existsSync(filePath)) { @@ -72,10 +73,14 @@ module.exports = async function collectSkins({ moved: collectionInfo.filter(info => info.moved).length, newScreenshots: collectionInfo.filter(info => info.screenshotCreated) .length, - classic: collectionInfo.filter(info => info.skinType === "CLASSIC").length, - packs: collectionInfo.filter(info => info.skinType === "PACK").length, - invalid: collectionInfo.filter(info => info.skinType === "INVALID").length, - modern: collectionInfo.filter(info => info.skinType === "MODERN").length, + classic: collectionInfo.filter(info => info.skinType === FILE_TYPES.CLASSIC) + .length, + packs: collectionInfo.filter(info => info.skinType === FILE_TYPES.PACK) + .length, + invalid: collectionInfo.filter(info => info.skinType === FILE_TYPES.INVALID) + .length, + modern: collectionInfo.filter(info => info.skinType === FILE_TYPES.MODERN) + .length, // TODO: Tell modern skins from packs nonClassic: collectionInfo.filter(info => !info.classic).length }; diff --git a/experiments/skinArchiveTools/lib/constants.js b/experiments/skinArchiveTools/lib/constants.js new file mode 100644 index 00000000..d45c2b21 --- /dev/null +++ b/experiments/skinArchiveTools/lib/constants.js @@ -0,0 +1,8 @@ +const FILE_TYPES = { + INVALID: "INVALID", + CLASSIC: "CLASSIC", + MODERN: "MODERN", + PACK: "PACK" +}; + +module.exports = { FILE_TYPES }; diff --git a/experiments/skinArchiveTools/lib/index.js b/experiments/skinArchiveTools/lib/index.js index c67fac41..48c8eba0 100755 --- a/experiments/skinArchiveTools/lib/index.js +++ b/experiments/skinArchiveTools/lib/index.js @@ -23,6 +23,7 @@ const outputDir = path.resolve(rawOutputDir); const screenshotDir = path.resolve(rawScreenshotDir); const filenamesPath = path.resolve(rawFilenamesPath); +// It's nice to be able to fiddle these manually const collect = true; const screenshots = true; diff --git a/experiments/skinArchiveTools/lib/utils.js b/experiments/skinArchiveTools/lib/utils.js index 2e3c604c..46ec543d 100644 --- a/experiments/skinArchiveTools/lib/utils.js +++ b/experiments/skinArchiveTools/lib/utils.js @@ -1,5 +1,6 @@ const JSZip = require("jszip"); const fsPromises = require("fs").promises; +const { FILE_TYPES } = require("./constants"); // Reduce an array down to it's unique value given an async hasher function async function unique(arr, hasher) { @@ -24,11 +25,13 @@ async function skinType(skinPath) { const zip = await JSZip.loadAsync(buffer); if (zip.file(/.*\.(wsz|wal|zip)$/i).length) { // This is a collection of skins - return "PACK"; + return FILE_TYPES.PACK; } - return zip.file(/^main\.bmp$/i).length === 1 ? "CLASSIC" : "MODERN"; + return zip.file(/^main\.bmp$/i).length === 1 + ? FILE_TYPES.CLASSIC + : FILE_TYPES.MODERN; } catch (e) { - return "INVALID"; + return FILE_TYPES.INVALID; } }