qleaner 1.0.6 → 1.0.7
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 +4 -2
- package/command.js +12 -8
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -15,6 +15,7 @@ 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>", "Exclude directories from the scan")
|
|
18
19
|
.action(async (path, options) => {
|
|
19
20
|
const imports = await getFiles(path, options);
|
|
20
21
|
});
|
|
@@ -22,8 +23,9 @@ program
|
|
|
22
23
|
program.command("qlean-scan")
|
|
23
24
|
.description("Scan the project for unused files")
|
|
24
25
|
.argument("<path>", "The path to the directory to scan for unused files")
|
|
25
|
-
.
|
|
26
|
-
|
|
26
|
+
.option("-e, --exclude-dir <dir>", "Exclude directories from the scan")
|
|
27
|
+
.action(async (path, options) => {
|
|
28
|
+
const unusedFiles = await unUsedFiles(path, options);
|
|
27
29
|
console.clear()
|
|
28
30
|
unusedFiles.forEach((file) => {
|
|
29
31
|
console.log(file);
|
package/command.js
CHANGED
|
@@ -6,18 +6,18 @@ const traverse = require("@babel/traverse").default;
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
async function getFiles(directory = "src", options) {
|
|
9
|
-
|
|
9
|
+
const contentPaths = [`${directory}/**/*.{tsx,ts,js,jsx}`];
|
|
10
|
+
if (options.excludeDir) {
|
|
11
|
+
contentPaths.push(`!${options.excludeDir}/**`);
|
|
12
|
+
}
|
|
13
|
+
const files = await fg(contentPaths);
|
|
10
14
|
const imports = [];
|
|
11
15
|
for (const file of files) {
|
|
12
16
|
const code = fs.readFileSync(file, "utf8");
|
|
13
17
|
const ast = parser.parse(code, {
|
|
14
18
|
sourceType: "module",
|
|
15
|
-
plugins: [
|
|
16
|
-
"jsx",
|
|
17
|
-
"typescript",
|
|
18
|
-
],
|
|
19
|
+
plugins: ["jsx", "typescript"],
|
|
19
20
|
});
|
|
20
|
-
|
|
21
21
|
traverse(ast, {
|
|
22
22
|
ImportDeclaration: ({ node }) => {
|
|
23
23
|
imports.push({
|
|
@@ -57,8 +57,12 @@ async function getFiles(directory = "src", options) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
async function unUsedFiles(directory = "src") {
|
|
61
|
-
const
|
|
60
|
+
async function unUsedFiles(directory = "src", options) {
|
|
61
|
+
const contentPaths = [`${directory}/**/*.{tsx,ts,js,jsx}`];
|
|
62
|
+
if (options.excludeDir) {
|
|
63
|
+
contentPaths.push(`!${options.excludeDir}/**`);
|
|
64
|
+
}
|
|
65
|
+
const files = await fg(contentPaths);
|
|
62
66
|
const imports = [];
|
|
63
67
|
const unusedFiles = [];
|
|
64
68
|
for (const file of files) {
|