RealFaviconGenerator / realfavicongenerator

Generate favicon for all major platforms
504 stars 24 forks source link

check-for-favicon-update gulp task should readFileSync with utf8 encoding argument #319

Open jgautsch opened 7 years ago

jgautsch commented 7 years ago

After favicon is generated, in the "Install your favicon" instructions tab for Google Web Starter Kit, step 2:

In tasks/real-favicon.js, the following gulp task is defined at the bottom:

// Check for updates on RealFaviconGenerator (think: Apple has just
// released a new Touch icon along with the latest version of iOS).
// Run this task from time to time. Ideally, make it part of your
// continuous integration system.
gulp.task('check-for-favicon-update', function(done) {
  var currentVersion = JSON.parse(fs.readFileSync('favicon-data.json')).version;
  realFavicon.checkForUpdates(currentVersion, function(err) {
    if (err) {
      throw err;
    }
    done();
  });
});

fs.readFileSync by default returns a Buffer- adding the second encoding argument of 'utf8' makes it return a string, which results in type compatibility with JSON.parse(...)

So: fs.readFileSync('favicon-data.json') should be fs.readFileSync('favicon-data.json', 'utf8')

Thanks again for such a great tool!

jgautsch commented 7 years ago

Looks like the 'utf8' arg could be added to this snippet as well, in gulpfile.babel.js:

// Favicon markups
.pipe($.if('*.html', realFavicon.injectFaviconMarkups(
  JSON.parse(fs.readFileSync('favicon-data.json')).favicon.html_code,
  {keep: 'link[rel="manifest"]'})))

resulting in:

// Favicon markups
.pipe($.if('*.html', realFavicon.injectFaviconMarkups(
  JSON.parse(fs.readFileSync('favicon-data.json', 'utf8')).favicon.html_code,
  {keep: 'link[rel="manifest"]'})))