Skip to content

Instantly share code, notes, and snippets.

@gpickin
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpickin/218068bf525a8f02d2a0 to your computer and use it in GitHub Desktop.
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.
#!/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