import * as fs from 'fs-extra' ; import * as path from 'path' ; import * as walk from 'walk' ; import { globalState } from './global-state' ; import { gitIgnores as gitIgnoreNames , ignoreScanFiles } from './structor-config' ; type WalkStats = fs . Stats & { name : string ; } ; type ICustomParsedPath = path . ParsedPath & { isDir : boolean ; } ; export function walkProjectFiles ( ) { return new Promise ( resolve => { const gitIgnores = gitIgnoreNames . map ( dir => { return path . join ( globalState . projectRootPath , dir ) ; } ) ; const scanIgnores = ignoreScanFiles . map ( addon => { return path . join ( globalState . projectRootPath , addon ) ; } ) ; const walker = walk . walk ( globalState . projectRootPath , { filters : [ ... gitIgnores , ... scanIgnores ] } ) ; const files = [ ] ; walker . on ( 'directories' , ( root , dirStatsArray , next ) => { dirStatsArray . forEach ( dirStats => { const dirPath = path . join ( root , dirStats . name ) ; if ( dirPath === globalState . projectRootPath ) { next ( ) ; return ; } if ( gitIgnores . concat ( scanIgnores ) . some ( ignorePath => { return ignorePath === path . join ( root , dirStats . name ) ; } ) ) { next ( ) ; return ; } files . push ( { isDir : true , ... path . parse ( dirPath ) } ) ; next ( ) ; } ) ; } ) ; walker . on ( 'file' , ( root , fileStats , next ) => { if ( gitIgnores . concat ( scanIgnores ) . some ( ignorePath => { return ignorePath === path . join ( root , fileStats . name ) ; } ) ) { next ( ) ; return ; } files . push ( { isDir : false , ... path . parse ( path . join ( root , fileStats . name ) ) } ) ; next ( ) ; } ) ; walker . on ( 'errors' , ( root , nodeStatsArray , next ) => { next ( ) ; } ) ; walker . on ( 'end' , ( ) => { resolve ( files ) ; } ) ; } ) ; }