diff --git a/package.json b/package.json index e3d3af41..edf01737 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject", "build-index": "node ./scripts/findSkins.js", - "create-search-index": "node ./scripts/createSearchIndex.js > index.json" + "create-search-index": "node ./scripts/createSearchIndex.js > index.json", + "extract": "find ../webamp/experiments/automatedScreenshots/skins \"(\" -name \"*.wsz\" -o -name \"*.zip\" \")\" -exec node ./scripts/extractSkinText.js \"{}\" \\;" }, "prettier": {}, "browserslist": [ diff --git a/scripts/extractSkinText.js b/scripts/extractSkinText.js new file mode 100644 index 00000000..4023bf8c --- /dev/null +++ b/scripts/extractSkinText.js @@ -0,0 +1,52 @@ +const path = require("path"); +var { exec } = require("child_process"); + +async function extractTextData(path) { + const reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g; + const extract = value => (value && value.match(reg)) || []; + + const ignoreFiles = [ + "genex.txt", + "genexinfo.txt", + "gen_gslyrics.txt", + "region.txt", + "pledit.txt", + "viscolor.txt", + "winampmb.txt", + "gen_ex help.txt", + "mbinner.txt" + // Skinning Updates.txt ? + ]; + + const ignoreArgs = ignoreFiles + .map(file => `-x "**/${file}" ${file}`) + .join(" "); + + // Change -p to -c to get context of which file is missing + const debug = false; + const listFlag = debug ? "-c" : "-p"; + + // TODO: Escape path + const cmd = `unzip ${listFlag} -C "${path}" "file_id.diz" "*.txt" ${ignoreArgs}`; + + const raw = await new Promise((resolve, reject) => { + exec(cmd, function(error, stdout, stderr) { + if (error != null) { + //reject(error); + //return; + } + resolve(stdout); + }); + }); + + return { raw, emails: extract(raw) }; +} + +const skinPath = path.join(process.cwd(), process.argv[2]); + +extractTextData(skinPath).then(data => { + if (data.emails.length) { + // console.log(data.emails); + } + console.log(data); +});