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

Question: Is it possible to upload both gzipped and non-gzipped files? #65

Closed
JamesMcMahon opened this issue Jun 4, 2015 · 3 comments
Closed

Comments

@JamesMcMahon
Copy link
Contributor

It is possible to upload both gzipped and non-gzipped files in a single task?

Currently I have the following:

var gulp = require("gulp");
var awspublish = require('gulp-awspublish');
var rename = require("gulp-rename");

var publisher = awspublish.create({
    params: {
        Bucket: 'test-bucket'
    }
});

function prefixFile(path) {
    path.dirname = '/foo/' + path.dirname;
}

gulp.task('s3:gzip', function() {
    return gulp.src('public/**/*')
        .pipe(rename(prefixFile))
        .pipe(awspublish.gzip({ ext: '.gz' }))
        .pipe(publisher.cache())
        .pipe(publisher.publish())
        .pipe(awspublish.reporter());
});

gulp.task('s3:plain', function() {
    return gulp.src('public/**/*')
        .pipe(rename(prefixFile))
        .pipe(publisher.cache())
        .pipe(publisher.publish())
        .pipe(awspublish.reporter()); 
});

But if I try to add sync to either or these tasks they delete each other's files. Is it possible to do this is in single task so that sync respects that both versions of the file should be uploaded?

@pgherveou
Copy link
Owner

You should be able to create two streams merge them and then sync

Sent from my iPhone

On 4 juin 2015, at 08:22, James F McMahon notifications@github.com wrote:

It is possible to upload both gzipped and non-gzipped files in a single task?

Currently I have the following:

var gulp = require("gulp");
var awspublish = require('gulp-awspublish');
var rename = require("gulp-rename");

var publisher = awspublish.create({
params: {
Bucket: 'test-bucket'
}
});

function prefixFile(path) {
path.dirname = '/foo/' + path.dirname;
}

gulp.task('s3:gzip', function() {
return gulp.src('public/*/')
.pipe(rename(prefixFile))
.pipe(awspublish.gzip({ ext: '.gz' }))
.pipe(publisher.cache())
.pipe(publisher.publish())
.pipe(awspublish.reporter());
});

gulp.task('s3:plain', function() {
return gulp.src('public/*/')
.pipe(rename(prefixFile))
.pipe(publisher.cache())
.pipe(publisher.publish())
.pipe(awspublish.reporter());
});

But if I try to add sync to either or these tasks they delete each other's files. Is it possible to do this is in single task so that sync respects that both versions of the file should be uploaded?


Reply to this email directly or view it on GitHub.

@JamesMcMahon
Copy link
Contributor Author

Ah, thanks for the tip, this is what I ended up doing:

var gulp = require("gulp");
var awspublish = require('gulp-awspublish');
var rename = require("gulp-rename");
var merge = require('merge-stream');

var publisher = awspublish.create({
    params: {
        Bucket: 'test-bucket'
    }
});

function prefixFile(path) {
    path.dirname = '/foo/' + path.dirname;
}

gulp.task('s3', function() {
    var gzipFilter = [
        'public/**/*.js', 'public/**/*.html',
        'public/**/*.css', 'public/**/*.xml',
        'public/**/*.txt', 'public/**/*.ico',
        'public/**/*.json',
    ];
    var negativeFilter = gzipFilter.map(function(x) {
        return '!' + x;
    });

    var gzip = gulp.src(gzipFilter)
        .pipe(rename(prefixFile))
        .pipe(awspublish.gzip());

    var plain = gulp.src(['public/**/*'].concat(negativeFilter))
        .pipe(rename(prefixFile));

    return merge(gzip, plain)
        .pipe(publisher.cache())
        .pipe(publisher.publish())
        .pipe(publisher.sync())
        .pipe(awspublish.reporter());
});

Think something like this is worth adding to the examples? I can create a PR when I get a chance.

@pgherveou
Copy link
Owner

yep but maybe just specify the part not specific to your app so just keep

var gzip = gulp.src(zipfiles)
    .pipe(awspublish.gzip());

var plain = gulp.src(plainFiles)

return merge(gzip, plain)
    .pipe(publisher.cache())
    .pipe(publisher.publish())
    .pipe(publisher.sync())
    .pipe(awspublish.reporter());

On Thu, Jun 4, 2015 at 11:52 AM, James F McMahon notifications@github.com
wrote:

Ah, thanks for the tip, this is what I ended up doing:

var gulp = require("gulp");var awspublish = require('gulp-awspublish');var rename = require("gulp-rename");var merge = require('merge-stream');
var publisher = awspublish.create({
params: {
Bucket: 'test-bucket'
}
});
function prefixFile(path) {
path.dirname = '/foo/' + path.dirname;
}

gulp.task('s3', function() {
var gzipFilter = [
'public//*.js', 'public//.html',
'public/__/
.css', 'public//*.xml',
'public/
/.txt', 'public/__/.ico',
'public/*/.json',
];
var negativeFilter = gzipFilter.map(function(x) {
return '!' + x;
});

var gzip = gulp.src(gzipFilter)
    .pipe(rename(prefixFile))
    .pipe(awspublish.gzip());

var plain = gulp.src(['public/**/*'].concat(negativeFilter))
    .pipe(rename(prefixFile));

return merge(gzip, plain)
    .pipe(publisher.cache())
    .pipe(publisher.publish())
    .pipe(publisher.sync())
    .pipe(awspublish.reporter());

});

Think something like this is worth adding to the examples? I can create a
PR when I get a chance.


Reply to this email directly or view it on GitHub
#65 (comment)
.

PG

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