@awesomeness-js/utils 1.0.16 → 1.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -2,24 +2,51 @@ import { readdirSync, statSync } from 'fs';
2
2
  import { join } from 'path';
3
3
  import shouldIgnore from './utils/shouldIgnore.js';
4
4
 
5
- export default function getAllFiles(base, dir, files = [], ignore = []) {
6
- const directory = join(base, dir);
7
- const normalizedDir = dir.replace(/\\/g, '/');
8
- if (ignore.some(pattern => normalizedDir.startsWith(pattern.replace(/\/\*$/, '')))) {
9
- return files;
10
- }
11
- const sortedFiles = readdirSync(directory).sort();
12
- sortedFiles.forEach(file => {
13
- const fullPath = join(directory, file);
14
- const relativePath = join(dir, file).replace(/\\/g, '/');
15
- if (shouldIgnore(relativePath, ignore)) {
16
- return;
17
- }
18
- if (statSync(fullPath).isDirectory()) {
19
- getAllFiles(base, join(dir, file), files, ignore);
20
- } else if (file.endsWith('.js') && !file.match(/\..*\./)) {
21
- files.push(relativePath);
22
- }
23
- });
24
- return files;
5
+ export default function getAllFiles(base, {
6
+ dir = '.',
7
+ files = [],
8
+ ignore = [],
9
+ fileTypes = []
10
+ } = {}) {
11
+
12
+ const directory = join(base, dir);
13
+ const normalizedDir = dir.replace(/\\/g, '/');
14
+
15
+ if (ignore.some(pattern => normalizedDir.startsWith(pattern.replace(/\/\*$/, '')))) {
16
+ return files;
17
+ }
18
+
19
+ const sortedFiles = readdirSync(directory).sort();
20
+
21
+ sortedFiles.forEach(file => {
22
+
23
+ const fullPath = join(directory, file);
24
+ const relativePath = join(dir, file).replace(/\\/g, '/');
25
+
26
+ if (shouldIgnore(relativePath, ignore)) {
27
+ return;
28
+ }
29
+
30
+ if (statSync(fullPath).isDirectory()) {
31
+
32
+ getAllFiles(base, {
33
+ dir: join(dir, file),
34
+ files,
35
+ ignore
36
+ });
37
+
38
+ } else {
39
+
40
+ if(fileTypes.length > 0) {
41
+ if (!fileTypes.some(ext => file.endsWith(ext))) return;
42
+ }
43
+
44
+ files.push(relativePath);
45
+
46
+ }
47
+
48
+ });
49
+
50
+ return files;
51
+
25
52
  }
@@ -3,7 +3,10 @@ import extractJSDocComment from './extractJSDocComment.js';
3
3
  import { join } from 'path';
4
4
 
5
5
  export default function buildFileDataList(src, ignore, includeComments) {
6
- const allFiles = getAllFiles(src, '.', [], ignore);
6
+ const allFiles = getAllFiles(src, {
7
+ ignore,
8
+ fileTypes: ['.js']
9
+ });
7
10
  return allFiles.map(file => {
8
11
  const normalizedFile = file.replace(/\\/g, '/');
9
12
  const parts = normalizedFile.split('/');
package/test.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import utils from './index.js';
2
2
 
3
- let fileList = utils.getAllFiles('./src');
4
- console.log({fileList});
3
+
4
+ let fileList2 = utils.getAllFiles('./secrets', {
5
+ fileTypes: ['.env'],
6
+ ignore: ['dev.env']
7
+ });
8
+
9
+ console.log({fileList2});
5
10
 
6
11
  let md5Test = utils.md5('test');
7
12
  console.log({md5Test});
@@ -1 +1,6 @@
1
- export default function getAllFiles(base: any, dir: any, files?: any[], ignore?: any[]): any[];
1
+ export default function getAllFiles(base: any, { dir, files, ignore, fileTypes }?: {
2
+ dir?: string;
3
+ files?: any[];
4
+ ignore?: any[];
5
+ fileTypes?: any[];
6
+ }): any[];