I'm trying to copy multiple files and folders using gulp.src
and gulp.dest
from my base directory .
to a new subdirectory dist
.
The base directory is the root of a Symfony project.
Here's my gulpfile:
var files = [
'./app**/*.*',
'./bin**/*.*',
'./src**/*.*',
'./tests**/*.*',
'./var/',
'./vendor/',
'./composer.json']
gulp.task('distribute', function() {
return gulp.src(files , { base: '.' }).pipe(gulp.dest('./dist'));
});
I just don't understand, why this isn't working. As result, I get a dist
folder with the contents of the specified folders. So app
, bin
, src
etc. are missing as root folders.
Based on Use gulp to select and move directories and their files, use ./
for the base
option and make sure the paths are correct:
var files = [
'./app/**/*.*',
'./bin/**/*.*',
'./src/**/*.*',
'./tests/**/*.*',
'./var/',
'./vendor/',
'./composer.json'
];
gulp.task('distribute', function() {
return gulp.src(files , { base: './' })
.pipe(gulp.dest('dist'));
});
Don't use the base
option and change your paths a little.
var files = [
'app/**/*.*',
'bin/**/*.*',
'src/**/*.*',
'tests/**/*.*',
'var/',
'vendor/',
'composer.json'
];
gulp.task('distribute', function() {
return gulp.src(files)
.pipe(gulp.dest('./dist'));
});
If you want to move the folder themselves, just make a task for each one using a task generator function.
function moveDirTask(dir, dest) {
return function() {
return gulp.src(`${dir}/**/*`)
.pipe(gulp.dest(`${dest}/${dir}/`));
};
}
gulp.task('move-app', moveDirTask('app', 'dest'));
gulp.task('move-bin', moveDirTask('bin', 'dest'));
gulp.task('move-src', moveDirTask('src', 'dest'));
gulp.task('move-tests', moveDirTask('tests', 'dest'));
// etc.
gulp.task('distribute', [
'move-app',
'move-bin',
'move-src',
'move-tests'
// etc.
], function() {
return gulp.src('composer.json')
.pipe(gulp.dest('dest'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With