Skip to content

Instantly share code, notes, and snippets.

@brandonpapworth
Created November 23, 2015 22:20
Show Gist options
  • Save brandonpapworth/7082326f9c1028e2bce5 to your computer and use it in GitHub Desktop.
Save brandonpapworth/7082326f9c1028e2bce5 to your computer and use it in GitHub Desktop.
'use strict';
const path = require('path');
const del = require('del');
const gulp = require('gulp');
const watch = require('gulp-watch');
const FILE_SRC_GLOB = ['src/**/*'];
const FILE_SRC_GLOB_NO_JS = [FILE_SRC_GLOB[0], `!${FILE_SRC_GLOB[0]}.js`];
const FILE_DEST_GLOB = 'app';
const JS_SRC_GLOB = [`${FILE_SRC_GLOB[0]}.js`];
const JS_DEST_DIR = FILE_DEST_GLOB;
function destPathFromSrc(srcGlob, destGlob, srcPath) {
return path.resolve(destGlob, path.relative(path.resolve(srcGlob), srcPath));
}
gulp.task('watch:sync-deletes', () => {
return new Promise((resolve, reject) => {
watch(FILE_SRC_GLOB, {name: 'watch:sync-deletes', ignoreInitial: true, events: ['unlink'], read: false}, vinylFile => {
let destPath = destPathFromSrc('src', FILE_DEST_GLOB, vinylFile.path);
del(destPath);
// Handle removal of sourcemaps
if (path.extname(vinylFile.path) == '.js') {
del(destPath + '.map');
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment