qleaner 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +7 -3
- package/command.js +29 -7
- package/package.json +1 -1
- package/src/3.png +0 -0
- package/src/4.png +0 -0
- package/src/demo/book/hidden.tsx +0 -1
- package/src/demo/demo.tsx +0 -9
- package/src/demo/functions.js +0 -18
- package/src/hello.find.tsx +0 -2
- package/src/jambo.tsx +0 -12
- package/src/layer/shell/shell.tsx +0 -1
- package/src/main.js +0 -6
- package/src/notused.tsx +0 -0
- package/src/one.png +0 -0
- package/src/poa.tsx +0 -10
- package/src/style.css +0 -7
- package/src/style.scss +0 -3
- package/src/two.png +0 -0
package/bin/cli.js
CHANGED
|
@@ -15,7 +15,9 @@ program
|
|
|
15
15
|
.argument("<path>", "The path to the directory to scan for imports")
|
|
16
16
|
.option("-l, --list-files", "List all the files in the project")
|
|
17
17
|
.option("-i, --list-imports", "List all the imports in the project")
|
|
18
|
-
.option("-e, --exclude-dir <dir
|
|
18
|
+
.option("-e, --exclude-dir <dir...>", "Exclude directories from the scan")
|
|
19
|
+
.option("-f, --exclude-file <file...>", "Exclude files from the scan")
|
|
20
|
+
.option("-F, --exclude-file-print <file...>", "Do not Print the excluded files")
|
|
19
21
|
.action(async (path, options) => {
|
|
20
22
|
const imports = await getFiles(path, options);
|
|
21
23
|
});
|
|
@@ -23,10 +25,12 @@ program
|
|
|
23
25
|
program.command("qlean-scan")
|
|
24
26
|
.description("Scan the project for unused files")
|
|
25
27
|
.argument("<path>", "The path to the directory to scan for unused files")
|
|
26
|
-
.option("-e, --exclude-dir <dir
|
|
28
|
+
.option("-e, --exclude-dir <dir...>", "Exclude directories from the scan")
|
|
29
|
+
.option("-f, --exclude-file <file...>", "Exclude files from the scan")
|
|
30
|
+
.option("-F, --exclude-file-print <files...>", "Do not Print the excluded files")
|
|
27
31
|
.action(async (path, options) => {
|
|
28
32
|
const unusedFiles = await unUsedFiles(path, options);
|
|
29
|
-
console.clear()
|
|
33
|
+
// console.clear()
|
|
30
34
|
unusedFiles.forEach((file) => {
|
|
31
35
|
console.log(file);
|
|
32
36
|
});
|
package/command.js
CHANGED
|
@@ -7,8 +7,15 @@ const traverse = require("@babel/traverse").default;
|
|
|
7
7
|
|
|
8
8
|
async function getFiles(directory = "src", options) {
|
|
9
9
|
const contentPaths = [`${directory}/**/*.{tsx,ts,js,jsx}`];
|
|
10
|
-
if (options.excludeDir) {
|
|
11
|
-
|
|
10
|
+
if (options.excludeDir && options.excludeDir.length > 0) {
|
|
11
|
+
options.excludeDir.forEach(dir => {
|
|
12
|
+
contentPaths.push(`!${dir}/**`);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (options.excludeFile && options.excludeFile.length > 0) {
|
|
16
|
+
options.excludeFile.forEach(file => {
|
|
17
|
+
contentPaths.push(`!${directory}/**/${file}`);
|
|
18
|
+
});
|
|
12
19
|
}
|
|
13
20
|
const files = await fg(contentPaths);
|
|
14
21
|
const imports = [];
|
|
@@ -59,8 +66,15 @@ async function getFiles(directory = "src", options) {
|
|
|
59
66
|
|
|
60
67
|
async function unUsedFiles(directory = "src", options) {
|
|
61
68
|
const contentPaths = [`${directory}/**/*.{tsx,ts,js,jsx}`];
|
|
62
|
-
if (options.excludeDir) {
|
|
63
|
-
|
|
69
|
+
if (options.excludeDir && options.excludeDir.length > 0) {
|
|
70
|
+
options.excludeDir.forEach(dir => {
|
|
71
|
+
contentPaths.push(`!${dir}/**`);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (options.excludeFile && options.excludeFile.length > 0) {
|
|
75
|
+
options.excludeFile.forEach(file => {
|
|
76
|
+
contentPaths.push(`!${directory}/**/${file}`);
|
|
77
|
+
});
|
|
64
78
|
}
|
|
65
79
|
const files = await fg(contentPaths);
|
|
66
80
|
const imports = [];
|
|
@@ -96,12 +110,16 @@ async function unUsedFiles(directory = "src", options) {
|
|
|
96
110
|
while (!isFound && i < imports.length) {
|
|
97
111
|
|
|
98
112
|
if (compareFiles(file, imports[i].from)) {
|
|
99
|
-
console.log('Found', file, imports[i].from);
|
|
100
113
|
isFound = true;
|
|
101
114
|
break;
|
|
102
115
|
}else if(i === imports.length - 1) {
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
if(options.excludeFilePrint && options.excludeFilePrint.length > 0) {
|
|
117
|
+
if(!isExcludedFile(file, options.excludeFilePrint)){
|
|
118
|
+
unusedFiles.push(file);
|
|
119
|
+
}
|
|
120
|
+
}else {
|
|
121
|
+
unusedFiles.push(file);
|
|
122
|
+
}
|
|
105
123
|
break;
|
|
106
124
|
}
|
|
107
125
|
i++;
|
|
@@ -110,6 +128,10 @@ async function unUsedFiles(directory = "src", options) {
|
|
|
110
128
|
return unusedFiles;
|
|
111
129
|
}
|
|
112
130
|
|
|
131
|
+
function isExcludedFile(file, excludeFiles) {
|
|
132
|
+
return excludeFiles.some(exclude => file.includes(exclude));
|
|
133
|
+
}
|
|
134
|
+
|
|
113
135
|
function compareFiles(filePath, importPath) {
|
|
114
136
|
const importNoExt = importPath.replace(/\.[^/.]+$/, "");
|
|
115
137
|
const prefixImportPath = importNoExt.replace(/^(?:\.{1,2}\/|[@~]+\/)+/, "");
|
package/package.json
CHANGED
package/src/3.png
DELETED
|
Binary file
|
package/src/4.png
DELETED
|
Binary file
|
package/src/demo/book/hidden.tsx
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import main from '../../main';
|
package/src/demo/demo.tsx
DELETED
package/src/demo/functions.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export function demoFunction() {
|
|
2
|
-
return 'demoFunction';
|
|
3
|
-
}
|
|
4
|
-
export function demoFunction2() {
|
|
5
|
-
return 'demoFunction2';
|
|
6
|
-
}
|
|
7
|
-
export function demoFunction3() {
|
|
8
|
-
return 'demoFunction3';
|
|
9
|
-
}
|
|
10
|
-
export function demoFunction4() {
|
|
11
|
-
return 'demoFunction4';
|
|
12
|
-
}
|
|
13
|
-
export function demoFunction5() {
|
|
14
|
-
return 'demoFunction5';
|
|
15
|
-
}
|
|
16
|
-
export function demoFunction6() {
|
|
17
|
-
return 'demoFunction6';
|
|
18
|
-
}
|
package/src/hello.find.tsx
DELETED
package/src/jambo.tsx
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import hidden from '../../demo/book/hidden'
|
package/src/main.js
DELETED
package/src/notused.tsx
DELETED
|
File without changes
|
package/src/one.png
DELETED
|
Binary file
|
package/src/poa.tsx
DELETED
package/src/style.css
DELETED
package/src/style.scss
DELETED
package/src/two.png
DELETED
|
Binary file
|