0
votes

I am trying to copy selected files from my home directory using Gulp but the following does not do it:

var files = ['one', 'two'];
gulp.task('collect', function(){
  return gulp.src(files, {base: '~/'})
  .pipe(gulp.dest('.'));
});

What is the correct setting for the base to make it work? The Docs is very terse on this.

1
try {base: '.'}, thats what I use - harishr
@entre not enough - files not copied - Dmitri Zaitsev

1 Answers

3
votes

To get the home directory use the user-home package (see https://github.com/sindresorhus/user-home) or when using Node >= 4.0 then you can also use os.homedir(). In Node >= 4.0:

var os = require('os'),
    path = require('path');
var files = ['one', 'two'];
var homeDir = os.homedir();

gulp.task('collect', function(){
    return gulp.src(files.map(x => path.join(homeDir, x)),
            {base: homeDir})
        .pipe(gulp.dest('.'));
});