k1LoW / serverless-s3-sync

A plugin to sync local directories and S3 prefixes for Serverless Framework :zap:
183 stars 70 forks source link

Add a `preCommand` option for running scripts before sync #59

Closed Jaffa closed 4 years ago

Jaffa commented 4 years ago

Background

I'm attempting to have a single source project containing both React app and serverless spec, and have sls deploy:

  1. Deploy backend resources to AWS
  2. Use @lucas-carneiro/serverless-stack-output to update React app with details from CloudFormation
  3. Run npm build
  4. Use serverless-s3-sync to copy the React build/ directory up to S3.

After getting the output of the CloudFormation stacks written, I need to do something to update the React runtime. I've tried to use serverless-plugin-scripts, but unfortunately I don't think the dynamic hooking and ordering can be made to work. It'd also be nice to avoid an extra dependency.

Purpose

This PR adds a preCommand option to s3Sync, allowing a command to be run before the folder is uploaded to S3:

custom:
  siteBucket: example-${self:provider.stage}
  s3Sync:
    - bucketName: ${self:custom.siteBucket}
      localDir: build/
      preCommand: npm run build
k1LoW commented 4 years ago

@Jaffa Thank you for your commit !! LGTM !

k1LoW commented 4 years ago

Released as v1.13.0.