const { dest, watch } = require('gulp'); const ts = require('gulp-typescript'); const fs = require('fs'); const path = require('path'); const tsProject = ts.createProject('tsconfig.json'); function deleteFolderRecursive(folder) { if (fs.existsSync(folder)) { fs.readdirSync(folder).forEach(function(file) { const currPath = path.resolve(folder, file); if (fs.lstatSync(currPath).isDirectory()) { deleteFolderRecursive(currPath); } else { fs.unlinkSync(currPath); } }); fs.rmdirSync(folder); } } function removeCompiledMigrations() { const migrationsDir = path.resolve('dist/main/migrations'); deleteFolderRecursive(migrationsDir); } function tsc() { removeCompiledMigrations(); return tsProject .src() .pipe(tsProject()) .js.pipe(dest('dist')); } exports.tsc = tsc; exports['tsc:watch'] = () => { watch('./src/**/*.ts', { ignoreInitial: false }, tsc); };