From 1c417f33d39106470564cc5680f4b6c7e4bd8eea Mon Sep 17 00:00:00 2001 From: danielconde Date: Sun, 24 Mar 2019 18:50:31 +0000 Subject: [PATCH] feat: allow assets bucket name to be provided via config --- .../addAssetsBucketForDeployment.test.js | 20 +++++++++++++++++++ lib/addAssetsBucketForDeployment.js | 12 +++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/__tests__/addAssetsBucketForDeployment.test.js b/lib/__tests__/addAssetsBucketForDeployment.test.js index 5348ee41cb..8c779d33e8 100644 --- a/lib/__tests__/addAssetsBucketForDeployment.test.js +++ b/lib/__tests__/addAssetsBucketForDeployment.test.js @@ -72,6 +72,26 @@ describe("addAssetsBucketForDeployment", () => { }); }); + it("should log when a bucket is going to be provisioned from plugin config", () => { + expect.assertions(1); + + parseNextConfiguration.mockReturnValueOnce( + parsedNextConfigurationFactory() + ); + + plugin = new ServerlessPluginBuilder() + .withNextCustomConfig({ + assetsBucketName: "my-assets" + }) + .build(); + + return addAssetsBucketForDeployment.call(plugin).then(() => { + expect(logger.log).toBeCalledWith( + expect.stringContaining(`Found bucket "my-assets"`) + ); + }); + }); + it("should update coreCloudFormationTemplate with static assets bucket", () => { expect.assertions(2); diff --git a/lib/addAssetsBucketForDeployment.js b/lib/addAssetsBucketForDeployment.js index 5312d13dba..e5e8ae5265 100644 --- a/lib/addAssetsBucketForDeployment.js +++ b/lib/addAssetsBucketForDeployment.js @@ -16,15 +16,23 @@ const getCFTemplatesWithBucket = async function(bucketName) { }; module.exports = async function() { - const { staticAssetsBucket } = parseNextConfiguration( + let { staticAssetsBucket } = parseNextConfiguration( this.getPluginConfigValue("nextConfigDir") ); + const bucketNameFromConfig = this.getPluginConfigValue("assetsBucketName"); + + if (bucketNameFromConfig) { + // bucket name provided via user config takes precendence + // over parsed value from assetPrefix + staticAssetsBucket = bucketNameFromConfig; + } + if (!staticAssetsBucket) { return; } - logger.log(`Found bucket "${staticAssetsBucket}" in assetPrefix!`); + logger.log(`Found bucket "${staticAssetsBucket}"`); const [ compiledCfWithBucket,