Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2084

Copy folder with it's content in gulp

I have a folder node_modules which contains @bower_components folder, jquery-powertip folder and other folders.

Using a gulp task I want to copy the content of the @bower_components folder and the jquery-powertip folder with it's content to a destination folder.

The problem I'm facing is copying the jquery-powertip folder with it's content.

I tried as following :

gulp.task('move-dependencies', function () {
    return gulp.src(['node_modules/@bower_components/**', 'node_modules/jquery-powertip'])
               .pipe( gulp.dest(src + '/bower_components') );
});

But this will only copy the jquery-powertip folder without it's content.

I tried this too :

gulp.task('move-dependencies', function () {
    return gulp.src(['node_modules/@bower_components/**', 'node_modules/jquery-powertip/**'])
               .pipe( gulp.dest(src + '/bower_components') );
});

But this will copy the content of the jquery-powertip folder to the target folder destination (I'm not getting the "jquery-powertip" folder in target, just its contents)

So how can I solve this ?

Upvotes: 3

Views: 2649

Answers (2)

Muhammad Mabrouk
Muhammad Mabrouk

Reputation: 675

Just in case someone revisits such a problem. It worked for me to put an asterisks infront of the folder you want to keep (https://github.com/gulpjs/gulp/issues/1358#issuecomment-563448694)

// will copy the assets folder and its sub directories + files to the destination
return gulp.src('assets*/**/*')

// will only copy the sub directories + files of the assets folder to the destination
return gulp.src('assets/**/*')

Upvotes: 0

Taha Paksu
Taha Paksu

Reputation: 15616

I would do it like this:

gulp.task('move-dependencies', function () {
    var task1 = gulp.src(['node_modules/@bower_components/**'])
                .pipe( gulp.dest(src + '/bower_components') );
    var task2 = gulp.src(['node_modules/jquery-powertip/**'])
                .pipe( gulp.dest(src + '/bower_components/jquery-powertip') );
    return [ task1, task2 ]; // or merge(task1, task2);
});

Upvotes: 4

Related Questions