import { readFileSync , existsSync } from 'fs' ; const deglob = require ( 'deglob' ) ; const gutil = require ( 'gulp-util' ) ; const moduleName = 'filename-check' ; interface Config { patterns : string [ ] ; options : { useGitIgnore ? : boolean ; usePackageJson ? : boolean ; configKey ? : string ; gitIgnoreFile ? : string ; ignore ? : string [ ] ; cwd ? : string ; } ; } function loadConfig ( ) { const defaultConfig = { patterns : [ '*' ] , options : { useGitIgnore : true , ignore : [ 'node_modules/**/*' ] , } , } ; if ( ! existsSync ( './package.json' ) ) { gutil . log ( moduleName , gutil . colors . yellow ( 'Can not found package.json, use default config' ) ) ; return defaultConfig ; } const packageConfig = readFileSync ( './package.json' ) . toString ( ) ; if ( packageConfig ) { const config = JSON . parse ( packageConfig ) ; if ( config [ moduleName ] ) return config [ moduleName ] ; } gutil . log ( moduleName , gutil . colors . yellow ( 'Load config from package.json error, use default config' ) ) ; return defaultConfig ; } function doCheck ( files ) { const baseLen = process . cwd ( ) . length ; files . forEach ( filePath => { const relativePath = filePath . substr ( baseLen + 1 , filePath . length - baseLen ) ; if ( relativePath . toLowerCase ( ) !== relativePath ) { gutil . log ( moduleName , gutil . colors . red ( `${ relativePath } contains uppercase characters` ) ) ; process . exitCode = - 1 ; } } ) ; } const config = loadConfig ( ) ; deglob ( config . patterns , config . options , ( err , files ) => { if ( err ) { gutil . log ( moduleName , gutil . colors . red ( err ) ) ; process . exit ( - 1 ) ; } doCheck ( files ) ; } ) ;