Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Improved plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Feb 26, 2016
1 parent 6ccb5c8 commit 765ca72
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,72 @@ const GulpChanged = require('gulp-changed');
const GulpIf = require('gulp-if');
const GulpImageMin = require('gulp-imagemin');
const GulpUtil = require('gulp-util');
const Maelstrom = require('maelstrom');

// // // // // // // // // // // // // // // // // // // // // // // // // // //

module.exports = function()
const $plugin = new Maelstrom.Plugin(__filename, ['images', 'imgs'],
{
const Maelstrom = this;
const Config = Maelstrom.config;
const Gulp = Maelstrom.gulp;
const Utils = Maelstrom.utils;
/**
* Return the location of raw, unoptimized images.
*/
src: function($src)
{
let $types = Maelstrom.config.images.types.join(',');
let $defaultSrc = Maelstrom.config.src.images + '/**/*.{' + $types + '}';

// -------------------------------------------------------------------------
return Maelstrom.utils.extendArgs($src, $defaultSrc);
},

let $plugin = new Maelstrom.Plugin(__filename, ['images', 'imgs'],
/**
* Return the location of the images output folder.
*/
dest: function()
{
/**
* Return the location of raw, unoptimized images.
*/
src: function($src)
{
let $types = Config.images.types.join(',');
let $defaultSrc = Config.src.images + '/**/*.{' + $types + '}';
return Maelstrom.config.dest.images;
}
});

return Utils.extendArgs($src, $defaultSrc);
},
// -----------------------------------------------------------------------------

/**
* Return the location of the images output folder.
*/
dest: function()
{
return Config.dest.images;
}
});
/**
* Optimize images with _imagemin_,
*/
$plugin.setStream('optimize', function()
{
return GulpImageMin(Maelstrom.config.images.imagemin);
});

// -------------------------------------------------------------------------
// -----------------------------------------------------------------------------

/**
* Optimize images with _imagemin_,
*/
$plugin.addStream('optimize', function()
{
return GulpImageMin(Config.images.imagemin);
});
/**
*
*/
$plugin.setTask('default', [Maelstrom.TASK_WATCH], function()
{
// *loop through resize tasks and resize the matching images according
// *to config settings

// -------------------------------------------------------------------------
// when the --all flag is used, do not filter for last changed images,
// but update all images
let $changedFilesOnly = (GulpUtil.env.all !== true);

/**
*
*/
$plugin.addTask('images', function()
{
// *loop through resize tasks and resize the matching images according
// *to config settings
return Maelstrom.gulp.src( $plugin.src() )
.pipe( Maelstrom.stream('plumber') )
.pipe( GulpIf($changedFilesOnly, GulpChanged( $plugin.dest() )) )
.pipe( $plugin.stream('optimize') )
.pipe( Maelstrom.stream('size') )
.pipe( Maelstrom.gulp.dest($plugin.dest()) );
});

// when the --all flag is used, do not filter for last changed images,
// but update all images
let $changedFilesOnly = (GulpUtil.env.all !== true);
/**
* Clean the CSS output dir from all excess files.
*/
$plugin.setTask('clean', [Maelstrom.TASK_CLEAN], function()
{
Maelstrom.stream('clean', $plugin.dest())
});

return Gulp.src( $plugin.src() )
.pipe( Maelstrom.stream('plumber') )
.pipe( GulpIf($changedFilesOnly, GulpChanged( $plugin.dest() )) )
.pipe( $plugin.stream('optimize') )
// .pipe( GulpSize(Config.main.size) )
.pipe( Maelstrom.stream('size') )
.pipe( Gulp.dest($plugin.dest()) );
});
// -----------------------------------------------------------------------------

return $plugin;
};
module.exports = $plugin;

0 comments on commit 765ca72

Please sign in to comment.