Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 21, 2019
1 parent ec84d25 commit bb480b9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 79 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
11 changes: 9 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

module.exports = grunt => {
grunt.initConfig({
svgmin: {
Expand All @@ -10,8 +11,14 @@ module.exports = grunt => {
withconfig: {
options: {
plugins: [
{removeViewBox: false},
{convertPathData: {straightCurves: false}}
{
removeViewBox: false
},
{
convertPathData: {
straightCurves: false
}
}
]
},
files: {
Expand Down
89 changes: 44 additions & 45 deletions package.json
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"
}
}
16 changes: 11 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ $ npm install --save-dev grunt-svgmin
## Usage

```js
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
require('load-grunt-tasks')(grunt);

grunt.initConfig({
svgmin: {
options: {
plugins: [
{
removeViewBox: false
}, {
},
{
removeUselessStrokeAndFill: false
}, {
},
{
removeAttrs: {
attrs: ['xmlns']
attrs: [
'xmlns'
]
}
}
]
Expand Down Expand Up @@ -66,7 +70,9 @@ To configure specific parameters for a plugin with the gruntfile.js, set its val
plugins: [
{
removeAttrs: {
attrs: ['xmlns']
attrs: [
'xmlns'
]
}
}
]
Expand Down
42 changes: 19 additions & 23 deletions tasks/svgmin.js
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();
});
};

0 comments on commit bb480b9

Please sign in to comment.