const { dest, watch } = require('gulp'); const ts = require('gulp-typescript'); const fs = require('fs'); const path = require('path'); const sourcemaps = require('gulp-sourcemaps'); 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(sourcemaps.init()) .pipe(tsProject()) .pipe(sourcemaps.write('.', { sourceRoot: './', includeContent: false })) .pipe(dest('dist')); } exports.tsc = tsc; exports['tsc:watch'] = () => { watch('./src/**/*.ts', { ignoreInitial: false }, tsc); };