Skip to content

Commit

Permalink
feat: allow assets bucket name to be provided via config
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcondemarin committed Mar 24, 2019
1 parent aa6644d commit 1c417f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/__tests__/addAssetsBucketForDeployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions lib/addAssetsBucketForDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1c417f3

Please sign in to comment.