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

Refactore index.js to be able to be required programmatically #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

92bondstreet
Copy link

@92bondstreet 92bondstreet commented Sep 14, 2018

What?

This MR contains largely a smooth refactoring to use gcal-cli also in a programmatically way.

How?

  • add the bin entry point bin.js
  • move google apis method to api.js
  • expose client, api and core method from index.js
  • add Do directives doc for the first authorization installation
  • settle bulk promises instead of call them with Promise.all

@toniov
Copy link
Owner

toniov commented Sep 15, 2018

Thanks for the PR! It's a huge refactor so let me take a close look at it :)
I think it's big enough to be released as an upgraded major version.

Btw what do you mean by dynamic way? Exposing the methods to be able to be required programmatically?

src/api.js Outdated
const promises = events.map(async event => {
return await insert(event);
});
return await pSettle(promises);
Copy link
Owner

Choose a reason for hiding this comment

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

return await is not performant since it's redundant, just doing return pSettle(promises); is better.

Copy link
Author

Choose a reason for hiding this comment

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

You're right. I'll update the MR.

module.exports.bulk = async events => {
const calendar = await client();
const insert = promisify(calendar.events.insert);
const promises = events.map(async event => {
Copy link
Owner

Choose a reason for hiding this comment

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

const promises = events.map(async event => insert(event));

Is better I think.

Copy link
Author

Choose a reason for hiding this comment

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

I think we should write also const promises = events.map(async event => insert(event));

Copy link
Owner

Choose a reason for hiding this comment

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

what do you mean?

I meant:

const promises = events.map(event => insert(event));

async is not necessary.

Copy link
Author

Choose a reason for hiding this comment

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

Got it.

package.json Outdated
"dependencies": {
"babel-eslint": "^9.0.0",
Copy link
Owner

Choose a reason for hiding this comment

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

What did you need it for? btw I think it should go in devDependencies.

Copy link
Author

Choose a reason for hiding this comment

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

It's due, i think, to my IDE.
I'll remove the installation.

docs/OAUTH.md Show resolved Hide resolved
@92bondstreet 92bondstreet changed the title Refactore index.js to allow dynamic usage Refactore index.js to be able to be required programmatically Sep 17, 2018
@92bondstreet
Copy link
Author

I edited also the description and the MR title to be explicit about the programmatically way.

@92bondstreet
Copy link
Author

The next step will be to upgrade dependencies and move googleapis from v21 to v33

@92bondstreet
Copy link
Author

Regarding all refactoring and new features, we could also open the PR to a dedicated branch.

@toniov
Copy link
Owner

toniov commented Sep 19, 2018

Regarding all refactoring and new features, we could also open the PR to a dedicated branch.

Since this is quite big I think that's a good idea! We could separate it in several PRs to a dedicated branch, and at the end merge that branch with master in a final PR.

@toniov
Copy link
Owner

toniov commented Sep 20, 2018

I created a branch called 2.0.0.

This order could be nice, so we can isolate possible bugs:

  1. Architecture refactor (splitting files and so on, not changing code)
  2. Code refactor (e.g. changing Promise.all() with pSettle)
  3. Upgrading dependencies
  4. New functionality (e.g. enable?)

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.

None yet

2 participants