From f2d872d999aefe47246d5b25d1a31a4724cb5870 Mon Sep 17 00:00:00 2001 From: wojtekd Date: Wed, 28 Feb 2018 15:30:36 +0100 Subject: [PATCH] Add CLI params for disabling deleting and config/policy/cors updates --- README.md | 2 +- index.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e7d281..99f7be0 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ echo "error page" >> client/dist/error.html **Fourth**, run the plugin, and visit your new website! ``` -serverless client deploy [--stage $STAGE] [--region $REGION] +serverless client deploy [--stage $STAGE] [--region $REGION] [--no-delete-contents] [--no-config-change] [--no-policy-change] [--no-cors-change] ``` The plugin should output the location of your newly deployed static site to the console. diff --git a/index.js b/index.js index 1ac18e1..3d30a9d 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ class Client { this.serverless = serverless; this.provider = 'aws'; this.aws = this.serverless.getProvider(this.provider); + this.options = options; this.commands = { client: { @@ -102,7 +103,7 @@ class Client { } deleteObjectsFromBucket(data) { - if (!this.bucketExists) return BbPromise.resolve(); + if (!this.bucketExists || this.options['delete-contents'] === false) return BbPromise.resolve(); this.serverless.cli.log(`Deleting all objects from bucket ${this.bucketName}...`); @@ -184,6 +185,11 @@ class Client { } function configureBucket() { + if (this.options['config-change'] === false) { + this.serverless.cli.log(`Retaining existing bucket configuration for ${this.bucketName}...`); + return BbPromise.resolve(); + } + this.serverless.cli.log(`Configuring website bucket ${this.bucketName}...`); const indexDoc = this.serverless.service.custom.client.indexDocument || 'index.html' @@ -201,6 +207,11 @@ class Client { } function configurePolicyForBucket(){ + if (this.options['policy-change'] === false) { + this.serverless.cli.log(`Retaining existing bucket policy for ${this.bucketName}...`); + return BbPromise.resolve(); + } + this.serverless.cli.log(`Configuring policy for bucket ${this.bucketName}...`); let policy = { @@ -228,6 +239,11 @@ class Client { } function configureCorsForBucket(){ + if (this.options['cors-change'] === false) { + this.serverless.cli.log(`Retaining existing CORS policy for ${this.bucketName}...`); + return BbPromise.resolve(); + } + this.serverless.cli.log(`Configuring CORS policy for bucket ${this.bucketName}...`); let putPostDeleteRule = {