Dmitri Zaitsev
Dmitri Zaitsev

Reputation: 14046

Accessing home directory with `base` in Gulp

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.

Upvotes: 0

Views: 1673

Answers (1)

qcz
qcz

Reputation: 448

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('.'));
});

Upvotes: 4

Related Questions