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

chore: minify svg husky hook #10560

Merged
merged 4 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions docs/blog/2017-11-08-migrate-from-jekyll-to-gatsby/gatsby.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
"*.{md,css,scss,yaml,yml}": [
"prettier --write",
"git add"
],
"*.svg": [
"svgo --pretty --indent=2 --config=svgo.yml --multipass",
"git add"
]
},
"husky": {
Expand All @@ -61,10 +65,10 @@
"scripts": {
"bootstrap": "npm-run-all -s check-versions lerna-prepare",
"check-versions": "babel-node scripts/check-versions.js",
"format": "npm run format:code && npm run format:other",
"format": "npm run format:code && npm run format:other && npm run format:svg",
"format:other": "npm run prettier -- --write",
"format:code": "npm run lint:code -- --fix",
"format-svg": "find www examples packages | grep '\\.svg$' | xargs -Iz -n 1 svgo --pretty --indent=2 --config=svgo.yml z",
"format:svg": "node scripts/format-svg.js",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
"hooks:install": "node node_modules/husky/husky.js install",
"jest": "jest",
Expand Down
24 changes: 24 additions & 0 deletions scripts/format-svg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// this file exists because svgo only accepts folders or files, to make this work you'll need to do
// find www examples packages | grep '\\.svg$' | xargs -Iz -n 1 svgo --pretty --indent=2 --config=svgo.yml z
// this only works on bash not inside windows so we create a simple js file that does the globbing for us
const glob = require(`glob`)
const execa = require(`execa`)
const path = require(`path`)

// list of ignored files because they don't get optimized correctly
const ignoreList = [
`./docs/blog/2017-11-08-migrate-from-jekyll-to-gatsby/diagram-ci.svg`,
]

const files = glob.sync(`./**/*.svg`, {
ignore: [`./node_modules/**`].concat(ignoreList),
})

const proc = execa(
`./node_modules/.bin/svgo`,
[`--pretty`, `--indent=2`, `--config=svgo.yml`, `--multipass`].concat(files),
{ cwd: path.join(__dirname, `..`) }
)

proc.stdout.pipe(process.stdout)
proc.stderr.pipe(process.stderr)
27 changes: 11 additions & 16 deletions www/src/assets/showcase-feather.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.