Last active
January 14, 2019 02:28
-
-
Save EZaykov/34f8ce0c5447fa74675ab9475c5c677f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp'); | |
const path = require('path'); | |
const del = require('del'); | |
const recursiveReaddir = require('recursive-readdir'); | |
const _ = require('lodash'); | |
gulp.watch('src/**/*.ts', async function clean (done) { | |
const srcFiles = await new Promise((resolve, reject) => { | |
recursiveReaddir('src', (err, files) => { | |
if(err) reject(err); | |
const arr = files.map(file => path.basename(file)) | |
.filter(file => file.includes('.ts')) | |
.map(file => path.basename(file, '.ts')); | |
resolve(arr); | |
}); | |
}); | |
let distFiles = await new Promise((resolve, reject) => { | |
recursiveReaddir('dist', (err, files) => { | |
if(err) reject(err); | |
const arr = files.map(file => path.basename(file)) | |
.filter(file => file.includes('.js')) | |
.map(file => path.basename(file, '.js')) | |
.map(file => path.basename(file, '.js.map')) | |
resolve(arr); | |
}); | |
}); | |
distFiles = _.uniq(distFiles); | |
const notFound = distFiles.filter(file => srcFiles.indexOf(file) === -1); | |
notFound.forEach(file => { | |
del([ | |
`dist/**/${file}.js`, | |
`dist/**/${file}.js.map` | |
]); | |
}); | |
done(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment