Skip to content

Commit ede3329

Browse files
authored
Merge pull request #111 from Nevon/additional-resources
Include tables from additional stacks
2 parents 9dd31b4 + 06de8ca commit ede3329

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

index.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,45 @@ class ServerlessDynamodbLocal {
171171
}
172172
}
173173

174-
/**
175-
* Gets the table definitions
176-
*/
177-
get tables() {
178-
const resources = this.service.resources.Resources;
174+
getDefaultStack() {
175+
return _.get(this.service, "resources");
176+
}
177+
178+
getAdditionalStacks() {
179+
return _.values(_.get(this.service, "custom.additionalStacks", {}));
180+
}
181+
182+
hasAdditionalStacksPlugin() {
183+
return _.get(this.service, "plugins", []).includes("serverless-plugin-additional-stacks");
184+
}
185+
186+
getTableDefinitionsFromStack(stack) {
187+
const resources = _.get(stack, "Resources", []);
179188
return Object.keys(resources).map((key) => {
180189
if (resources[key].Type === "AWS::DynamoDB::Table") {
181190
return resources[key].Properties;
182191
}
183192
}).filter((n) => n);
184193
}
185194

195+
/**
196+
* Gets the table definitions
197+
*/
198+
get tables() {
199+
let stacks = [];
200+
201+
const defaultStack = this.getDefaultStack();
202+
if (defaultStack) {
203+
stacks.push(defaultStack);
204+
}
205+
206+
if (this.hasAdditionalStacksPlugin()) {
207+
stacks = stacks.concat(this.getAdditionalStacks());
208+
}
209+
210+
return stacks.map((stack) => this.getTableDefinitionsFromStack(stack)).reduce((tables, tablesInStack) => tables.concat(tablesInStack), []);
211+
}
212+
186213
/**
187214
* Gets the seeding sources
188215
*/

0 commit comments

Comments
 (0)