@awesomeness-js/utils 1.0.17 → 1.0.18
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/index.js +7 -0
- package/package.json +1 -1
- package/src/getAllFiles.js +41 -45
- package/src/utils/shouldIgnore.js +38 -12
- package/test/css/hideMe.env +0 -0
- package/test/css/some.css +0 -0
- package/test/css/some.js +0 -0
- package/test/dontIgnore.js +0 -0
- package/test/ignoreFolder/ignoreMe.js +3 -0
- package/test/ignoreFolder2/ignoreMe.js +3 -0
- package/test/js/abc.test.js +0 -0
- package/test/js/hideMe.env +0 -0
- package/test/js/some.css +0 -0
- package/test/js/some.js +0 -0
- package/test/secret.test.js +1 -0
- package/test.js +12 -5
- package/types/index.d.ts +7 -0
package/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import _convertBytes from './src/convertBytes.js';
|
|
|
9
9
|
import _each from './src/each.js';
|
|
10
10
|
import _eachAsync from './src/eachAsync.js';
|
|
11
11
|
import _getAllFiles from './src/getAllFiles.js';
|
|
12
|
+
import _ignoreFolder_ignoreMe from './src/ignoreFolder/ignoreMe.js';
|
|
13
|
+
import _ignoreMe from './src/ignoreMe.js';
|
|
12
14
|
import _isUUID from './src/isUUID.js';
|
|
13
15
|
import _md5 from './src/md5.js';
|
|
14
16
|
import _setLocalEnvs from './src/setLocalEnvs.js';
|
|
@@ -31,6 +33,7 @@ export { _convertBytes as convertBytes };
|
|
|
31
33
|
export { _each as each };
|
|
32
34
|
export { _eachAsync as eachAsync };
|
|
33
35
|
export { _getAllFiles as getAllFiles };
|
|
36
|
+
export { _ignoreMe as ignoreMe };
|
|
34
37
|
export { _isUUID as isUUID };
|
|
35
38
|
export { _md5 as md5 };
|
|
36
39
|
export { _setLocalEnvs as setLocalEnvs };
|
|
@@ -63,11 +66,15 @@ export default {
|
|
|
63
66
|
each: _each,
|
|
64
67
|
eachAsync: _eachAsync,
|
|
65
68
|
getAllFiles: _getAllFiles,
|
|
69
|
+
ignoreMe: _ignoreMe,
|
|
66
70
|
isUUID: _isUUID,
|
|
67
71
|
md5: _md5,
|
|
68
72
|
setLocalEnvs: _setLocalEnvs,
|
|
69
73
|
toPennies: _toPennies,
|
|
70
74
|
uuid: _uuid,
|
|
75
|
+
ignoreFolder: {
|
|
76
|
+
ignoreMe: _ignoreFolder_ignoreMe,
|
|
77
|
+
},
|
|
71
78
|
utils: {
|
|
72
79
|
buildExportsTree: _utils_buildExportsTree,
|
|
73
80
|
buildFileDataList: _utils_buildFileDataList,
|
package/package.json
CHANGED
package/src/getAllFiles.js
CHANGED
|
@@ -3,50 +3,46 @@ import { join } from 'path';
|
|
|
3
3
|
import shouldIgnore from './utils/shouldIgnore.js';
|
|
4
4
|
|
|
5
5
|
export default function getAllFiles(base, {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
dir = '.',
|
|
7
|
+
files = [],
|
|
8
|
+
ignore = [],
|
|
9
|
+
fileTypes = []
|
|
10
10
|
} = {}) {
|
|
11
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
|
-
return files;
|
|
51
|
-
|
|
52
|
-
}
|
|
12
|
+
const directory = join(base, dir);
|
|
13
|
+
|
|
14
|
+
const sortedFiles = readdirSync(directory).sort();
|
|
15
|
+
|
|
16
|
+
sortedFiles.forEach(file => {
|
|
17
|
+
const fullPath = join(directory, file);
|
|
18
|
+
// 1) Generate the original "relative path"
|
|
19
|
+
const relativePath = join(dir, file).replace(/\\/g, '/');
|
|
20
|
+
|
|
21
|
+
// 2) Prepend a slash so patterns like "/css/*.js" will match "/css/some.js"
|
|
22
|
+
const pathForIgnore = '/' + relativePath.replace(/^\/*/, '');
|
|
23
|
+
|
|
24
|
+
// 3) Check with the leading slash path
|
|
25
|
+
if (shouldIgnore(pathForIgnore, ignore)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Recurse if it's a directory
|
|
30
|
+
if (statSync(fullPath).isDirectory()) {
|
|
31
|
+
getAllFiles(base, {
|
|
32
|
+
dir: join(dir, file),
|
|
33
|
+
files,
|
|
34
|
+
ignore,
|
|
35
|
+
fileTypes
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
// Filter by file types if specified
|
|
39
|
+
if (fileTypes.length > 0 && !fileTypes.some(ext => file.endsWith(ext))) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// 4) Store the original relative path (without leading slash) in `files` if you prefer
|
|
43
|
+
files.push(relativePath);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return files;
|
|
48
|
+
}
|
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
export default function shouldIgnore(filePath, ignorePatterns) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
// filePath is already something like "/css/some.js"
|
|
3
|
+
return ignorePatterns.some(pattern => {
|
|
4
|
+
// pattern might be "/css/*.js" or "/ignoreFolder", etc.
|
|
5
|
+
let normalizedPattern = pattern.replace(/\\/g, '/');
|
|
6
|
+
|
|
7
|
+
// 1) Full directory ignore: "/ignoreFolder" => ignore "/ignoreFolder" + subdirectories
|
|
8
|
+
// If the pattern ends with "/", treat it as a directory path.
|
|
9
|
+
if (!normalizedPattern.includes('*')) {
|
|
10
|
+
// e.g. "/ignoreFolder/"
|
|
11
|
+
if (normalizedPattern.endsWith('/')) {
|
|
12
|
+
normalizedPattern = normalizedPattern.slice(0, -1); // remove trailing slash
|
|
13
|
+
}
|
|
14
|
+
return filePath === normalizedPattern || filePath.startsWith(normalizedPattern + '/');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 2) folder/* => Ignore all immediate children in that folder (no subfolders)
|
|
6
18
|
if (normalizedPattern.endsWith('/*')) {
|
|
7
|
-
const
|
|
8
|
-
|
|
19
|
+
const baseFolder = normalizedPattern.slice(0, -2); // e.g. "/css"
|
|
20
|
+
// e.g. filePath === "/css/some.js" => startsWith("/css/")
|
|
21
|
+
// But also ensure there's no further subfolder.
|
|
22
|
+
return filePath.startsWith(baseFolder + '/') &&
|
|
23
|
+
!filePath.slice(baseFolder.length + 1).includes('/');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 3) *.ext => extension-based ignore (any folder)
|
|
27
|
+
if (normalizedPattern.startsWith('*.')) {
|
|
28
|
+
const ext = normalizedPattern.slice(1); // remove '*'
|
|
29
|
+
return filePath.endsWith(ext);
|
|
9
30
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
|
|
32
|
+
// 4) folder/*.ext => only files with that extension in that folder (no subfolders)
|
|
33
|
+
if (normalizedPattern.includes('/*')) {
|
|
34
|
+
const [baseFolder, ext] = normalizedPattern.split('/*');
|
|
35
|
+
return filePath.startsWith(baseFolder + '/') &&
|
|
36
|
+
filePath.endsWith(ext) &&
|
|
37
|
+
!filePath.slice(baseFolder.length + 1).includes('/');
|
|
13
38
|
}
|
|
14
|
-
|
|
39
|
+
|
|
40
|
+
// 5) Exact match
|
|
41
|
+
return filePath === normalizedPattern;
|
|
15
42
|
});
|
|
16
|
-
|
|
17
|
-
}
|
|
43
|
+
}
|
|
File without changes
|
|
File without changes
|
package/test/css/some.js
ADDED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/js/some.css
ADDED
|
File without changes
|
package/test/js/some.js
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// just a test file to ignore
|
package/test.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import utils from './index.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
let fileList2 = utils.getAllFiles('./test', {
|
|
4
|
+
// fileTypes: ['.css'],
|
|
5
|
+
// fileTypes: ['.js'],
|
|
6
|
+
ignore: [
|
|
7
|
+
"/ignoreFolder",
|
|
8
|
+
"/ignoreFolder2/",
|
|
9
|
+
"*.env",
|
|
10
|
+
"*.test.js",
|
|
11
|
+
"/css/*.js",
|
|
12
|
+
"/js/*.css"
|
|
13
|
+
]
|
|
14
|
+
})
|
|
8
15
|
|
|
9
16
|
console.log({fileList2});
|
|
10
17
|
|
package/types/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type _convertBytes from './convertBytes';
|
|
|
9
9
|
import type _each from './each';
|
|
10
10
|
import type _eachAsync from './eachAsync';
|
|
11
11
|
import type _getAllFiles from './getAllFiles';
|
|
12
|
+
import type _ignoreFolder_ignoreMe from './ignoreFolder/ignoreMe';
|
|
13
|
+
import type _ignoreMe from './ignoreMe';
|
|
12
14
|
import type _isUUID from './isUUID';
|
|
13
15
|
import type _md5 from './md5';
|
|
14
16
|
import type _setLocalEnvs from './setLocalEnvs';
|
|
@@ -31,6 +33,7 @@ export declare const convertBytes: typeof _convertBytes;
|
|
|
31
33
|
export declare const each: typeof _each;
|
|
32
34
|
export declare const eachAsync: typeof _eachAsync;
|
|
33
35
|
export declare const getAllFiles: typeof _getAllFiles;
|
|
36
|
+
export declare const ignoreMe: typeof _ignoreMe;
|
|
34
37
|
export declare const isUUID: typeof _isUUID;
|
|
35
38
|
export declare const md5: typeof _md5;
|
|
36
39
|
export declare const setLocalEnvs: typeof _setLocalEnvs;
|
|
@@ -63,11 +66,15 @@ declare const _default: {
|
|
|
63
66
|
each: typeof _each;
|
|
64
67
|
eachAsync: typeof _eachAsync;
|
|
65
68
|
getAllFiles: typeof _getAllFiles;
|
|
69
|
+
ignoreMe: typeof _ignoreMe;
|
|
66
70
|
isUUID: typeof _isUUID;
|
|
67
71
|
md5: typeof _md5;
|
|
68
72
|
setLocalEnvs: typeof _setLocalEnvs;
|
|
69
73
|
toPennies: typeof _toPennies;
|
|
70
74
|
uuid: typeof _uuid;
|
|
75
|
+
ignoreFolder: {
|
|
76
|
+
ignoreMe: typeof _ignoreFolder_ignoreMe,
|
|
77
|
+
},
|
|
71
78
|
utils: {
|
|
72
79
|
buildExportsTree: typeof _utils_buildExportsTree,
|
|
73
80
|
buildFileDataList: typeof _utils_buildFileDataList,
|