Skip to content
This repository was archived by the owner on Jun 10, 2019. It is now read-only.

Adding image-size check script and pre-commit hook to run it - #758

Merged
kylemh merged 2 commits into
masterfrom
image_check_script_issue_676
Jan 24, 2018
Merged

kylemh merged 2 commits into
masterfrom
image_check_script_issue_676

Conversation

@Cooperbuilt

Copy link
Copy Markdown
Contributor

Description of changes

Adds a pre-commit hook that recursively checks all images within the src/images folder. If they are above the 1MB size limit, this hook will console log the offending files and fail the commit.

Note:

In order to get this to PR, I ran my commit with a --no-verify flag because we have two offending files. src/images/serviceSeals/USMCReserve.png and src/images/Family-2.png. I will open a new issue to resize these images.

Issue Resolved

Fixes #676

@Cooperbuilt
Cooperbuilt requested a review from kylemh December 12, 2017 12:28
@Cooperbuilt Cooperbuilt changed the title Adding image-size check script anf pre-commit hook to run it Adding image-size check script and pre-commit hook to run it Dec 12, 2017
@kylemh

kylemh commented Jan 2, 2018

Copy link
Copy Markdown
Member

If I merge this, the images that already break this rule will prevent further merges until the image size issues are rectified, correct?

Comment thread scripts/imageSize.js Outdated
const path = require('path');
const fs = require('fs');

let fileArray = [];

@kevinkiklee kevinkiklee Jan 19, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of storing it to an external array, I think we can return the result directly by filtering instead of mapping at the end of read.

  .filter(file => typeof file === 'string')
  .filter(image => fs.lstatSync(image).size > 1000000)

Can also be combined into one filter, if you would like.

Then we can just set const fileArray = read('src/images/').

Comment thread scripts/imageSize.js Outdated

read('src/images/');

if (fileArray.length > 0) {

@kevinkiklee kevinkiklee Jan 19, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can be just if (fileArray.length) {} since 0 is the only case we care about.

Comment thread scripts/imageSize.js Outdated

let fileArray = [];

const read = dir =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know this is something small, but could this be renamed to readDir? read feels vague to me.

@kevinkiklee kevinkiklee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I didn't know about pre-commit. That's really cool. I learned something new.

This was referenced Jan 21, 2018
@kylemh

kylemh commented Jan 21, 2018

Copy link
Copy Markdown
Member

Targets neutralized

#814

@kylemh kylemh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed with @kevinkiklee 's review. Also worried about using typeof in conjunction with const

Under, "Temporal Dead Zones"

@Cooperbuilt
Cooperbuilt force-pushed the image_check_script_issue_676 branch from 0723bcd to 112fb6c Compare January 23, 2018 11:55
@Cooperbuilt

Copy link
Copy Markdown
Contributor Author

Gun #2 ready for re-check.
Tests are failing because I am on a hotspot and don't have the bandwidth to connect to the test runner (Travis is failing with connection errors). I can re-run them later for a passing build, or if one of you awesome reviewers have the power to re-run them that would be fine.

@kylemh
kylemh merged commit 5804531 into master Jan 24, 2018
@kylemh
kylemh deleted the image_check_script_issue_676 branch January 24, 2018 06:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create an image file size check on a git hook

3 participants