Skip to content

Commit 202d17c

Browse files
committed
Use Node 4.x-compatible syntax
1 parent fef6e49 commit 202d17c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const _ = require("lodash");
33
const BbPromise = require("bluebird");
44
const AWS = require("aws-sdk");
55
const dynamodbLocal = require("dynamodb-localhost");
6-
const { writeSeeds, locateSeeds } = require("./src/seeder");
6+
const seeder = require("./src/seeder");
77

88
class ServerlessDynamodbLocal {
99
constructor(serverless, options) {
@@ -95,7 +95,7 @@ class ServerlessDynamodbLocal {
9595
}
9696

9797
dynamodbOptions() {
98-
const { config } = this;
98+
const config = this.config;
9999
const port = _.get(config, "start.port", 8000);
100100
const dynamoOptions = {
101101
endpoint: `http://localhost:${port}`,
@@ -112,19 +112,19 @@ class ServerlessDynamodbLocal {
112112

113113
migrateHandler() {
114114
const dynamodb = this.dynamodbOptions();
115-
const { tables } = this;
115+
const tables = this.tables;
116116
return BbPromise.each(tables, (table) => this.createTable(dynamodb, table));
117117
}
118118

119119
seedHandler() {
120-
const { doc: documentClient } = this.dynamodbOptions();
121-
const { seedSources } = this;
120+
const documentClient = this.dynamodbOptions().doc;
121+
const seedSources = this.seedSources;
122122
return BbPromise.each(seedSources, (source) => {
123123
if (!source.table) {
124124
throw new Error("seeding source \"table\" property not defined");
125125
}
126-
return locateSeeds(source.sources || [])
127-
.then((seeds) => writeSeeds(documentClient, source.table, seeds));
126+
return seeder.locateSeeds(source.sources || [])
127+
.then((seeds) => seeder.writeSeeds(documentClient, source.table, seeds));
128128
});
129129
}
130130

@@ -133,12 +133,12 @@ class ServerlessDynamodbLocal {
133133
}
134134

135135
installHandler() {
136-
const { options } = this;
136+
const options = this.options;
137137
return new BbPromise((resolve) => dynamodbLocal.install(resolve, options.localPath));
138138
}
139139

140140
startHandler() {
141-
const { config } = this;
141+
const config = this.config;
142142
const options = _.merge({
143143
sharedDb: this.options.sharedDb || true
144144
},
@@ -172,7 +172,7 @@ class ServerlessDynamodbLocal {
172172
get seedSources() {
173173
const config = this.service.custom.dynamodb;
174174
const seedConfig = _.get(config, "seed", {});
175-
const { seed } = this.options;
175+
const seed = this.options.seed;
176176
if (!seed) {
177177
console.log("No seed option defined. Cannot seed data.");
178178
return [];

src/seeder.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
const AWS = require("aws-sdk");
23
const BbPromise = require("bluebird");
34
const _ = require("lodash");
@@ -110,7 +111,10 @@ function getSeedsAtLocation(location) {
110111
* Locates seeds given a set of files to scrape
111112
* @param {string[]} sources The filenames to scrape for seeds
112113
*/
113-
function locateSeeds(sources = [], cwd = process.cwd()) {
114+
function locateSeeds(sources, cwd) {
115+
sources = sources || [];
116+
cwd = cwd || process.cwd();
117+
114118
const locations = sources.map((source) => path.join(cwd, source));
115119
return BbPromise.map(locations, (location) => {
116120
return fileExists(location).then((exists) => {

0 commit comments

Comments
 (0)