qleaner 1.0.6 → 1.0.8

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 CHANGED
@@ -15,6 +15,8 @@ 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")
19
+ .option("-f, --exclude-file <file...>", "Exclude files from the scan")
18
20
  .action(async (path, options) => {
19
21
  const imports = await getFiles(path, options);
20
22
  });
@@ -22,9 +24,11 @@ program
22
24
  program.command("qlean-scan")
23
25
  .description("Scan the project for unused files")
24
26
  .argument("<path>", "The path to the directory to scan for unused files")
25
- .action(async (path) => {
26
- const unusedFiles = await unUsedFiles(path);
27
- console.clear()
27
+ .option("-e, --exclude-dir <dir...>", "Exclude directories from the scan")
28
+ .option("-f, --exclude-file <file...>", "Exclude files from the scan")
29
+ .action(async (path, options) => {
30
+ const unusedFiles = await unUsedFiles(path, options);
31
+ // console.clear()
28
32
  unusedFiles.forEach((file) => {
29
33
  console.log(file);
30
34
  });
package/command.js CHANGED
@@ -6,18 +6,25 @@ const traverse = require("@babel/traverse").default;
6
6
 
7
7
 
8
8
  async function getFiles(directory = "src", options) {
9
- const files = await fg([`${directory}/**/*.{tsx,ts,js,jsx}`]);
9
+ const contentPaths = [`${directory}/**/*.{tsx,ts,js,jsx}`];
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
+ });
19
+ }
20
+ const files = await fg(contentPaths);
10
21
  const imports = [];
11
22
  for (const file of files) {
12
23
  const code = fs.readFileSync(file, "utf8");
13
24
  const ast = parser.parse(code, {
14
25
  sourceType: "module",
15
- plugins: [
16
- "jsx",
17
- "typescript",
18
- ],
26
+ plugins: ["jsx", "typescript"],
19
27
  });
20
-
21
28
  traverse(ast, {
22
29
  ImportDeclaration: ({ node }) => {
23
30
  imports.push({
@@ -57,8 +64,19 @@ async function getFiles(directory = "src", options) {
57
64
  }
58
65
  }
59
66
 
60
- async function unUsedFiles(directory = "src") {
61
- const files = await fg([`${directory}/**/*.{tsx,ts,js,jsx}`]);
67
+ async function unUsedFiles(directory = "src", options) {
68
+ const contentPaths = [`${directory}/**/*.{tsx,ts,js,jsx}`];
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
+ });
78
+ }
79
+ const files = await fg(contentPaths);
62
80
  const imports = [];
63
81
  const unusedFiles = [];
64
82
  for (const file of files) {
@@ -92,11 +110,9 @@ async function unUsedFiles(directory = "src") {
92
110
  while (!isFound && i < imports.length) {
93
111
 
94
112
  if (compareFiles(file, imports[i].from)) {
95
- console.log('Found', file, imports[i].from);
96
113
  isFound = true;
97
114
  break;
98
115
  }else if(i === imports.length - 1) {
99
- console.log('Not Found', file, imports[i].from);
100
116
  unusedFiles.push(file);
101
117
  break;
102
118
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qleaner",
3
3
  "packageManager": "yarn@4.6.0",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "main": "command.js",
6
6
  "bin": "./bin/cli.js",
7
7
  "scripts": {
File without changes
File without changes