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

Allow customization of sendDeployData #8

Merged
merged 1 commit into from
Nov 14, 2017

Conversation

mydea
Copy link
Contributor

@mydea mydea commented Nov 14, 2017

This PR makes it possible to specify a custom sendDeployData method in the deploy config.
This can be used to do some custom tracking, e.g. if you don't want to track to keen.io but to another service.

Allow customization of sendDeployData
@YoranBrondsema
Copy link
Collaborator

Thanks a lot @mydea for the addition!

@YoranBrondsema YoranBrondsema merged commit 5be80ef into kiwiupover:master Nov 14, 2017
@YoranBrondsema
Copy link
Collaborator

I will publish a new release shortly.

@kiwiupover
Copy link
Owner

kiwiupover commented Nov 14, 2017

@mydea thanks, If you have a bit more time would mind providing a bit more detail on what you are doing the sendDeployData function. I think a little more detail would make it bit more user-friendly.

Cheers
Dave

Again thanks heaps for this PR!

ENV['asset-sizes'] = {
  sendDeployData(assets, options) {
    // Manually do something with the assets
    // 'assets' is an array of objects with 'name', 'size' and 'gzipSize'
  }
}

@YoranBrondsema
Copy link
Collaborator

YoranBrondsema commented Nov 14, 2017

Ah damn @kiwiupover, I had already merged. Sorry about that. Haven't published a release though. I will wait until we're all happy with the changes to do that.

@kiwiupover
Copy link
Owner

kiwiupover commented Nov 14, 2017

@YoranBrondsema no worries It will only be a readme update I would think. Please cut a release.

@mydea
Copy link
Contributor Author

mydea commented Nov 15, 2017

In our company, we have a custom proxy for keen. So basically, instead of sending data to keen directly, we send it to an internal endpoint which modifies the data and then posts it to keen.

So basically, my function looks something like this:

const https = require('https'); 
const RSVP = require('rsvp'); 

sendDeployData(keenData, configOptions) { 
        let postData = JSON.stringify({ 'deploy-file-sizes': [keenData] }); 
        let hostname = configOptions.KEEN_PROJECT_ID; 
 
        let options = { 
          hostname, 
          path: '/api/internal-endpoint', 
          method: 'POST', 
          port: 443, 
          headers: { 
            'Content-Type': 'application/json', 
            'Content-Length': postData.length 
          } 
        }; 
 
        return new RSVP.Promise(function(resolve, reject) { 
          // If no hostname is configured, resolve without doing anything 
          if (!hostname) { 
            console.log('No hostname was specified for asset-sizes, skipping tracking...');
            return resolve(); 
          } 
 
          let req = https.request(options, (res) => { 
            res.setEncoding('utf8'); 
            console.log(`File size data was tracked to keen for ${hostname} with status code ${res.statusCode}`);
            resolve(); 
          }); 
 
          req.on('error', (e) => { 
            reject(e); 
          }); 
 
          req.write(postData); 
          req.end(); 
        }); 
      } 
} 

@kiwiupover
Copy link
Owner

Thanks heaps @mydea

@YoranBrondsema
Copy link
Collaborator

YoranBrondsema commented Nov 15, 2017

I found out that the tests probably don't run anywhere but on @mydea's computer because of the absolute paths in https://github.com/kiwiupover/ember-cli-deploy-asset-sizes/pull/8/files#diff-f47a110ab50cb6481739372ca5a08789R203 (see the Travis build too). Just a heads up that I think those should be fixed before we push out a new release.

By the way @kiwiupover, do you have any idea why the build status does not appear next to the commit? Normally it shows the result of the build (green tick or red cross) next to the commit message in the screenshot below.

github

@mydea
Copy link
Contributor Author

mydea commented Nov 15, 2017

Huh, oops. Not sure how that sneaked in :O. sorry about that. I also wondered why my PR was not being picked up by travis.

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