Skip to content

Commit fb8a029

Browse files
committed
Include tables from additional stacks
1 parent cf46a80 commit fb8a029

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
@@ -163,18 +163,45 @@ class ServerlessDynamodbLocal {
163163
dynamodbLocal.stop(this.port);
164164
}
165165

166-
/**
167-
* Gets the table definitions
168-
*/
169-
get tables() {
170-
const resources = this.service.resources.Resources;
166+
getDefaultStack() {
167+
return _.get(this.service, "resources");
168+
}
169+
170+
getAdditionalStacks() {
171+
return _.values(_.get(this.service, "custom.additionalStacks", {}));
172+
}
173+
174+
hasAdditionalStacksPlugin() {
175+
return _.get(this.service, "plugins", []).includes("serverless-plugin-additional-stacks");
176+
}
177+
178+
getTableDefinitionsFromStack(stack) {
179+
const resources = _.get(stack, "Resources", []);
171180
return Object.keys(resources).map((key) => {
172181
if (resources[key].Type === "AWS::DynamoDB::Table") {
173182
return resources[key].Properties;
174183
}
175184
}).filter((n) => n);
176185
}
177186

187+
/**
188+
* Gets the table definitions
189+
*/
190+
get tables() {
191+
let stacks = [];
192+
193+
const defaultStack = this.getDefaultStack();
194+
if (defaultStack) {
195+
stacks.push(defaultStack);
196+
}
197+
198+
if (this.hasAdditionalStacksPlugin()) {
199+
stacks = stacks.concat(this.getAdditionalStacks());
200+
}
201+
202+
return stacks.map(stack => this.getTableDefinitionsFromStack(stack)).reduce((tables, tablesInStack) => tables.concat(tablesInStack), []);
203+
}
204+
178205
/**
179206
* Gets the seeding sources
180207
*/

0 commit comments

Comments
 (0)