1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
- import { fileURLToPath } from 'url' ;
4
3
5
- const __filename = fileURLToPath ( import . meta. url ) ;
6
- const __dirname = path . dirname ( __filename ) ;
4
+ const __dirname = import . meta. dirname ;
7
5
8
6
function getAllFiles ( dirPath ) {
9
- let nonKebabElements = [ ] ;
7
+ let incorrectFormatFiles = [ ] ;
10
8
const entries = fs . readdirSync ( dirPath , { withFileTypes : true } ) ;
11
9
12
- const kebabCaseRegex = / ^ [ a - z 0 - 9 ] + (?: - [ a - z 0 - 9 ] + ) * $ / ;
10
+ const filenameFormat = / ^ [ a - z 0 - 9 ] + (?: [ - . ] [ a - z 0 - 9 ] + ) * $ / ;
13
11
14
12
for ( const entry of entries ) {
15
13
// Skip certain files/folders
@@ -27,18 +25,18 @@ function getAllFiles(dirPath) {
27
25
? path . parse ( entry . name ) . name
28
26
: entry . name ;
29
27
30
- if ( ! kebabCaseRegex . test ( nameToTest ) ) {
31
- nonKebabElements . push ( path . join ( dirPath , entry . name ) ) ;
28
+ if ( ! filenameFormat . test ( nameToTest ) ) {
29
+ incorrectFormatFiles . push ( path . join ( dirPath , entry . name ) ) ;
32
30
}
33
31
34
32
// Recursively check subdirectories
35
33
if ( entry . isDirectory ( ) ) {
36
34
const subDirResults = getAllFiles ( path . join ( dirPath , entry . name ) ) ;
37
- nonKebabElements = nonKebabElements . concat ( subDirResults ) ;
35
+ incorrectFormatFiles = incorrectFormatFiles . concat ( subDirResults ) ;
38
36
}
39
37
}
40
38
41
- return nonKebabElements ;
39
+ return incorrectFormatFiles ;
42
40
}
43
41
44
42
const folders = [ 'docs' , 'blog' ] ;
0 commit comments