Last active
August 29, 2015 14:20
-
-
Save gpickin/218068bf525a8f02d2a0 to your computer and use it in GitHub Desktop.
This Cordova Hook cleans up your Cordova www folder, removes those pesky OS files like Thumbs.db and .DS_Store.
This file contains 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
#!/usr/bin/env node | |
// Original : https://blog.nraboy.com/2015/01/hooks-apache-cordova-mobile-applications/ | |
// Modified by Gavin Pickin - 05/09/15 | |
var fs = require('fs'); | |
var path = require('path'); | |
var foldersToProcess = [ | |
"js", | |
"css" | |
]; | |
console.log('-----------------------------------------'); | |
console.log('Cordova Cleanup Starting'); | |
foldersToProcess.forEach(function(folder) { | |
processFiles("www/" + folder); | |
}); | |
function processFiles(dir) { | |
fs.readdir(dir, function(err, list) { | |
if(err) { | |
console.log('processFiles err: ' + err); | |
return; | |
} | |
list.forEach(function(file) { | |
file = dir + '/' + file; | |
fs.stat(file, function(err, stat) { | |
if(!stat.isDirectory()) { | |
switch(path.basename(file)) { | |
case ".DS_Store": | |
fs.unlink(file, function(error) { | |
console.log("Removed file " + file); | |
}); | |
break; | |
case "Thumbs.db": | |
fs.unlink(file, function(error) { | |
console.log("Removed file " + file); | |
}); | |
break; | |
default: | |
//console.log("Skipping file " + file); | |
break; | |
} | |
} | |
else { | |
processFiles( file ); | |
} | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment