-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec84d25
commit bb480b9
Showing
6 changed files
with
85 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,46 @@ | ||
{ | ||
"name": "grunt-svgmin", | ||
"version": "5.0.0", | ||
"description": "Minify SVG", | ||
"license": "MIT", | ||
"repository": "sindresorhus/grunt-svgmin", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && grunt" | ||
}, | ||
"files": [ | ||
"tasks" | ||
], | ||
"keywords": [ | ||
"gruntplugin", | ||
"svg", | ||
"vector", | ||
"graphic", | ||
"image", | ||
"optimize", | ||
"minify" | ||
], | ||
"dependencies": { | ||
"chalk": "^2.3.0", | ||
"each-async": "^1.1.1", | ||
"log-symbols": "^2.1.0", | ||
"pretty-bytes": "^4.0.2", | ||
"svgo": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"grunt": "^1.0.1", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-contrib-clean": "^1.0.0", | ||
"grunt-simple-mocha": "^0.4.0", | ||
"xo": "*" | ||
}, | ||
"peerDependencies": { | ||
"grunt": ">=0.4.0" | ||
} | ||
"name": "grunt-svgmin", | ||
"version": "5.0.0", | ||
"description": "Minify SVG", | ||
"license": "MIT", | ||
"repository": "sindresorhus/grunt-svgmin", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && grunt" | ||
}, | ||
"files": [ | ||
"tasks" | ||
], | ||
"keywords": [ | ||
"gruntplugin", | ||
"svg", | ||
"vector", | ||
"graphic", | ||
"image", | ||
"optimize", | ||
"minify" | ||
], | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"log-symbols": "^2.2.0", | ||
"pretty-bytes": "^5.1.0", | ||
"svgo": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "^1.0.3", | ||
"grunt-cli": "^1.3.2", | ||
"grunt-contrib-clean": "^2.0.0", | ||
"grunt-simple-mocha": "^0.4.1", | ||
"xo": "^0.24.0" | ||
}, | ||
"peerDependencies": { | ||
"grunt": ">=1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
'use strict'; | ||
const chalk = require('chalk'); | ||
const eachAsync = require('each-async'); | ||
const prettyBytes = require('pretty-bytes'); | ||
const logSymbols = require('log-symbols'); | ||
const SVGO = require('svgo'); | ||
|
||
module.exports = grunt => { | ||
grunt.registerMultiTask('svgmin', 'Minify SVG', function () { | ||
grunt.registerMultiTask('svgmin', 'Minify SVG', async function () { | ||
const done = this.async(); | ||
const svgo = new SVGO(this.options()); | ||
let totalSaved = 0; | ||
let totalSavedBytes = 0; | ||
|
||
eachAsync(this.files, (el, i, next) => { | ||
const srcPath = el.src[0]; | ||
const srcSvg = grunt.file.read(srcPath); | ||
await Promise.all(this.files.map(async element => { | ||
const sourcePath = element.src[0]; | ||
const sourceSvg = grunt.file.read(sourcePath); | ||
|
||
svgo.optimize(srcSvg).then(result => { | ||
if (result.error) { | ||
grunt.warn(srcPath + ': ' + result.error); | ||
next(); | ||
return; | ||
} | ||
const result = await svgo.optimize(sourceSvg); | ||
if (result.error) { | ||
grunt.warn(`${sourcePath}: ${result.error}`); | ||
return; | ||
} | ||
|
||
const saved = srcSvg.length - result.data.length; | ||
const percentage = saved / srcSvg.length * 100; | ||
totalSaved += saved; | ||
const savedBytes = sourceSvg.length - result.data.length; | ||
const percentage = savedBytes / sourceSvg.length * 100; | ||
totalSavedBytes += savedBytes; | ||
|
||
grunt.verbose.writeln(logSymbols.success + ' ' + srcPath + chalk.gray(' (saved ' + chalk.bold(prettyBytes(saved)) + ' ' + Math.round(percentage) + '%)')); | ||
grunt.file.write(el.dest, result.data); | ||
next(); | ||
}); | ||
}, () => { | ||
grunt.log.writeln('Total saved: ' + chalk.green(prettyBytes(totalSaved))); | ||
done(); | ||
}); | ||
grunt.verbose.writeln(logSymbols.success + ' ' + sourcePath + chalk.gray(' (saved ' + chalk.bold(prettyBytes(savedBytes)) + ' ' + Math.round(percentage) + '%)')); | ||
grunt.file.write(element.dest, result.data); | ||
})); | ||
|
||
grunt.log.writeln(`Total saved: ${chalk.green(prettyBytes(totalSavedBytes))}`); | ||
done(); | ||
}); | ||
}; |