Created
October 7, 2016 09:28
-
-
Save icyflame/0fbcb79684e422759281877ceb70af9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findZip(dir, callback) { | |
var fs = require('fs'); | |
var fileList = fs.readdirSync(dir); | |
var candidates = []; | |
for(i in fileList) { | |
if (fileList[i].match(/.zip$/)) { | |
candidates.push(fileList[i]); | |
} | |
} | |
if (candidates.length == 1) { | |
console.log("Found one other ZIP file: " + candidates[0]); | |
console.log("Do you want to upload this zip file? (y/n): "); | |
var stdin = process.stdin; | |
stdin.resume(); | |
stdin.once("data", function(data) { | |
if (data.toString().localeCompare("y")) { | |
var path = require('path'); | |
callback(null, path.join(dir, candidates[0])); | |
} else { | |
callback(new Error("User rejected uploading of another zip in place of www.zip")); | |
} | |
}); | |
} | |
} | |
findZip("/code/OpenBrews", function(err, filepath) { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} else { | |
console.log("Okay, will upload " + filepath); | |
process.exit(0); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment