Last active
September 8, 2015 17:50
-
-
Save latentflip/89ff2b538f639858c0a2 to your computer and use it in GitHub Desktop.
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 exec = require('child_process').exec; | |
var config = require('./src/browser.webpack.config.js'); | |
var compiler = require('webpack')(config); | |
var path = require('path'); | |
compiler.run(function (err, stats) { | |
if (err) { | |
throw err | |
} | |
var json = stats.toJson({ | |
assets: true, | |
modules: true | |
}); | |
if (json.errors.length > 0) { | |
console.log(json.errors.join('\n')); | |
throw 'Webpack errors'; | |
} | |
var modules = json.modules.filter(function (m) { return m.name.match(/\/src\//); }); | |
var usedFiles = modules.map(function (m) { | |
return path.resolve(__dirname, m.name); | |
}); | |
getFiles(__dirname + '/src/core', function (err, results) { | |
if (err) { throw err; } | |
var unused = results.filter(function (file) { | |
return usedFiles.indexOf(file) === -1; | |
}); | |
console.log(unused); | |
console.log('Used:', usedFiles.length, 'Files:', results.length, 'Unused:', unused.length); | |
}); | |
}); | |
function getFiles(path, done) { | |
exec('find ' + path + ' -type f', function (err, results) { | |
if (err) { return done(err); } | |
done(null, results.trim().split('\n')); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment