-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
39 lines (33 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* jshint node: true */
'use strict';
var cst = require('cst');
var mime = require('mime-types');
var fs = require('fs');
var walk = require('fs-walk');
var path = require('path');
var DeadComputedProperties = require('./lib/dead-computed-properties');
module.exports = {
name: 'ember-cli-tree-shake',
includedCommands: function() {
var treePaths = this.treePaths;
var appPath = treePaths.app;
return {
treeShake: {
name: 'tree-shake',
description: 'Discover code that is probably dead or unused',
run: function(commandOptions, rawArgs) {
var parser = new cst.Parser();
walk.walkSync(appPath, function(basedir, filename, stat) {
var filepath = path.join(basedir, filename);
if (mime.lookup(filepath) !== 'application/javascript') {
return;
}
var code = fs.readFileSync(filepath, 'utf8');
var tree = parser.parse(code);
new DeadComputedProperties(tree, treePaths, filepath).emit();
});
}
}
}
}
};