99x / dynamodb-localhost

Dynamodb localhost runner for development and testing
MIT License
35 stars 92 forks source link

Allow a custom install path #22

Closed crash7 closed 6 years ago

crash7 commented 6 years ago

Hello, First of all, thanks for this lib and the serverless-dynamodb-local plugin!

I'm using this library through the serverless-dynamodb-local and when using it with yarn, I have to install the dynamodb jar everytime I install a new package (since yarn removes the bin folder that this lib creates to download the jar binary).

I have been able to make the changes that will use a better directory for this when using it with serverless (a .dynamodb dir int the service folder, same as .serverless one).

Most of the changes are in the serverless plugin, for this lib I just need to change the following piece of code in https://github.com/99xt/dynamodb-localhost/blob/master/dynamodb/starter.js

var starter = {
    start: function (options, config) {
        /* Dynamodb local documentation http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html */
        var additionalArgs = [],
            port = options.port || config.start.port,
-           db_dir = utils.absPath(config.setup.install_path),
+           db_dir = options.install_path || utils.absPath(config.setup.install_path),
            jar = config.setup.jar;

Then, in the serverless plugin I would change in https://github.com/99xt/serverless-dynamodb-local/blob/v1/index.js:

    constructor(serverless, options) {
        this.serverless = serverless;
        this.service = serverless.service;
        this.serverlessLog = serverless.cli.log.bind(serverless.cli);
        this.config = this.service.custom && this.service.custom.dynamodb || {};
-       this.options = options;
+       this.options = _.merge({
+               localPath: path.join(serverless.config.servicePath, '.dynamodb')
+           },
+           options
+       );
    startHandler() {
        const config = this.config;
        const options = _.merge({
-                sharedDb: this.options.sharedDb || true
+                sharedDb: this.options.sharedDb || true,
+                install_path: this.options.localPath
            },
            config && config.start,
            this.options
        );

        // otherwise endHandler will be mis-informed
        this.options = options;
        if (!options.noStart) {
          dynamodbLocal.start(options);
        }
        return BbPromise.resolve()
        .then(() => options.migrate && this.migrateHandler())
        .then(() => options.seed && this.seedHandler());
    }

Let me know what you think! I have the changes ready so if you are ok, I can create the two PRs.

AshanFernando commented 6 years ago

@rehrumesh @lakindu95 @mjzone Can you have a look at this?

ptimson commented 6 years ago

+1

aneilbaboo commented 6 years ago

I'd love to see this get merged. Is there anything holding it up?