Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modularizing server and introduce cli example. #6

Merged
merged 9 commits into from
Oct 16, 2014

Conversation

stephenplusplus
Copy link
Contributor

Following up from googleapis/google-cloud-datastore#50, this sent the server files to a new /server directory, as well as introduced a CLI example a little more sophisticated than the one from the earlier PR.

An easier to look at representation: https://github.com/stephenplusplus/gcloud-node-todos

screen shot 2014-09-26 at 3 13 33 pm

});
});

gulp.task('test', ['dredd']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed Gulp, as it seemed overkill for just this task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I wanted to add more! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, no problem. I can add it back in :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, also the travis build should probably depends on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add gulp back?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,18 @@
{
"bitwise": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

@stephenplusplus
Copy link
Contributor Author

My recent updates resolved:

  • readme links to TodoMVC & Docker

  • modularize todo functionality into one file, shared by the CLI & express apps

  • changed api blueprint:

    {
      "id": 42,
    - "text": "do this",
    - "done": false
    + "data": {
    +   "text": "do this",
    +   "done": false
    + }
    }

Still to-do:

  • Bring back gulp

@proppy
Copy link
Member

proppy commented Oct 5, 2014

Thanks for making those changes! Will take a closer look at them next week ;)

}));
});
}
module.exports.getAll = getAll;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why you export them one by one instead of doing (beware, I'm not that up to date on latest Node.js trends):

module.exports {
  getAll: function() {
  },
  // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's certainly fine to do it that way, but common convention in my experience tends to keep indentation as close to the left wall as possible. Nesting inside of module.exports just adds a level that can be quickly removed by extracting the functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about having the exports as the top then, instead of below each function?

Or even module.exports.getAll = function() {}

I'm curious about which one is more idomatic those days.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one of those situations where you pick it and just be consistent in your own code. The only benefit to one over another is readability, but as these are all common ways of writing JavaScript, they should each offer the same readability to a newcomer.

If you prefer to look at:

module.exports.getAll = function() {
  // ...
};

I'm happy to go that route 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always prefer to export everything at the bottom of the file. That way I can go to a file and immediately scroll to the end to see what it's exporting. I would suggest we do it like proppy first suggested:

module.exports = {
  getAll: function() {
  },
  // ...
};
// EOF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@stephenplusplus
Copy link
Contributor Author

stephenplusplus@77fd19c made a few changes:

  • todo structure is flat.
  • dredd was upgraded to support an afterAll hook to delete all todos created during testing
  • tests don't use request to ping the API in the hooks, instead the todos module

I caught a bug after upgrading gcloud to 0.8.0: googleapis/google-cloud-node#250, so after a merge and release of the fix, I'll update the gcloud dependency here to 0.8.1

@@ -0,0 +1,75 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should live under app/ WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean this individual file or the server directory? mv server apps?

@stephenplusplus
Copy link
Contributor Author

Gulp is back, along with minor restructuring:

  • [mv] server/server.js -> server/index.js
  • [mv] server/test/test_hooks.js -> server/test/hooks.js
  • [rm] server/test/server_test.js

@@ -0,0 +1,51 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is lowercase more the norm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If yes, can you git mv instead so we have history?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the norm and sure.

@stephenplusplus
Copy link
Contributor Author

Well, I squashed these down in hopes to make doing the git mv Gulpfile.js gulpfile.js traceable in history, but git doesn't seem to be so smart with the case conversion. It still ended up being a rm and add, apparently because I had to git mv G... g... -f.

Anyway, same changes, just one commit now.


# API
See the [apps](//github.com/GoogleCloudPlatform/gcloud-node-todos/apps) directory for a full list of examples.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only concern here is that the app directory doesn't include the server sample.

Maybe we could have a flat structure instead.

Have todos.js, server.js and cli/ at the root and tests/ what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 although this might be uncovering some underlying confusion I'm having. I don't consider the server an app, rather the gcloud integration point, simply always running in the background for the FE implementations to ping.

It does make sense to move it out of server/ just to make it more visible from the frontpage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so maybe:

server.js
todos.js
package.json
tests/
cli/

And consider cli/ as a sub project with it's own README.md and package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. If we get to a point that we have multiple (many) examples, we can always shift them into their own directory if we think that's necessary.

@stephenplusplus
Copy link
Contributor Author

Flattened!

stephenplusplus referenced this pull request in proppy/gcloud-node-todos Oct 15, 2014
@@ -0,0 +1,11 @@
# Command Line Example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md to match the parent?

@proppy
Copy link
Member

proppy commented Oct 15, 2014

LGTM, just some nits.

@stephenplusplus
Copy link
Contributor Author

Updated!


[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-node-todos.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-node-todos)

TodoMVC backend using [gcloud-node](//github.com/GoogleCloudPlatform/gcloud-node).
## Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put that at the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under 'Other Examples'

@proppy
Copy link
Member

proppy commented Oct 16, 2014

At some point I will need to stop commenting and hit that merge button :)

@stephenplusplus
Copy link
Contributor Author

:) hey, they're all for the better!

@stephenplusplus
Copy link
Contributor Author

Travis is bombing: https://travis-ci.org/GoogleCloudPlatform/gcloud-node-todos/builds/38111282

Is this anything I caused?

@proppy
Copy link
Member

proppy commented Oct 16, 2014

@stephenplusplus nop, don't worry about travis, because it relies on encrypted credentials it will only work on master

});

function _handleApiResponse(res, successStatus) {
return function(err, response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/response/payload/? to avoid the confusion between res and response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed that the first time. Fixed!

@proppy
Copy link
Member

proppy commented Oct 16, 2014

Thanks!

proppy added a commit that referenced this pull request Oct 16, 2014
modularizing server and introduce cli example.
@proppy proppy merged commit d659be0 into GoogleCloudPlatform:master Oct 16, 2014
@stephenplusplus
Copy link
Contributor Author

Woo!

@proppy
Copy link
Member

proppy commented Oct 16, 2014

And so much congrats for not breaking the build :)
https://travis-ci.org/GoogleCloudPlatform/gcloud-node-todos/builds/38112579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants