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

awspublish.gzip sets s3.path making it impossible to change it later #82

Open
Prinzhorn opened this issue Sep 10, 2015 · 6 comments
Open

Comments

@Prinzhorn
Copy link

Every plugin that tries to change the file path after awspublish.gzip has been run has no effect.

Example using gulp-rename:

//Correctly uploads "bundle.js" into the "s3-folder-prefix" folder inside the bucket
gulp.src('./dist/bundle.js')
    .pipe(rename(function(path) {
        path.dirname = 's3-folder-prefix';
    }))
    .pipe(awspublish.gzip())
    .pipe(publisher.publish(headers))
    .pipe(awspublish.reporter());
});

//Incorrectly uploads "bundle.js" into the bucket root
gulp.src('./dist/bundle.js')
    .pipe(awspublish.gzip())
    .pipe(rename(function(path) {
        path.dirname = 's3-folder-prefix';
    }))
    .pipe(publisher.publish(headers))
    .pipe(awspublish.reporter());
});

The workaround is to use awspublish.gzip immediately before publisher.publish.

@elgreg
Copy link

elgreg commented Nov 7, 2015

Just got bitten by this pretty hard. +1 to fix please

@pgherveou
Copy link
Owner

Maybe we can add a note in the Readme?
Would you mind sending a PR, of if you have a better solution feel free to update the code!

@psullivan6
Copy link

I found this issue really helpful in my searches, so I wanted to update the temporary solution from above with revised code. The below example uses node's path.join to create a path for each file passed in from the source glob. This way, you can have a local sub-directory structure that remains intact as it is moved into a new directory on S3.

var path   = require('path');
var rename = require('gulp-rename');

var NEW_S3_DIRECTORY = 'new/s3/directory-example';

gulp.src('path/to/distribution/directory/**/*')
  .pipe(rename(function(filePath) {
    filePath.dirname = path.join(NEW_S3_DIRECTORY, filePath.dirname);
  }))
  .pipe(awspublish.gzip())
  .pipe(publisher.publish())
  .pipe(publisher.cache())
  .pipe(awspublish.reporter());

@emilymerwin
Copy link

@psullivan6 Thanks! Just make sure you don't do .pipe(publisher.sync()) or it will delete everything else in your bucket

@dcalhoun
Copy link

@emilymerwin @psullivan6 if you'd like, you should be able to use Publisher.sync's prefix option to only sync the specific created directory. From my experience, that leaves the rest of the bucket intact.

@bennypowers
Copy link

Hello Internet,

If you're here because you're using awspublishRouter, take a look at the following configuration, which works to upload to a particular dir called eve

gulp.task('publish', () => {
  const publisher = awspublish.create({
    region: 'us-east-1',
    params: {
      Bucket: 'my-bucket',
    },
  });
  return gulp.src('./build/unbundled/**/*')
    .pipe(awspublishRouter({
      cache: {cacheTime: 315360000, gzip: true},
      routes: {
        // Cache index and service worker for 5 minutes
        "((\bindex\.html\b)|(\bservice-worker\.js\b))": {cacheTime: 600, key: "eve/$&"},
        //pass everything else through to `eve`
        "^.+$": {key: "eve/$&"}
      }
    }))
    .pipe(publisher.publish())
    .pipe(publisher.cache())
    .pipe(awspublish.reporter());
});

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

7 participants