99
1010import fs from 'fs' ;
1111import * as path from 'path' ;
12+ import { getFilesInDirectory } from './fileloader' ;
1213
1314// Place files you wish to ignore by name in here
1415const ignoredFiles : string [ ] = [ '.DS_Store' , 'ui.da.json' , 'ui.en.json' , 'README.md' ] ;
@@ -26,42 +27,6 @@ const readFile = (fileLocation: string, expect: string) => {
2627 return fileContent . toString ( ) . toLowerCase ( ) . includes ( expect . toLowerCase ( ) ) ;
2728} ;
2829
29- type DirectoryContents = {
30- files : string [ ] ;
31- folders : string [ ] ;
32- } ;
33-
34- const readDirectory = ( directory : string , ignoreList : string [ ] ) : DirectoryContents => {
35- const files : string [ ] = [ ] ;
36- const folders : string [ ] = [ ] ;
37- const filesRead = fs . readdirSync ( directory ) ;
38- filesRead . forEach ( file => {
39- if ( ignoreList . includes ( file ) ) return ;
40- if ( file . endsWith ( '.json' ) ) return ; // Json cant have comments
41- const fileLocation = path . join ( directory , file ) ;
42- const stats = fs . statSync ( fileLocation ) ;
43- if ( stats . isFile ( ) ) {
44- files . push ( fileLocation ) ;
45- } else {
46- folders . push ( fileLocation ) ;
47- }
48- } ) ;
49- return { files : files , folders : folders } ;
50- } ;
51-
52- const flattenDirectory = ( directory : string ) : string [ ] => {
53- const files : string [ ] = [ ] ;
54- const content = readDirectory ( directory , ignoredFiles ) ;
55- const filesFromSubFolders : string [ ] = [ ] ;
56- content . folders . forEach ( value => {
57- const subFolderFlat = flattenDirectory ( value ) ;
58- subFolderFlat . forEach ( value => filesFromSubFolders . push ( value ) ) ;
59- } ) ;
60- filesFromSubFolders . forEach ( value => files . push ( value ) ) ;
61- content . files . forEach ( value => files . push ( value ) ) ;
62- return files ;
63- } ;
64-
6530const filesMissingIdentifier = ( files : string [ ] , expects : string [ ] ) : string [ ] => {
6631 const filesWithMissingIdentifier : string [ ] = [ ] ;
6732
@@ -82,7 +47,7 @@ describe('License identifier tests', () => {
8247 'All files should contain license identifier' ,
8348 ( ) => {
8449 const flatten = directoriesToScan . reduce ( ( acc : string [ ] , current ) => {
85- return acc . concat ( flattenDirectory ( current ) ) ;
50+ return acc . concat ( getFilesInDirectory ( current , ignoredFiles ) ) ;
8651 } , [ ] ) ;
8752
8853 const faultyFiles = filesMissingIdentifier ( flatten , [
0 commit comments