Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy multiples sources to multiples destinations #372

Closed
jgoux opened this issue Mar 25, 2014 · 2 comments
Closed

Copy multiples sources to multiples destinations #372

jgoux opened this issue Mar 25, 2014 · 2 comments

Comments

@jgoux
Copy link

jgoux commented Mar 25, 2014

Hello,
I would like to know if there is a better way to copy a bunch of sources to their own folders.
Here is what I wrote :

var copy = {
sass: {
        src: [
            'vendors/bootstrap-sass-official/vendor/assets/stylesheets/*',
            'vendors/font-awesome/scss/*'
        ],
        dest: 'src/sass/vendors'
    }
};

gulp.task('copy-sass', function() {
    copy.sass.src.forEach(function(src) {
        var dest = copy.sass.dest + '/' + src.split('/')[1];
        gulp.src(src)
        .pipe(gulp.dest(dest));
    });
});

Basically, I grab my files from my vendors/ directory, then I copy them to my src/sass/vendors/ directory inside their vendors subfolders names.
For example :
vendors/font-awesome/scss/font-awesome.scss ----> src/sass/vendors/font-awesome/font-awesome.scss

Thanks in advance, and congratulations for this awesome tool !

@yocontra
Copy link
Member

var copy = {
sass: {
        src: [
            'vendors/bootstrap-sass-official/vendor/assets/stylesheets/*',
            'vendors/font-awesome/scss/*'
        ],
        dest: 'src/sass/vendors'
    }
};

gulp.task('copy-sass', function() {
  return gulp.src(copy.sass.src)
    .pipe(gulp.dest(copy.sass.dest));
});

What paths does that put out in the dest folder? Probably like src/sass/vendors/vendors/font-awesome/etc... right? You can put gulp-rename in between the src and the dest to change path.relative which is where the filenames come from in .dest()

@yocontra
Copy link
Member

You could also use gulp-tap to modify file.path before the files get to .dest() and strip the extra path stuff

var copy = {
  sass: {
    src: [
      'vendors/bootstrap-sass-official/vendor/assets/stylesheets/*',
      'vendors/font-awesome/scss/*'
    ],
    dest: 'src/sass/vendors'
  }
};

gulp.task('copy-sass', function () {
  return gulp.src(copy.sass.src)
    .pipe(tap(function (file) {
      // get the relative path pre-transform
      var relative = file.relative;
      var vendorFolder = file.path.split('/')[1];
      // set the path to vendorFolder/fileName
      file.path = vendorFolder+relative;
      file.base = vendorFolder;
    }))
    .pipe(gulp.dest(copy.sass.dest));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants