Skip to content

Instantly share code, notes, and snippets.

@dcalhoun
Last active Apr 13, 2019
Embed
What would you like to do?
Task for using Grunticon with Gulp thanks to grunticon-lib.
var gulp = require('gulp'),
q = require('q'),
path = require('path'),
fs = require('fs'),
Grunticon = require('grunticon-lib');
gulp.task('icons', function () {
var deferred = q.defer(),
iconDir = 'app/images/icons/',
options = { enhanceSVG: true };
var files = fs.readdirSync(iconDir).map(function (fileName) {
return path.join(iconDir, fileName);
});
var grunticon = new Grunticon(files, 'dist/icons', options);
grunticon.process(function () {
deferred.resolve();
});
return deferred.promise;
});
@nsierram
Copy link

nsierram commented May 6, 2016

This slimmer version also works,
it uses gulp async task support
and glob.

var gulp      = require('gulp'),
    glob      = require('glob'),
    Grunticon = require('grunticon-lib');

gulp.task('icons', function (done) {
  var icons = 'app/images/icons/*.*',
      options = { enhanceSVG: true };

  var grunticon = new Grunticon(icons, 'dist/icons', options);

  grunticon.process(done);

});

@goesbysteve
Copy link

goesbysteve commented May 10, 2016

@nsierram grunticon-lib needs the first parameter as an array of files not a glob pattern.

Amending your async code -

var gulp      = require('gulp'),
    glob      = require('glob'),
    Grunticon = require('grunticon-lib');

gulp.task('icons', function (done) {
  var icons = glob.sync('app/images/icons/*.*'), // <-- get array of files from glob pattern
      options = { enhanceSVG: true };

  var grunticon = new Grunticon(icons, 'dist/icons', options);

  grunticon.process(done);

});

@nsierram
Copy link

nsierram commented May 10, 2016

Yup, u are right, I had forgotten to put that line ;)
glob.sync(src)..

@aminta
Copy link

aminta commented May 30, 2016

Hi! Great code! Is it possibile integrate it with a .pipe so I can use gulp-svgmin before launch grunticon? Can I concatenate the grunticon.loader.js with other JS files and concatenate the .css files with other Css files?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment