import minimatch from 'minimatch' ; import { deleteAll , deleteEmptyFolders , scanDelete , Task , GlobalTask } from '../lib' ; export const Clean = { global : true , description : 'Cleaning artifacts from previous builds' , async run ( config , log ) { await deleteAll ( [ config . resolveFromRepo ( 'build' ) , config . resolveFromRepo ( 'target' ) , config . resolveFromRepo ( '.node_binaries' ) , ] , log ) ; } , } ; export const CleanPackages = { description : 'Cleaning source for packages that are now installed in node_modules' , async run ( config , log , build ) { await deleteAll ( [ build . resolvePath ( 'packages' ) , build . resolvePath ( 'yarn.lock' ) , build . resolvePath ( '.npmrc' ) ] , log ) ; } , } ; export const CleanTypescript = { description : 'Cleaning typescript source files that have been transpiled to JS' , async run ( config , log , build ) { log . info ( 'Deleted %d files' , await scanDelete ( { directory : build . resolvePath ( ) , regularExpressions : [ /\.(ts|tsx|d\.ts)$/ , /tsconfig.*\.(json|tsbuildinfo)$/ ] , } ) ) ; } , } ; export const CleanExtraFilesFromModules = { description : 'Cleaning tests, examples, docs, etc. from node_modules' , async run ( config , log , build ) { const makeRegexps = ( patterns ) => patterns . map ( ( pattern ) => minimatch . makeRe ( pattern , { nocase : true } ) ) ; const regularExpressions = makeRegexps ( [ '**/test' , '**/tests' , '**/jest.config.js' , '**/__tests__' , '**/*.test.js' , '**/*.snap' , '**/coverage' , '**/doc' , '**/docs' , '**/CONTRIBUTING.md' , '**/Contributing.md' , '**/contributing.md' , '**/History.md' , '**/HISTORY.md' , '**/history.md' , '**/CHANGELOG.md' , '**/Changelog.md' , '**/changelog.md' , '**/example' , '**/examples' , '**/demo' , '**/samples' , '**/.bin' , '**/.eslintrc' , '**/.eslintrc.js' , '**/.eslintrc.yml' , '**/.prettierrc' , '**/.jshintrc' , '**/.babelrc' , '**/.jscs.json' , '**/.lint' , '**/*.flow' , '**/*.webidl' , '**/*.map' , '**/@types' , '**/*.sh' , '**/*.bat' , '**/*.exe' , '**/Gruntfile.js' , '**/gulpfile.js' , '**/Makefile' , '**/*.coffee' , '**/*.scss' , '**/*.sass' , '**/.ts' , '**/.tsx' , '**/.editorconfig' , '**/.vscode' , '**/.gitattributes' , '**/.gitkeep' , '**/.gitempty' , '**/.gitmodules' , '**/.keep' , '**/.empty' , '**/.travis.yml' , '**/.coveralls.yml' , '**/.instanbul.yml' , '**/appveyor.yml' , '**/.zuul.yml' , '**/package-lock.json' , '**/component.json' , '**/bower.json' , '**/yarn.lock' , '**/.*ignore' , '**/.DS_Store' , '**/Dockerfile' , '**/docker-compose.yml' , '**/png-js/images/*.png' , ] ) ; log . info ( 'Deleted %d files' , await scanDelete ( { directory : build . resolvePath ( 'node_modules' ) , regularExpressions , } ) ) ; } , } ; export const CleanExtraBinScripts = { description : 'Cleaning extra bin/* scripts from platform-specific builds' , async run ( config , log , build ) { for ( const platform of config . getNodePlatforms ( ) ) { if ( platform . isWindows ( ) ) { await deleteAll ( [ build . resolvePathForPlatform ( platform , 'bin' , '*' ) , `!${ build . resolvePathForPlatform ( platform , 'bin' , '*.bat' ) }` , ] , log ) ; } else { await deleteAll ( [ build . resolvePathForPlatform ( platform , 'bin' , '*.bat' ) ] , log ) ; } } } , } ; export const CleanEmptyFolders = { description : 'Cleaning all empty folders recursively' , async run ( config , log , build ) { await deleteEmptyFolders ( log , build . resolvePath ( '.' ) , [ build . resolvePath ( 'plugins' ) , build . resolvePath ( 'data' ) , build . resolvePath ( 'logs' ) , ] ) ; } , } ;