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

Goodparts refactor #70

Merged
merged 11 commits into from
Feb 9, 2017
Merged

Goodparts refactor #70

merged 11 commits into from
Feb 9, 2017

Conversation

newswim
Copy link
Collaborator

@newswim newswim commented Feb 8, 2017

Hello! This new PR is meant to add GoodParts compliance a la Issue #66 and re-initialize the merge from within the upstream repo rather than my own fork.

It has the following TODOs:

  • sendemail is not returning anything, so tests 10 and 11 never end (see failure in action).

@samhstn
Copy link
Member

samhstn commented Feb 8, 2017

I think the way to ensure the last 2 tests pass is to rewrite the compile_template function.

The last 2 tests currently is breaking because the filepath variable is being evaluated when the process.env.TEMPLATE_DIRECTORY is undefined and erroring.

This didn't used to be a problem because before we wouldn't trip into the if statement and we wouldn't evaluate it.

But as we are now evaluating this variable (which will sometimes break things), we need to rethink the function

@newswim
Copy link
Collaborator Author

newswim commented Feb 8, 2017

Prior to refactoring to comply with goodparts, there were some vars in odd places, and goodparts wants them always at the top of whatever scope they're in. You're right, and also moving them may have caused some of the evaluation order breakage.

@samhstn
Copy link
Member

samhstn commented Feb 8, 2017

On master changing the compile_templates function should comply with goodparts and doesn't break the tests:

function compile_template(template_name, type) {
  var filepathWithoutExt = process.env.TEMPLATE_DIRECTORY + '/' + template_name;
  var filepath = path.resolve(filepathWithoutExt + '.' + type);
  var template = !COMPILED_TEMPLATES[template_name+'.'+type]
    ? fs.readFileSync(filepath, 'utf8')
    : '';
  var compiled = Handlebars.compile(template);

  // check if the template has already been opened
  if(!COMPILED_TEMPLATES[template_name+'.'+type]) {
    COMPILED_TEMPLATES[template_name+'.'+type] = compiled;
  }
  return COMPILED_TEMPLATES[template_name+'.'+type];
}

But it's a little messy

@codecov-io
Copy link

codecov-io commented Feb 8, 2017

Codecov Report

Merging #70 into master will not change coverage.

@@          Coverage Diff          @@
##           master    #70   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines          29     31    +2     
=====================================
+ Hits           29     31    +2
Impacted Files Coverage Δ
lib/index.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62f7ad4...b900ce6. Read the comment docs.

@newswim
Copy link
Collaborator Author

newswim commented Feb 8, 2017

I had to disable a couple of eslint rules, namely no-console before the error check of ses.sendEmail, and vars-on-top to handle the immediate reassignment of filepath.

We could probably get rid of the console exception by throwing a new Error object instead. I'm not sure how to handle that reassignment.

@samhstn
Copy link
Member

samhstn commented Feb 8, 2017

I think logging the ses error is fine and using eslint-disable no-console here is ok.

I've rewritten the compile_templates function addressing the vars-on-top rule.

@newswim let me know what you think

@newswim
Copy link
Collaborator Author

newswim commented Feb 8, 2017

Looks good! It's also a bit more readable.

@samhstn
Copy link
Member

samhstn commented Feb 8, 2017

@newswim Do you think we should also remove the jshint dependecy (and it's baggage) and change the pre-commit hook to use goodparts instead of jshint?

@samhstn samhstn assigned nelsonic and unassigned newswim Feb 8, 2017
@samhstn samhstn requested review from nelsonic and removed request for nelsonic February 8, 2017 19:55
@samhstn samhstn assigned newswim and unassigned nelsonic Feb 8, 2017
@newswim
Copy link
Collaborator Author

newswim commented Feb 8, 2017

Good call! I'll remove it

@samhstn
Copy link
Member

samhstn commented Feb 8, 2017

Looks ready to me. @nelsonic Could you have a quick look and merge if your happy.

@iteles
Copy link
Member

iteles commented Feb 8, 2017

You guys 😍 Thank you for all the work that's gone into this!

var AWS = require('aws-sdk');
AWS.config.region = process.env.AWS_REGION;
Copy link
Member

Choose a reason for hiding this comment

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

Do we no longer need to configure the AWS_REGION before instantiating the SES client? ❓

var Handlebars = require('handlebars'); // -> compile templates
var COMPILED_TEMPLATES = {}; // -> cache compiled templates

AWS.config.region = process.env.AWS_REGION;
Copy link
Member

@nelsonic nelsonic Feb 9, 2017

Choose a reason for hiding this comment

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

can AWS_REGION be configured down here after SES has been instantiated?
(good ol OOP, hey...?) 😆

throw "Please Set a Template Directory";
function set_template_directory (dir) {
if (!dir) {
throw new Error('Please Set a Template Directory');
Copy link
Member

Choose a reason for hiding this comment

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

thanks for tidying up this error throwing. 👍

Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

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

@newswim this looks so much better!! 😍
(thank you so much for making the time to do this refactor. it's textbook!) 🥇
@Shouston3 thanks for remote-pairing / peer-reviewing the refactor. ❤️ ✅ 🚀
Merging. 👍

@nelsonic nelsonic merged commit 2b973f6 into master Feb 9, 2017
@nelsonic nelsonic deleted the goodparts-refactor branch February 9, 2017 02:20
@nelsonic
Copy link
Member

nelsonic commented Feb 9, 2017

@newswim the latest version on NPM sendemail@3.1.0 contains your changes! thanks again! ❤️

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

Successfully merging this pull request may close these issues.

5 participants