tikitariki
1/7/2016 - 12:17 AM

copyToLocal.js

var cp = require('cp')

var localPathToWpContent = '/Users/tiki/dev/VVV/www/avispl/htdocs/wp-content/'
var directoriesToWatch = ['*', 'template-parts/*', 'inc/**/*', 'js/**/*']

gulp.task('copyToLocal', function() {
	gulp.watch(
		directoriesToWatch,
		function(event) {
			if (event.type === 'changed' || event.type === 'added') {
				var filename = event.path.split('/')
				var relativePathStart
				var destRelativePath = ''
				for (var segment in filename) {
					if (filename[segment] == 'themes')
						relativePathStart = segment
				}
				for (var i = relativePathStart; i < filename.length; i++) {
					var endChar = (i == filename.length - 1) ? '' : '/'
					destRelativePath += filename[i] + endChar
				}

				var destination = localPathToWpContent + destRelativePath
				cp(event.path, destination, function(err) {
					if (!err)
						console.log( destRelativePath + ' moved successfully.' )
					else
						console.log(err)
				});
			}
		}
	)
})