index.js
function saveSprites(images, options, sprites) {
	return new Promise(function (resolve, reject) {
		if (!fs.existsSync(options.spritePath)) {
			mkdirp.sync(options.spritePath);
		}

		var all = _
			.chain(sprites)
			.map(function (sprite) {
				sprite.path = makeSpritePath(options, sprite.groups);
				var deferred = Promise.pending();

				// If this file is up to date
				if (sprite.isFromCache) {
					log(options.logLevel, 'lv3', ['Lazysprite:', colors.yellow(path.relative(process.cwd(), sprite.path)), 'unchanged.']);
					deferred.resolve(sprite);
					return deferred.promise;
				}

				// Save new file version
				return fs.writeFileAsync(sprite.path, Buffer.from(sprite.image, 'binary'))
					.then(function () {
						log(options.logLevel, 'lv2', ['Lazysprite:', colors.green(path.relative(process.cwd(), sprite.path)), 'generated.']);
						return sprite;
					});
			})
			.value();

		Promise.all(all)
			.then(function (sprites) {
				resolve([images, options, sprites]);
			})
			.catch(function (err) {
				if (err) {
					reject(err);
				}
			});
	});
}
function saveSprites(images, options, sprites) {
	return new Promise(function (resolve, reject) {
		if (!fs.existsSync(options.spritePath)) {
			mkdirp.sync(options.spritePath);
		}

		var all = _
			.chain(sprites)
			.map(function (sprite) {
				sprite.path = makeSpritePath(options, sprite.groups);
				var deferred = Promise.pending();

				// If this file is up to date
				if (sprite.isFromCache) {
					log(options.logLevel, 'lv3', ['Lazysprite:', colors.yellow(path.relative(process.cwd(), sprite.path)), 'unchanged.']);
					deferred.resolve(sprite);
					return deferred.promise;
				}

				// Save new file version
				return fs.writeFileAsync(sprite.path, Buffer.from(sprite.image, 'binary'))
					.then(function () {
						log(options.logLevel, 'lv2', ['Lazysprite:', colors.green(path.relative(process.cwd(), sprite.path)), 'generated.']);
						return sprite;
					});
			})
			.value();

		Promise.all(all)
			.then(function (sprites) {
				resolve([images, options, sprites]);
			})
			.catch(function (err) {
				if (err) {
					reject(err);
				}
			});
	});
}
function saveSprites ( images , options , sprites ) { return new Promise ( function ( resolve , reject ) { if ( ! fs . existsSync ( options . spritePath ) ) { mkdirp . sync ( options . spritePath ) ; } var all = _ . chain ( sprites ) . map ( function ( sprite ) { sprite . path = makeSpritePath ( options , sprite . groups ) ; var deferred = Promise . pending ( ) ; // If this file is up to date if ( sprite . isFromCache ) { log ( options . logLevel , 'lv3' , [ 'Lazysprite:' , colors . yellow ( path . relative ( process . cwd ( ) , sprite . path ) ) , 'unchanged.' ] ) ; deferred . resolve ( sprite ) ; return deferred . promise ; } // Save new file version return fs . writeFileAsync ( sprite . path , Buffer . from ( sprite . image , 'binary' ) ) . then ( function ( ) { log ( options . logLevel , 'lv2' , [ 'Lazysprite:' , colors . green ( path . relative ( process . cwd ( ) , sprite . path ) ) , 'generated.' ] ) ; return sprite ; } ) ; } ) . value ( ) ; Promise . all ( all ) . then ( function ( sprites ) { resolve ( [ images , options , sprites ] ) ; } ) . catch ( function ( err ) { if ( err ) { reject ( err ) ; } } ) ; } ) ; }
Save the sprites to the target path.
@param  {Object} options
@param  {Array}  images
@param  {Array}  sprites
@return {Promise}
Save the sprites to the target path .