-
Notifications
You must be signed in to change notification settings - Fork 8
/
unusedFiles.js
72 lines (62 loc) · 3.48 KB
/
unusedFiles.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*global define, brackets, $, console */
define(function (require, exports, module) {
"use strict";
var DocumentManager = brackets.getModule('document/DocumentManager'),
FileSystem = brackets.getModule('filesystem/FileSystem'),
ProjectManager = brackets.getModule('project/ProjectManager'),
WorkspaceManager = brackets.getModule('view/WorkspaceManager'),
Resizer = brackets.getModule('utils/Resizer'),
resultTemplate = require("text!unusedResult.html"),
unusedPanel = WorkspaceManager.createBottomPanel('unusedFiles.panel', $(resultTemplate), 100),
$unusedPanel = $('#unused-results');
function compareFiles(callingFilesList, unusedFilesList) {
var callingFilesListLength = callingFilesList.length,
unusedFilesListLength = unusedFilesList.length;
function checkinginFile(n) {
DocumentManager.getDocumentText(FileSystem.getFileForPath(callingFilesList[n].fullPath)).done(function (doc) {
var unusedFilesListLength = unusedFilesList.length;
for (var i = 0; i < unusedFilesListLength; i++) {
if ((typeof unusedFilesList[i] !== "undefined")) var used = new RegExp(unusedFilesList[i]["name"], 'i').test(doc);
if ( used ) delete unusedFilesList[i];
}
if (n + 1 === callingFilesList.length){
var unusedFilesListLength = unusedFilesList.length;
for (var j = 0; j < unusedFilesListLength; j++) {
if ((typeof unusedFilesList[j] !== "undefined")) $('table.unusedTable').append('<tr><td>' + unusedFilesList[j]["name"] + '</td><td>' + unusedFilesList[j]["fullPath"] + '</td></tr>');
}
$('#unused-results .title').text(Object.keys(unusedFilesList).length + ' unused file(s)');
Resizer.show( $unusedPanel );
}
});
}
for (var k = 0; k < callingFilesListLength; k++) {
checkinginFile(k);
}
}
function listFiles() {
ProjectManager.getAllFiles().done( function (fileListResult) {
var ext_a = [".html", ".htm", ".css", ".php", ".js", ".aspx", ".ascx", ".master", ".cshtml", ".less", ".scss", ".sass", ".json", ".md"],
ext_b = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".bmp", ".ico", ".js", ".css"],
filesList = [],
unusedFilesList = [],
dot = 0,
ext = '',
fileListResultLength = fileListResult.length;
for (var i = 0; i < fileListResultLength; i++) {
dot = fileListResult[i].name.lastIndexOf("."),
ext = fileListResult[i].name.substring(dot);
if (ext_a.indexOf(ext) !== -1) filesList.push({'name' : fileListResult[i].name, 'fullPath' : fileListResult[i].fullPath});
if (ext_b.indexOf(ext) !== -1) unusedFilesList.push({'name' : fileListResult[i].name, 'fullPath' : fileListResult[i].fullPath});
}
compareFiles(filesList, unusedFilesList);
});
}
function init(){
$('table.unusedTable, #unused-results .title').empty();
$unusedPanel.find('.close').on('click', function() {
Resizer.hide( $unusedPanel );
});
listFiles();
}
exports.init = init;
});