checkForUpdates = function (currentVersion, callback) { rfg.changeLog(currentVersion, function(err, versions) { if ((err !== undefined) && (callback !== undefined)) { callback(err, versions); return; } if (versions.length > 0) { var url = 'https://realfavicongenerator.net/change_log?since=' + currentVersion; // Yep, override err so callback receives it as an error err = "A new version is available for your favicon. Visit " + url + " for more information."; gutil.log(gutil.colors.red(err)); } else { gutil.log(gutil.colors.green("Your favicon is up-to-date. Hurray!")); } if (callback !== undefined) { callback(err, versions); } }); }
...
var gulp = require('gulp');
var realFavicon = require('../');
var assert = require('assert');
var gutil = require('gulp-util');
describe('checkForUpdates', function() {
it('should return an error when a new version is available', function(done) {
realFavicon.checkForUpdates(0.9, function(err) {
assert.notEqual(err, undefined);
done();
});
});
it('should return no error when no new version is available', function(done) {
// The hardcoded version should match the current version returned
...
escapeJSONSpecialChars = function (json) { return rfg.escapeJSONSpecialChars(json); }
n/a
generateFavicon = function (params, callback) { var request = rfg.createRequest({ apiKey: API_KEY, masterPicture: params.masterPicture, iconsPath: params.iconsPath, design: params.design, settings: params.settings, versioning: params.versioning }); rfg.generateFavicon(request, params.dest, function(err, data) { if (err) { throw new gutil.PluginError({ plugin: PLUGIN_NAME, message: err }); } fs.writeFileSync(params.markupFile, JSON.stringify(data)); if (callback !== undefined) { callback(err); } }); }
...
masterPicture: params.masterPicture,
iconsPath: params.iconsPath,
design: params.design,
settings: params.settings,
versioning: params.versioning
});
rfg.generateFavicon(request, params.dest, function(err, data) {
if (err) {
throw new gutil.PluginError({
plugin: PLUGIN_NAME,
message: err
});
}
...
injectFaviconMarkups = function (htmlMarkups, options) { var stream = through.obj(function(file, enc, cb) { if (file.isBuffer()) { rfg.injectFaviconMarkups(file.contents, htmlMarkups, (typeof options !== undefined) ? options : {}, function(err, html) { file.contents = new Buffer(html); stream.push(file); cb(); }); } if (file.isStream()) { this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Stream not supported')); } }); // returning the file stream return stream; }
...
}
});
},
injectFaviconMarkups: function(htmlMarkups, options) {
var stream = through.obj(function(file, enc, cb) {
if (file.isBuffer()) {
rfg.injectFaviconMarkups(file.contents, htmlMarkups,
(typeof options !== undefined) ? options : {}, function(err, html) {
file.contents = new Buffer(html);
stream.push(file);
cb();
});
}
...