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 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>", "Exclude directories from the scan")
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>", "Exclude directories from the scan")
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
- contentPaths.push(`!${options.excludeDir}/**`);
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
- contentPaths.push(`!${options.excludeDir}/**`);
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
- console.log('Not Found', file, imports[i].from);
104
- unusedFiles.push(file);
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qleaner",
3
3
  "packageManager": "yarn@4.6.0",
4
- "version": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "main": "command.js",
6
6
  "bin": "./bin/cli.js",
7
7
  "scripts": {
package/src/3.png DELETED
Binary file
package/src/4.png DELETED
Binary file
@@ -1 +0,0 @@
1
- import main from '../../main';
package/src/demo/demo.tsx DELETED
@@ -1,9 +0,0 @@
1
- import hello from '../hello.find';
2
- import hidden from '../../../demo/book/hidden'
3
- export default function Demo() {
4
- return (
5
- <div>
6
- <img src="/one.png" />
7
- </div>
8
- )
9
- }
@@ -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
- }
@@ -1,2 +0,0 @@
1
- import name from './demo/functions';
2
- import hidden from '~/demo/book/hidden'
package/src/jambo.tsx DELETED
@@ -1,12 +0,0 @@
1
- import * as functions from './demo/functions';
2
- import hello from 'hello.find';
3
- export const JAMBO_JET = 'poa'
4
-
5
- export function JamboJet() {
6
- return (
7
- <div>
8
- <img src={one} />
9
- <img src={'3.png'} />
10
- </div>
11
- )
12
- }
@@ -1 +0,0 @@
1
- import hidden from '../../demo/book/hidden'
package/src/main.js DELETED
@@ -1,6 +0,0 @@
1
- import jambo from 'jambo'
2
- import poa from 'poa'
3
- import './style.css'
4
- import demo from './demo/demo'
5
- import { JamboJet } from './jambo'
6
- import hidden from '@/demo/book/hidden'
package/src/notused.tsx DELETED
File without changes
package/src/one.png DELETED
Binary file
package/src/poa.tsx DELETED
@@ -1,10 +0,0 @@
1
- import one from 'one.png'
2
- export default function poa() {
3
- console.log('poa')
4
- return (
5
- <div>
6
- <img src={one} />
7
- <img src={'3.png'} />
8
- </div>
9
- )
10
- }
package/src/style.css DELETED
@@ -1,7 +0,0 @@
1
- .name {
2
- background-image: url('one.png') no-repeat;
3
- }
4
-
5
- .user {
6
- background-image: url('two.png');
7
- }
package/src/style.scss DELETED
@@ -1,3 +0,0 @@
1
- .body {
2
- background-image: url('4.png');
3
- }
package/src/two.png DELETED
Binary file