Created
October 15, 2014 11:44
-
-
Save allouis/76ad97e510fbdacf7e9d to your computer and use it in GitHub Desktop.
cleanup jsbin directory on server
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
var fs = require('fs'); | |
var semver = require('semver'); | |
var numToKeep = process.argv[2] || 2; | |
var files = fs.readdirSync(__dirname).filter(function (file) { | |
return file.indexOf('jsbin-v') === 0; | |
}).sort(function (a, b) { | |
return semver.lt(a.slice(7), b.slice(7)); | |
}).slice(numToKeep || 2).forEach(function (file) { | |
console.log('Removing', file); | |
fs.rmdirSync(__dirname + '/' + file); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment