Skip to content

Commit 421157a

Browse files
committed
Fixing command line parameter definitions and dynamodb local start issues in beta@v1.
1 parent 11783c9 commit 421157a

File tree

1 file changed

+159
-159
lines changed

1 file changed

+159
-159
lines changed

index.js

Lines changed: 159 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -6,183 +6,183 @@ const _ = require('lodash'),
66
AWS = require('aws-sdk'),
77
dynamodbLocal = require('dynamodb-localhost');
88

9-
class DynamodbLocal {
9+
class ServerlessDynamodbLocal {
1010
constructor(serverless, options) {
1111
this.serverless = serverless;
12+
this.service = serverless.service;
1213
this.options = options;
1314
this.provider = 'aws';
1415
this.commands = {
15-
dynamodb: {
16-
commands: {
17-
create: {
18-
lifecycleEvents: ['createHandler'],
19-
options: {
20-
name: {
21-
required: true,
22-
shortcut: 'n',
23-
usage: 'Create a migration template inside the directlry given in s-project.json with the given name.',
24-
}
16+
dynamodb: {
17+
commands: {
18+
create: {
19+
lifecycleEvents: ['createHandler'],
20+
options: {
21+
name: {
22+
required: true,
23+
shortcut: 'n',
24+
usage: 'Create a migration template inside the directlry given in s-project.json with the given name.',
2525
}
26-
},
27-
execute: {
28-
lifecycleEvents: ['executeHandler'],
29-
options: {
30-
name: {
31-
required: true,
32-
shortcut: 'n'
33-
usage: 'Execute a migration template with the given name'
34-
},
35-
region: {
36-
required: true,
37-
shortcut: 'r'
38-
usage: 'Region that dynamodb should be remotely executed'
39-
},
40-
stage: {
41-
required: true,
42-
shortcut: 's'
43-
usage: 'Stage that dynamodb should be remotely executed'
44-
}
26+
}
27+
},
28+
execute: {
29+
lifecycleEvents: ['executeHandler'],
30+
options: {
31+
name: {
32+
required: true,
33+
shortcut: 'n',
34+
usage: 'Execute a migration template with the given name'
35+
},
36+
region: {
37+
required: true,
38+
shortcut: 'r',
39+
usage: 'Region that dynamodb should be remotely executed'
40+
},
41+
stage: {
42+
required: true,
43+
shortcut: 's',
44+
usage: 'Stage that dynamodb should be remotely executed'
4545
}
46-
},
47-
executeAll: {
48-
lifecycleEvents: ['executeAllHandler'],
49-
options: {
50-
region: {
51-
required: true,
52-
shortcut: 'r',
53-
usage: 'Region that dynamodb should be remotely executed'
54-
},
55-
stage: {
56-
required: true,
57-
shortcut: 's',
58-
usage: 'Stage that dynamodb should be remotely executed'
59-
}
46+
}
47+
},
48+
executeAll: {
49+
lifecycleEvents: ['executeAllHandler'],
50+
options: {
51+
region: {
52+
required: true,
53+
shortcut: 'r',
54+
usage: 'Region that dynamodb should be remotely executed'
55+
},
56+
stage: {
57+
required: true,
58+
shortcut: 's',
59+
usage: 'Stage that dynamodb should be remotely executed'
6060
}
61-
},
62-
start: {
63-
lifecycleEvents: ['startHandler'],
64-
options: {
65-
port: {
66-
required: true,
67-
shortcut: 'p',
68-
usage: 'The port number that DynamoDB will use to communicate with your application. If you do not specify this option, the default port is 8000'
69-
},
70-
cors: {
71-
shortcut: 'c',
72-
usage: 'Enable CORS support (cross-origin resource sharing) for JavaScript. You must provide a comma-separated "allow" list of specific domains. The default setting for -cors is an asterisk (*), which allows public access.'
73-
},
74-
inMemory: {
75-
shortcut: 'i',
76-
usage: 'DynamoDB; will run in memory, instead of using a database file. When you stop DynamoDB;, none of the data will be saved. Note that you cannot specify both -dbPath and -inMemory at once.'
77-
},
78-
dbPath: {
79-
shortcut: 'd',
80-
usage: 'The directory where DynamoDB will write its database file. If you do not specify this option, the file will be written to the current directory. Note that you cannot specify both -dbPath and -inMemory at once. For the path, current working directory is <projectroot>/node_modules/serverless-dynamodb-local/dynamob. For example to create <projectroot>/node_modules/serverless-dynamodb-local/dynamob/<mypath> you should specify -d <mypath>/ or --dbPath <mypath>/ with a forwardslash at the end.'
81-
},
82-
sharedDb: {
83-
shortcut: 'h',
84-
usage: 'DynamoDB will use a single database file, instead of using separate files for each credential and region. If you specify -sharedDb, all DynamoDB clients will interact with the same set of tables regardless of their region and credential configuration.'
85-
},
86-
delayTransientStatuses: {
87-
shortcut: 't',
88-
usage: 'Causes DynamoDB to introduce delays for certain operations. DynamoDB can perform some tasks almost instantaneously, such as create/update/delete operations on tables and indexes; however, the actual DynamoDB service requires more time for these tasks. Setting this parameter helps DynamoDB simulate the behavior of the Amazon DynamoDB web service more closely. (Currently, this parameter introduces delays only for global secondary indexes that are in either CREATING or DELETING status.'
89-
},
90-
optimizeDbBeforeStartup: {
91-
shortcut: 'o',
92-
usage: 'Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.'
93-
},
94-
migration: {
95-
shortcut: 'm',
96-
usage: 'After starting dynamodb local, run dynamodb migrations'
97-
}
61+
}
62+
},
63+
start: {
64+
lifecycleEvents: ['startHandler'],
65+
options: {
66+
port: {
67+
shortcut: 'p',
68+
usage: 'The port number that DynamoDB will use to communicate with your application. If you do not specify this option, the default port is 8000'
69+
},
70+
cors: {
71+
shortcut: 'c',
72+
usage: 'Enable CORS support (cross-origin resource sharing) for JavaScript. You must provide a comma-separated "allow" list of specific domains. The default setting for -cors is an asterisk (*), which allows public access.'
73+
},
74+
inMemory: {
75+
shortcut: 'i',
76+
usage: 'DynamoDB; will run in memory, instead of using a database file. When you stop DynamoDB;, none of the data will be saved. Note that you cannot specify both -dbPath and -inMemory at once.'
77+
},
78+
dbPath: {
79+
shortcut: 'd',
80+
usage: 'The directory where DynamoDB will write its database file. If you do not specify this option, the file will be written to the current directory. Note that you cannot specify both -dbPath and -inMemory at once. For the path, current working directory is <projectroot>/node_modules/serverless-dynamodb-local/dynamob. For example to create <projectroot>/node_modules/serverless-dynamodb-local/dynamob/<mypath> you should specify -d <mypath>/ or --dbPath <mypath>/ with a forwardslash at the end.'
81+
},
82+
sharedDb: {
83+
shortcut: 'h',
84+
usage: 'DynamoDB will use a single database file, instead of using separate files for each credential and region. If you specify -sharedDb, all DynamoDB clients will interact with the same set of tables regardless of their region and credential configuration.'
85+
},
86+
delayTransientStatuses: {
87+
shortcut: 't',
88+
usage: 'Causes DynamoDB to introduce delays for certain operations. DynamoDB can perform some tasks almost instantaneously, such as create/update/delete operations on tables and indexes; however, the actual DynamoDB service requires more time for these tasks. Setting this parameter helps DynamoDB simulate the behavior of the Amazon DynamoDB web service more closely. (Currently, this parameter introduces delays only for global secondary indexes that are in either CREATING or DELETING status.'
89+
},
90+
optimizeDbBeforeStartup: {
91+
shortcut: 'o',
92+
usage: 'Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.'
93+
},
94+
migration: {
95+
shortcut: 'm',
96+
usage: 'After starting dynamodb local, run dynamodb migrations'
9897
}
99-
},
100-
remove: {
101-
lifecycleEvents: ['removeHandler']
102-
},
103-
install: {
104-
lifecycleEvents: ['installHandler']
10598
}
99+
},
100+
remove: {
101+
lifecycleEvents: ['removeHandler']
102+
},
103+
install: {
104+
lifecycleEvents: ['installHandler']
106105
}
107106
}
108-
},
109-
this.hooks = {
110-
'dynamodb:create:createHandler': this.createHandler,
111-
'dynamodb:execute:executeHandler': this.executeHandler,
112-
'dynamodb:executeAll:executeAllHandler': this.executeAllHandler,
113-
'dynamodb:remove:removeHandler': this.removeHandler,
114-
'dynamodb:install:installHandler': this.installHandler,
115-
'dynamodb:start:startHandler': this.startHandler,
116107
}
108+
};
117109

118-
createHandler() {
119-
let self = this,
120-
options = this.options;
121-
return new BbPromise(function(resolve, reject) {
122-
let dynamodb = self.dynamodbOptions(),
123-
tableOptions = self.tableOptions();
124-
dynamodbMigrations.init(dynamodb, tableOptions.path);
125-
dynamodbMigrations.create(options.name).then(resolve, reject);
126-
});
127-
}
110+
this.hooks = {
111+
'dynamodb:create:createHandler': this.createHandler.bind(this),
112+
'dynamodb:execute:executeHandler': this.executeHandler.bind(this),
113+
'dynamodb:executeAll:executeAllHandler': this.executeAllHandler.bind(this),
114+
'dynamodb:remove:removeHandler': this.removeHandler.bind(this),
115+
'dynamodb:install:installHandler': this.installHandler.bind(this),
116+
'dynamodb:start:startHandler': this.startHandler.bind(this),
117+
};
118+
}
119+
createHandler() {
120+
let self = this,
121+
options = this.options;
122+
return new BbPromise(function(resolve, reject) {
123+
let dynamodb = self.dynamodbOptions(),
124+
tableOptions = self.tableOptions();
125+
dynamodbMigrations.init(dynamodb, tableOptions.path);
126+
dynamodbMigrations.create(options.name).then(resolve, reject);
127+
});
128+
}
128129

129-
executeHandler() {
130-
let self = this,
131-
options = this.options;
132-
return new BbPromise(function(resolve, reject) {
133-
let dynamodb = self.dynamodbOptions(options.stage, options.region),
134-
tableOptions = self.tableOptions();
135-
dynamodbMigrations.init(dynamodb, tableOptions.path);
136-
dynamodbMigrations.execute(options.name, tableOptions).then(resolve, reject);
137-
});
138-
}
130+
executeHandler() {
131+
let self = this,
132+
options = this.options;
133+
return new BbPromise(function(resolve, reject) {
134+
let dynamodb = self.dynamodbOptions(options.stage, options.region),
135+
tableOptions = self.tableOptions();
136+
dynamodbMigrations.init(dynamodb, tableOptions.path);
137+
dynamodbMigrations.execute(options.name, tableOptions).then(resolve, reject);
138+
});
139+
}
139140

140-
executeAllHandler() {
141-
let self = this,
142-
options = this.options;
143-
return new BbPromise(function(resolve, reject) {
144-
let dynamodb = self.dynamodbOptions(options.stage, options.region),
145-
tableOptions = self.tableOptions();
146-
dynamodbMigrations.init(dynamodb, tableOptions.path);
147-
dynamodbMigrations.executeAll(tableOptions).then(resolve, reject);
148-
});
149-
}
141+
executeAllHandler() {
142+
let self = this,
143+
options = this.options;
144+
return new BbPromise(function(resolve, reject) {
145+
let dynamodb = self.dynamodbOptions(options.stage, options.region),
146+
tableOptions = self.tableOptions();
147+
dynamodbMigrations.init(dynamodb, tableOptions.path);
148+
dynamodbMigrations.executeAll(tableOptions).then(resolve, reject);
149+
});
150+
}
150151

151-
removeHandler() {
152-
return new BbPromise(function(resolve) {
153-
dynamodbLocal.remove(resolve);
154-
});
155-
}
152+
removeHandler() {
153+
return new BbPromise(function(resolve) {
154+
dynamodbLocal.remove(resolve);
155+
});
156+
}
156157

157-
installHandler() {
158-
return new BbPromise(function(resolve) {
159-
dynamodbLocal.install(resolve);
160-
});
161-
}
158+
installHandler() {
159+
return new BbPromise(function(resolve) {
160+
dynamodbLocal.install(resolve);
161+
});
162+
}
162163

163-
startHandler() {
164-
let self = this;
165-
return new BbPromise(function(resolve) {
166-
let config = this.serverless.service.custom.dynamodb,
167-
options = _.merge({
168-
sharedDb: this.options.sharedDb || true
169-
},
170-
this.options,
171-
config && config.start
172-
);
173-
if (options.migration) {
174-
dynamodbLocal.start(options);
175-
console.log(""); // seperator
176-
self.executeAll();
177-
resolve();
178-
} else {
179-
dynamodbLocal.start(options);
180-
console.log("");
181-
resolve();
182-
}
183-
});
184-
}
164+
startHandler() {
165+
let self = this,
166+
options = this.options;
167+
return new BbPromise(function(resolve) {
168+
let config = self.service.custom.dynamodb,
169+
options = _.merge({
170+
sharedDb: self.options.sharedDb || true
171+
},
172+
self.options,
173+
config && config.start
174+
);
175+
if (options.migration) {
176+
dynamodbLocal.start(options);
177+
console.log(""); // seperator
178+
self.executeAll();
179+
resolve();
180+
} else {
181+
dynamodbLocal.start(options);
182+
console.log("");
183+
resolve();
184+
}
185+
});
185186
}
186187
}
187-
}
188-
module.exports = DynamodbLocal;
188+
module.exports = ServerlessDynamodbLocal;

0 commit comments

Comments
 (0)